1
00:00:01,680 --> 00:00:05,610
OK, in the last video, we drew a couple straight lines in this video, I want to start to introduce

2
00:00:05,610 --> 00:00:09,690
the mouse into this because, you know, when we're drawing, we're not going to programmatically create

3
00:00:09,690 --> 00:00:10,500
these lines like this.

4
00:00:10,500 --> 00:00:12,630
We're just going to drag our mouse around the screen.

5
00:00:12,630 --> 00:00:16,570
And hopefully that will create the color on the screen and draw the lines that way.

6
00:00:16,590 --> 00:00:17,940
So how do we start to do that?

7
00:00:17,940 --> 00:00:24,510
Well, any time you're doing something like adding keyboard events or mouse events, you're actually

8
00:00:24,630 --> 00:00:27,870
finding our widget and that's what it's called.

9
00:00:27,870 --> 00:00:28,910
It's binding a widget.

10
00:00:28,920 --> 00:00:34,470
And when you bind a widget, you're saying, hey, when you do something in this widget with, for instance,

11
00:00:34,470 --> 00:00:37,830
the mouse, sort of connect it to that widget.

12
00:00:37,830 --> 00:00:38,100
Right.

13
00:00:38,120 --> 00:00:44,790
So we're saying when we want to, like, move the mouse around the canvas record that make make note

14
00:00:44,790 --> 00:00:46,350
of that, bind that.

15
00:00:46,530 --> 00:00:46,740
Right.

16
00:00:46,840 --> 00:00:48,540
So to do that, we just bind it.

17
00:00:48,810 --> 00:00:50,790
We just bind the mouse to the canvas.

18
00:00:51,090 --> 00:00:52,410
And it's fairly simple.

19
00:00:52,410 --> 00:00:54,750
We just call my canvas dot bind.

20
00:00:56,390 --> 00:00:59,360
And this is a function now, what do we want to capture?

21
00:00:59,570 --> 00:01:04,100
Well, in this case, we want to capture the mouse moving around, but not just the mouse moving around.

22
00:01:04,400 --> 00:01:09,620
We also want to capture when we click the mouse button and then drag around, because that's how we're

23
00:01:09,620 --> 00:01:10,220
going to draw.

24
00:01:10,220 --> 00:01:11,480
We're going to click the mouse button.

25
00:01:11,630 --> 00:01:16,760
And while we're holding the mouse button down, we want to move the mouse around and then draw.

26
00:01:16,880 --> 00:01:19,940
And then when we let off the mouse button, we want it to stop drawing.

27
00:01:20,100 --> 00:01:26,990
So that is a special kind of mouse binding called One Motion.

28
00:01:27,140 --> 00:01:34,280
And to do that, to designate that, we use these brackets and then we just type B one as capital B

29
00:01:34,490 --> 00:01:35,630
dash motion.

30
00:01:35,900 --> 00:01:39,800
So B one stands for button one, which is the left mouse button.

31
00:01:40,020 --> 00:01:46,250
So we're going to left click the mouse button motion means we're moving the mouse right where it's motion.

32
00:01:46,430 --> 00:01:48,540
So that's how you bind that.

33
00:01:48,560 --> 00:01:54,980
Now what do we want to happen when we do that, when we click the canvas and move the mouse around,

34
00:01:54,980 --> 00:01:56,000
what do we want to happen?

35
00:01:56,180 --> 00:01:59,370
Or we want to run a function and we want to call that function paint.

36
00:01:59,600 --> 00:02:03,260
Now, we haven't actually created this function yet, so we need to do that now.

37
00:02:03,680 --> 00:02:05,200
So let's go ahead and do that.

38
00:02:05,810 --> 00:02:08,360
And I'm just going to come up here to the top.

39
00:02:09,660 --> 00:02:14,610
Of our program here, I like to do my functions all the time top and let's create a function called

40
00:02:14,610 --> 00:02:15,060
paint.

41
00:02:15,300 --> 00:02:20,780
Now, every time we create a function with a binding, we have to pass in an event.

42
00:02:21,000 --> 00:02:23,790
And here I'm passing in E stands for event.

43
00:02:23,950 --> 00:02:25,200
You could also type event.

44
00:02:25,680 --> 00:02:30,620
You could call this Bob if you want, but the convention is called E, which stands for event.

45
00:02:30,930 --> 00:02:31,800
What is an event.

46
00:02:32,040 --> 00:02:34,850
An event is when you do something right.

47
00:02:34,870 --> 00:02:41,600
So when you're moving your mouse around, that's a mouse event that you've now binded to the canvas.

48
00:02:41,910 --> 00:02:45,000
So it just keeps track of where the mouse is as you're moving it around.

49
00:02:45,300 --> 00:02:46,920
That's what the event is.

50
00:02:46,920 --> 00:02:48,510
It's the moving of the mouse.

51
00:02:48,690 --> 00:02:52,650
And by passing it into this function, we can keep track of where the mouse is.

52
00:02:52,860 --> 00:02:58,260
And later on, we're going to use that to say, draw where the mouse is when you click the button.

53
00:02:58,440 --> 00:02:58,790
Right.

54
00:02:59,010 --> 00:03:02,900
A little convoluted maybe, but it'll make more sense as we actually create it.

55
00:03:02,910 --> 00:03:05,730
So for now, we're not going to do that just yet.

56
00:03:05,730 --> 00:03:06,570
We're not there yet.

57
00:03:06,720 --> 00:03:08,460
For now, we just want to do something.

