I am writing a rudimentary drawing app for my own amusement. The app uses a canvas control on a window .
The user clicks on a button representing a set of primitives. This sets a variable to either ‘line’ , ‘rectangle’,’ circle’ and so on, so the app knows what to draw.
here is the code for the pushbutton action event.
dmode="line"// Dmode is the drawing mode
Once the mouse pointer begins moving on the canvas area it will not start drawing the shape until the mousedown event is triggered. mousedown code as follows;
PenDown=true// allow the canvas to draw
spx=x// starting point for x
spy=y// starting point for y
return true// recognise the mouse up event
code for the mouse move event
if PenDown=true then// PenDown must be testing false because this block does not process
epx=x// end point for x
epy=y// end point for y
self.Invalidate// fire the paint event
when the user has drawn the desired shape and the mouse up event is fired, mouse movement on the canvas no longer draws anything.
mouse up event
PenDown=false// stop drawing
The problem that I am having is that an if then statement is not testing the boolean variable ‘PenDown’ or 'PenDown is testing false. If it is false, I have no clue why because there is nothing between mousedown, mouse move and mouse up that could set it to false. To add to my confusion, the PenDown value does not even appear in the snapshot values if I add a breakpoint.
The PenDown variable is a property of the form the canvas is on, so I know that the scope aspect is ok. I have also tested PenDown
in the mousedown event and it tests true, so I know that it is set in readiness of the mouse move event.
Hi Tomas, I shouldn’t need “EndIf” should I? Surely ‘End’ should suffice or else the compiler would raise an error .The remarks were added for clarity on the forum. They don’t actually appear in my code.
I know that it draws because I have already done what you suggested. Never posted a project on a forum before. How do I do that?
Its a Mac project. BTW Jeff, tried your suggestion a bottle of jack Daniels ago.
Will, Ulrich and Jeff. Indeed you were all correct in your suggestions. The mousedrag is the event to use for this solution.
All seems to be working as planned now. Just another trap for new users of Xojo.