We can enhance our mouse-handling too, so we
only leave a trail when the left mouse button is down.
The steps for doing this are:
- Declare a variable to keep track of whether the button is down
- Create a mousedown handler and set the variable to true if the left button has gone down
- Create a mouseup handler and set the variable to false if the left button has gone up
- In the MouseMoveHandler, only draw the mark if the variable is set to true
You may notice if you move the mouse quite quickly, the line drawn is somewhat spotty. We're going to fix that with a more sophisticated drawing program, but first we're going to introduce a new way of storing variables.