IsMouseDown - drawing while button is pressed?

In another post, I mentioned that a 64bit build of my WIndows app works when using 2015, but fails to invalidate the screen in compiled code from 2018
Asked to produce a ‘simple example’, I have been forced to revisit some of the rubbish I had to go through years back to make ‘drawing under the control of the mouse’ happen at all.

You might imagine:

Click and drag on a canvas, drawing rectangles as you go

would be easy.
But in practice, in the mousemove event, there is no ‘isMouseDown’ parameter.
Keyboard.async… has nothing about it either

So you have to trap mouse down in the mousedown event, and remember.
Then, in the mouse move event, only try to draw if a property like ‘mousewaspressed’ is true.

We can’t draw directly to the graphics of the canvas any more.
So we create and draw on an offscreen picture, and draw that to the canvas in the paint event.

However, even when calling Invalidate, the invalidation/redrawing doesn’t happen WHILE THE MOUSE IS PRESSED.

The whole thing feels back to front to me.
Stuff is different on Windows, but this is on Mac

1/ I should be able to detect if the mouse is down during a Mouse Move. (it’s part of the WM_MOUSEMOVE message handling on Windows - mouse events and keyboard CTRL/SHIFT states are parameters)

2/ I should be able to make the canvas refresh the area under the mouse if the button is down while moving

Add a property MouseIsDown to your canvas.
in MouseDown set it to true and return true

In mouseMove you could now do the drawing (set flags or whatever) ?

in MouseUp set MouseIsDown to false…

1 Like

there is also a System.MouseDown. for right button IsContextualClick

What about the mouseDrag event of a canvas?
https://documentation.xojo.com/MouseDrag_event

1 Like

Add a property MouseIsDown to your canvas.
in MouseDown set it to true and return true

In mouseMove you could now do the drawing (set flags or whatever) ?

in MouseUp set MouseIsDown to false…

Yeah,I know.
Doesn’t work.
The canvas does not update while the mouse button is down and the mouse is moved.

A window with a canvas, a window property of type picture (theStaticBit, initialised in Open), and a property of bDrawing (boolean)

Canvas1 Mousedown:
bDrawing = True

If I add return = false or omit it, Mouseup never fires.
Nothing is drawn while mouse is down, but stuff does draw while mouse is moved but not pressed

If Return = true, nothing happens in Mousemove at all, but mouseup does fire

Canvas1 Mousemove:
If bdrawing Then
  theStaticBit.Graphics.fillrect x-20,y-20,40,40
  canvas1.invalidate  
End If

This is the mouseup

MouseUP:
bdrawing = false

The paint event…just draws what the offscreen picture holds

Canvas1 Paint:

g.DrawPicture theStaticBit,0,0

MouseMove event not come at windows if you hold the mouse button.
Add
System.DebugLog CurrentMethodName

Exactly.
Bear in mind I’m ultimately trying to create a simple example of why things don’t work in a 64bit windows build.
These are problems I ‘solved’ years ago, but faced all over again when trying from a ‘bare bones’ project.

Mousedrag works if I return true in mousedown - (lthough to be fair, I dont consider that Im dragging anything…)

On windows, I then need (ed?) to subclass the window in order to recreate the mousedrag stuff.

Gonna mark this as solved, in an attempt to close it. Its gone off track a bit, but the forum doesnt let me hide it or close it .

i agree that realtime graphics in xojo with mouse interactions is very difficult.
you can make life easier if you use your own mouse class.

if me not know when events come i put System.DebugLog in each.

1 Like