Make item-level mousedrag events work again.

This commit is contained in:
Jürg Lehni 2016-01-27 12:11:59 +01:00
parent d72db14c1f
commit 0cfa83fc32
2 changed files with 21 additions and 13 deletions

View file

@ -11,7 +11,9 @@
svg.visible = true; // Turn off display: none; svg.visible = true; // Turn off display: none;
// Resize the tiger to fit within the window: // Resize the tiger to fit within the window:
svg.fitBounds(view.bounds); view.on('resize', function() {
svg.fitBounds(this.bounds);
});
var items = project.activeLayer.firstChild.children; var items = project.activeLayer.firstChild.children;
var mouseIsDown = false; var mouseIsDown = false;

View file

@ -104,8 +104,10 @@ var View = Base.extend(Emitter, /** @lends View# */{
// Items that need the onFrame handler called on them // Items that need the onFrame handler called on them
this._frameItems = {}; this._frameItems = {};
this._frameItemCount = 0; this._frameItemCount = 0;
// Count the installed item events, see _countItemEvent(). // Count the installed native and virtual item events,
this._itemEvents = {}; // see #_countItemEvent():
this._itemNativeEvents = {};
this._itemVirtualEvents = {};
}, },
/** /**
@ -1137,7 +1139,7 @@ new function() { // Injection scope for event handling on the browser
* Required by code that is counting the amount of required natives events. * Required by code that is counting the amount of required natives events.
* The mapping is native -> virtual. * The mapping is native -> virtual.
*/ */
var itemEvents = { var itemNativeEvents = {
mousedown: { mousedown: {
mousedown: 1, mousedown: 1,
mousedrag: 1, mousedrag: 1,
@ -1180,12 +1182,12 @@ new function() { // Injection scope for event handling on the browser
* tools. * tools.
*/ */
_handleMouseEvent: function(type, event, point) { _handleMouseEvent: function(type, event, point) {
var handleItems = this._itemEvents[type], var hitItems = this._itemNativeEvents[type],
tool = this._scope.tool, tool = this._scope.tool,
view = this; view = this;
function responds(type) { function responds(type) {
return view._itemEvents[type] || view.responds(type) return view._itemVirtualEvents[type] || view.responds(type)
|| tool && tool.responds(type); || tool && tool.responds(type);
} }
@ -1199,9 +1201,9 @@ new function() { // Injection scope for event handling on the browser
point = this.getEventPoint(event); point = this.getEventPoint(event);
// Run the hit-test on items first, but only if we're required to do // Run the hit-test on items first, but only if we're required to do
// so for this given mouse event, see #_countItemEvent(). // so for this given mouse event, see hitItems, #_countItemEvent():
var inView = this.getBounds().contains(point), var inView = this.getBounds().contains(point),
hit = inView && handleItems && this._project.hitTest(point, { hit = inView && hitItems && this._project.hitTest(point, {
tolerance: 0, tolerance: 0,
fill: true, fill: true,
stroke: true stroke: true
@ -1327,12 +1329,16 @@ new function() { // Injection scope for event handling on the browser
_countItemEvent: function(type, sign) { _countItemEvent: function(type, sign) {
// If the view requires counting of installed mouse events, // If the view requires counting of installed mouse events,
// change the event counters now according to itemEvents. // change the event counters now according to itemNativeEvents
var events = this._itemEvents; // (defined in the code further above).
for (var key in itemEvents) { var nativeEvents = this._itemNativeEvents,
events[key] = (events[key] || 0) virtualEvents = this._itemVirtualEvents;
+ (itemEvents[key][type] || 0) * sign; for (var key in itemNativeEvents) {
nativeEvents[key] = (nativeEvents[key] || 0)
+ (itemNativeEvents[key][type] || 0) * sign;
} }
// Also update the count of virtual events installed.
virtualEvents[type] = (virtualEvents[type] || 0) + sign;
}, },
statics: { statics: {