mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Always use View.focused in handlers without caching view locally, as it can be modified elsewhere.
This commit is contained in:
parent
e0f13dd3a0
commit
fc32a6757a
1 changed files with 9 additions and 10 deletions
|
@ -371,25 +371,24 @@ var View = this.View = Base.extend({
|
||||||
*/
|
*/
|
||||||
onResize: null
|
onResize: null
|
||||||
}, new function() { // Injection scope for mouse handlers
|
}, new function() { // Injection scope for mouse handlers
|
||||||
var view,
|
var tool,
|
||||||
tool,
|
|
||||||
timer,
|
timer,
|
||||||
curPoint,
|
curPoint,
|
||||||
dragging = false;
|
dragging = false;
|
||||||
|
|
||||||
function viewToArtwork(event) {
|
function viewToArtwork(view, event) {
|
||||||
return view.viewToArtwork(DomEvent.getOffset(event, view._canvas));
|
return view.viewToArtwork(DomEvent.getOffset(event, view._canvas));
|
||||||
}
|
}
|
||||||
|
|
||||||
function mousemove(event) {
|
function mousemove(event) {
|
||||||
DomEvent.stop(event);
|
var view = View.focused;
|
||||||
if (!view || !(tool = view._scope.tool))
|
if (!view || !(tool = view._scope.tool))
|
||||||
return;
|
return;
|
||||||
// If the event was triggered by a touch screen device, prevent the
|
// If the event was triggered by a touch screen device, prevent the
|
||||||
// default behaviour, as it will otherwise scroll the page:
|
// default behaviour, as it will otherwise scroll the page:
|
||||||
if (event && event.targetTouches)
|
if (event && event.targetTouches)
|
||||||
DomEvent.preventDefault(event);
|
DomEvent.preventDefault(event);
|
||||||
var point = event && viewToArtwork(event);
|
var point = event && viewToArtwork(view, event);
|
||||||
var onlyMove = !!(!tool.onMouseDrag && tool.onMouseMove);
|
var onlyMove = !!(!tool.onMouseDrag && tool.onMouseMove);
|
||||||
if (dragging && !onlyMove) {
|
if (dragging && !onlyMove) {
|
||||||
curPoint = point || curPoint;
|
curPoint = point || curPoint;
|
||||||
|
@ -404,6 +403,7 @@ var View = this.View = Base.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
function mouseup(event) {
|
function mouseup(event) {
|
||||||
|
var view = View.focused;
|
||||||
if (!view || !dragging)
|
if (!view || !dragging)
|
||||||
return;
|
return;
|
||||||
dragging = false;
|
dragging = false;
|
||||||
|
@ -411,9 +411,8 @@ var View = this.View = Base.extend({
|
||||||
if (tool) {
|
if (tool) {
|
||||||
if (timer != null)
|
if (timer != null)
|
||||||
timer = clearInterval(timer);
|
timer = clearInterval(timer);
|
||||||
if (tool.onHandleEvent('mouseup', viewToArtwork(event), event))
|
if (tool.onHandleEvent('mouseup', viewToArtwork(view, event), event))
|
||||||
view.draw(true);
|
view.draw(true);
|
||||||
DomEvent.stop(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,14 +438,14 @@ var View = this.View = Base.extend({
|
||||||
|
|
||||||
return {
|
return {
|
||||||
_createEvents: function() {
|
_createEvents: function() {
|
||||||
var that = this;
|
var view = this;
|
||||||
|
|
||||||
function mousedown(event) {
|
function mousedown(event) {
|
||||||
// Tell the Key class which view should receive keyboard input.
|
// Tell the Key class which view should receive keyboard input.
|
||||||
view = View.focused = that;
|
View.focused = view;
|
||||||
if (!(tool = view._scope.tool))
|
if (!(tool = view._scope.tool))
|
||||||
return;
|
return;
|
||||||
curPoint = viewToArtwork(event);
|
curPoint = viewToArtwork(view, event);
|
||||||
if (tool.onHandleEvent('mousedown', curPoint, event))
|
if (tool.onHandleEvent('mousedown', curPoint, event))
|
||||||
view.draw(true);
|
view.draw(true);
|
||||||
if (tool.eventInterval != null)
|
if (tool.eventInterval != null)
|
||||||
|
|
Loading…
Reference in a new issue