Skip to content

add some convience classes for external mouse tracking

Jonathan Wilkes requested to merge legacy-mouse-buddies into master

add some rudimentary mouse tracking objects so that the questionable C code in the various mouse-related classes can be replaced with abstractions:

  • mouseclick - track mouseup and mousedown state, including position on canvas at the time of click
  • mousemotion - track mousemove events sent from the GUI. Relative to the DOM window over which the mouse is currenty being moved
  • mousewheel - track mousewheel motion. (Not implemented yet, but a user requested it and it should be easy enough.)

These classes can track mouse actions across all open canvas windows. For coordinates they return x/y positions relative to the DOM window over which the mouse is currently being tracked.

IMO this is an inferior interface to the mouse methods for data structures that I implemented. The relevant [draw] methods only work on a specified area of the canvas and are thus less prone to getting in the way of audio computation. Also, the [draw] methods can be used to turn mouse events like mousemove on and off at will (or even selectively turned on for only certain scalar instances and not others). [mousemotion] will inescapably try to send output for every mousemove event. (I could add a method to toggle this, but canvas_motion would still need to dispatch to all receivers so that they could check their own toggle state, which probably defeats the purpose...)

Still, there are probably lots of tutorials in the wild built atop legacy externals that want to just mindlessly poll mouse position. If the idea is to just map freq./amp./etc. to mouse position, they serve their purpose. Thus, it's easier to just build abstractions around these new mouse classes than it would be to re-implement every ad-hoc Pd<->GUI interface in these externals.

I haven't tested the performance of the changes to canvas_motion in g_editor.c yet. As long as none of these mouse objects exist the affect should be negligible (just a check for existence, a a pointer dereference, and a one-time gensym). Once there is a [mousemotion] there is an additional method call to it for every tick of the mouse.

Edited by Jonathan Wilkes

Merge request reports