From 17b9d73e09fdeadb68dd3e1a984a309718bb7aa4 Mon Sep 17 00:00:00 2001 From: Jonathan Wilkes <jon.w.wilkes@gmail.com> Date: Fri, 29 Jan 2016 17:55:24 -0500 Subject: [PATCH] Added transformed dx/dy for scalar "drag" events. This can be revisited if it turns out to be a CPU hog. --- pd/nw/pd_canvas.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pd/nw/pd_canvas.js b/pd/nw/pd_canvas.js index a354cc8d1..e62bfd49d 100644 --- a/pd/nw/pd_canvas.js +++ b/pd/nw/pd_canvas.js @@ -420,11 +420,23 @@ var canvas_events = (function() { }, scalar_draggable_mousemove: function(evt) { var new_x = evt.pageX, - new_y = evt.pageY; + new_y = evt.pageY, + dx = new_x - last_draggable_x, + dy = new_y - last_draggable_y, + // For the sake of convenience we're sending transformed + // dx and dy back to the user. If it turns out this is + // expensive we can either optimize this or just leave it + // up to the user to handle on their own. (But I should + // mention that it was non-trivial for me to do the math + // of inverting and multiplying the matrices from within + // a Pd patch. And I'm the author of this API. Make + // of that what you will... + minv = draggable_elem.getCTM().inverse(), + tx = minv.a * dx + minv.c * dy, + ty = minv.b * dx + minv.d * dy; var obj = scalar_draggables[draggable_elem.id]; pdgui.pdsend(obj.cid, "scalar_event", obj.scalar_sym, - obj.drawcommand_sym, obj.event_name, new_x - last_draggable_x, - new_y - last_draggable_y); + obj.drawcommand_sym, obj.event_name, dx, dy, tx, ty); last_draggable_x = new_x; last_draggable_y = new_y; }, -- GitLab