pd-lua icon indicating copy to clipboard operation
pd-lua copied to clipboard

additional `mouse_enter` and `mouse_exit` functions?

Open ben-wes opened this issue 1 year ago • 9 comments

the mouse_move(x, y) callback can be used to create hover feedback in pdlua GUI objects.

unfortunately, this has one major restriction though: the position is only reported on changes inside the object box and these changes are not necessarily reporting continuous coordinates. so there's no way to reliably determine whether the mouse has left the object area (or "crossed a border").

one option to deal with this might be additional functions. i learnt that @timothyschoen had these implemented some time ago and then removed them again since they seemed slightly hacky for vanilla. maybe they could be reconsidered though since they would allow for some additional interaction patterns.

one question in this context is whether mouse_enter and mouse_exit could also be achieved easily with purr data?

ben-wes avatar Oct 15 '24 16:10 ben-wes

hey maintainer can I work on the issue

Gorachand-Senapati avatar Dec 04 '24 08:12 Gorachand-Senapati

hey maintainer can I work on the issue

Not the maintainer, but if you want get started, I recommend looking at how else's [canvas.mouse] object works:

https://github.com/porres/pd-else/blob/9e5c2a23a77e9d413f03f283d9c6460203040217/Source/Control/canvas.mouse.c

timothyschoen avatar Dec 04 '24 11:12 timothyschoen

hey maintainer can I work on the issue

@Gorachand-Senapati just curious: did you start working on this?

ben-wes avatar Dec 23 '24 12:12 ben-wes

just noting here that in this context, it might be also nice to report the mouse_up() outside the object boundaries (after a mouse_down() inside) - not completely sure about that though.

ben-wes avatar Dec 25 '24 12:12 ben-wes

just noting here that in this context, it might be also nice to report the mouse_up() outside the object boundaries (after a mouse_down() inside) - not completely sure about that though.

Yes, I agree with this. I think the plugdata version might actually already do this, since this is how mouse events behave in JUCE. It's good if we can guarantee that every "mouse_down" will be followed by a "mouse_up", it makes it easier to write dragging logic.

edit: Testing in plugdata, it indeed already does this. pd-vanilla seems to do it too, except if you drag the mouse outside of the pd window. But it does seem like mouse_up still gets sent if the mouse is outside of object bounds.

timothyschoen avatar Dec 25 '24 12:12 timothyschoen

But it does seem like mouse_up still gets sent if the mouse is outside of object bounds.

ah damn. I was too quickly making false assumptions while experimenting with "long distance dragging". thanks for your tests!

ben-wes avatar Dec 25 '24 13:12 ben-wes

But it does seem like mouse_up still gets sent if the mouse is outside of object bounds.

tested this again here and i'm a bit irritated since i can't confirm it. mouse_up() is only called when there's an additional movement (unlike mouse_down() that fires directly when pressing the button) - and it only fires when the cursor is in the object boundaries for me.

this differs between plugdata and puredata though.

attaching a simple test object and patch: mouse_test.zip

ben-wes avatar Dec 25 '24 23:12 ben-wes

not sure if the issue of the held back mouse_up() can be easily solved here (i admittedly don't completely understand the logic):

https://github.com/agraef/pd-lua/blob/4301f744a9023ea77b6fe0ba35918ad18e19276f/pdlua.c#L826-L833

maybe we should adapt more of the event handling in https://github.com/porres/pd-else/blob/9e5c2a23a77e9d413f03f283d9c6460203040217/Source/Control/canvas.mouse.c ? (or similarly https://github.com/iem-projects/pd-iemguts/blob/main/src/receivecanvas.c )

ben-wes avatar Jan 03 '25 11:01 ben-wes

i created #70 now as a first draft for Pd vanilla. but it really feels a bit hacky with that canvas message proxy ...

https://github.com/user-attachments/assets/e2e1c4cd-2b04-4b6f-83c8-9235bcb9e77b

some details (possibly for discussion):

  • mouse_enter() and mouse_exit() are not called while dragging
  • on mouse_up() after dragging outside, mouse_up() and mouse_exit() are called immediately

ben-wes avatar Jan 16 '25 21:01 ben-wes