58
00:03:08,460 --> 00:03:09,240
What do we want to do?

59
00:03:09,450 --> 00:03:12,690
Well, let's change the color of the canvas whenever we click on it.

60
00:03:12,900 --> 00:03:19,860
So let's go my underscore canvas dot config and we use the config function to update widgets after the

61
00:03:19,860 --> 00:03:20,910
program has run.

62
00:03:21,270 --> 00:03:23,040
So we're running the program.

63
00:03:23,040 --> 00:03:24,090
Then we want to configure it.

64
00:03:24,090 --> 00:03:24,960
What do we want to do?

65
00:03:25,230 --> 00:03:27,720
Or remember down here we had the background color as white.

66
00:03:28,080 --> 00:03:30,390
We can change the background color to anything else.

67
00:03:30,390 --> 00:03:31,860
Let's just change it to black.

68
00:03:31,890 --> 00:03:32,210
Right?

69
00:03:32,490 --> 00:03:37,800
So when we click on the canvas and drag the mouse, it should change to black if we've done it right.

70
00:03:37,800 --> 00:03:42,990
So let's go and save this and head back over here to your terminal and run this guy again.

71
00:03:43,500 --> 00:03:50,010
And you can see we still got our red lines on here, so I'm about to click boom changes it to black.

72
00:03:50,010 --> 00:03:54,060
If I click again, it doesn't change it back again because we haven't programmed it to do that.

73
00:03:54,060 --> 00:03:59,340
It just changes the changes that the black and the red lines haven't changed, just the canvas background

74
00:03:59,340 --> 00:03:59,730
color.

75
00:04:00,060 --> 00:04:05,490
But we've now created a binding for our mouse.

76
00:04:05,490 --> 00:04:06,870
It's now bound to this widget.

77
00:04:06,870 --> 00:04:11,370
And we can test this by, for instance, coming down here and I'm going to click the button and drag

78
00:04:11,370 --> 00:04:12,210
down here.

79
00:04:12,630 --> 00:04:13,470
Nothing happens.

80
00:04:13,470 --> 00:04:14,400
Can you hear me clicking?

81
00:04:16,570 --> 00:04:21,130
My mouse is pretty silent, but I'm clicking the mouse and dragging, and nothing happens only when

82
00:04:21,130 --> 00:04:26,950
we do it in the canvas because we only binded it bounded around, I guess, to the canvas.

83
00:04:26,960 --> 00:04:27,880
So if I do it here.

84
00:04:30,070 --> 00:04:34,450
It changes color so very cool and very, very easy, and that's all there is to that.

85
00:04:34,460 --> 00:04:39,790
So we are now a good portion of a good way towards drawing.

86
00:04:39,790 --> 00:04:41,880
We've got we know how to draw a line.

87
00:04:42,070 --> 00:04:49,020
We know how to bring the mouse into play and sort of have that deal with the function really quickly.

88
00:04:49,030 --> 00:04:50,680
We can look at this, be one motion.

89
00:04:50,690 --> 00:04:52,750
Remember, this is pressing button one.

90
00:04:52,960 --> 00:04:56,860
If we just do motion, that just means we're moving the mouse into there.

91
00:04:57,100 --> 00:04:58,360
We're not actually clicking a button.

92
00:04:58,360 --> 00:05:02,470
So if we save this and just look at this real quick, if we run this.

93
00:05:04,720 --> 00:05:10,120
So here's my mouse, as soon as I bring it in here, boom, it changes color because all it takes is

94
00:05:10,120 --> 00:05:13,600
just a little motion of the mouse in there and then it runs.

95
00:05:13,600 --> 00:05:18,190
So we want a BE1 motion because we're always going to be clicking the button to draw.

96
00:05:18,340 --> 00:05:18,750
Right.

97
00:05:19,390 --> 00:05:24,220
But if for some reason you didn't want that, you could just call motion.

98
00:05:24,580 --> 00:05:27,390
So the other button, I believe, is B3.

99
00:05:27,400 --> 00:05:33,610
If we save this and, you know, my computer mice, mouses, whatever the plural is for a computer,

100
00:05:33,610 --> 00:05:35,600
mouse usually has two buttons.

101
00:05:35,600 --> 00:05:37,650
So let's see the right button.

102
00:05:38,140 --> 00:05:38,560
Yeah.

103
00:05:38,740 --> 00:05:41,500
If I click the right button, boom, that's B three.

104
00:05:41,890 --> 00:05:43,060
And why not be two.

105
00:05:43,060 --> 00:05:45,370
Because back in the day computer mouses.

106
00:05:45,580 --> 00:05:46,300
It sounds weird to me.

107
00:05:46,310 --> 00:05:51,490
Computer mice used to have three buttons, one in the middle usually now they have a ruler in the middle,

108
00:05:51,640 --> 00:05:53,710
not a third mouse button.

109
00:05:53,710 --> 00:05:56,320
So Kintyre has button.

110
00:05:56,620 --> 00:06:01,750
Button one is the left one, button three is the right one and button two is probably the middle one.

111
00:06:01,750 --> 00:06:05,110
But you're going to be hard pressed to find a mouse with three buttons these days.

112
00:06:05,290 --> 00:06:07,240
So that's all there is to this.

113
00:06:07,240 --> 00:06:12,550
In the next video, we're going to start to bring in bring this all together, use the mouse motion

114
00:06:12,550 --> 00:06:17,410
and creating lines to start to draw on the actual canvas with the mouse.

115
00:06:17,410 --> 00:06:18,940
And that'll be coming up in the next video.
