Skip to content

Commit 213cc61

Browse files
committed
1 parent bd0b280 commit 213cc61

1 file changed

Lines changed: 51 additions & 52 deletions

File tree

src/easeljs/display/Stage.js

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ this.createjs = this.createjs||{};
6363
**/
6464
function Stage(canvas) {
6565
this.Container_constructor();
66-
67-
66+
67+
6868
// public properties:
6969
/**
7070
* Indicates whether the stage should automatically clear the canvas before each render. You can set this to <code>false</code>
@@ -81,7 +81,7 @@ this.createjs = this.createjs||{};
8181
* @default true
8282
**/
8383
this.autoClear = true;
84-
84+
8585
/**
8686
* The canvas the stage will render to. Multiple stages can share a single canvas, but you must disable autoClear for all but the
8787
* first stage that will be ticked (or they will clear each other's render).
@@ -97,7 +97,7 @@ this.createjs = this.createjs||{};
9797
* @type HTMLCanvasElement | Object
9898
**/
9999
this.canvas = (typeof canvas == "string") ? document.getElementById(canvas) : canvas;
100-
100+
101101
/**
102102
* The current mouse X position on the canvas. If the mouse leaves the canvas, this will indicate the most recent
103103
* position over the canvas, and mouseInBounds will be set to false.
@@ -106,7 +106,7 @@ this.createjs = this.createjs||{};
106106
* @readonly
107107
**/
108108
this.mouseX = 0;
109-
109+
110110
/**
111111
* The current mouse Y position on the canvas. If the mouse leaves the canvas, this will indicate the most recent
112112
* position over the canvas, and mouseInBounds will be set to false.
@@ -115,15 +115,15 @@ this.createjs = this.createjs||{};
115115
* @readonly
116116
**/
117117
this.mouseY = 0;
118-
118+
119119
/**
120120
* Specifies the area of the stage to affect when calling update. This can be use to selectively
121121
* re-draw specific regions of the canvas. If null, the whole canvas area is drawn.
122122
* @property drawRect
123123
* @type {Rectangle}
124124
*/
125125
this.drawRect = null;
126-
126+
127127
/**
128128
* Indicates whether display objects should be rendered on whole pixels. You can set the
129129
* {{#crossLink "DisplayObject/snapToPixel"}}{{/crossLink}} property of
@@ -133,23 +133,23 @@ this.createjs = this.createjs||{};
133133
* @default false
134134
**/
135135
this.snapToPixelEnabled = false;
136-
136+
137137
/**
138138
* Indicates whether the mouse is currently within the bounds of the canvas.
139139
* @property mouseInBounds
140140
* @type Boolean
141141
* @default false
142142
**/
143143
this.mouseInBounds = false;
144-
144+
145145
/**
146146
* If true, tick callbacks will be called on all display objects on the stage prior to rendering to the canvas.
147147
* @property tickOnUpdate
148148
* @type Boolean
149149
* @default true
150150
**/
151151
this.tickOnUpdate = true;
152-
152+
153153
/**
154154
* If true, mouse move events will continue to be called when the mouse leaves the target canvas. See
155155
* {{#crossLink "Stage/mouseInBounds:property"}}{{/crossLink}}, and {{#crossLink "MouseEvent"}}{{/crossLink}}
@@ -159,8 +159,8 @@ this.createjs = this.createjs||{};
159159
* @default false
160160
**/
161161
this.mouseMoveOutside = false;
162-
163-
162+
163+
164164
/**
165165
* Prevents selection of other elements in the html page if the user clicks and drags, or double clicks on the canvas.
166166
* This works by calling `preventDefault()` on any mousedown events (or touch equivalent) originating on the canvas.
@@ -169,15 +169,15 @@ this.createjs = this.createjs||{};
169169
* @default true
170170
**/
171171
this.preventSelection = true;
172-
172+
173173
/**
174174
* The hitArea property is not supported for Stage.
175175
* @property hitArea
176176
* @type {DisplayObject}
177177
* @default null
178178
*/
179-
180-
179+
180+
181181
// private properties:
182182
/**
183183
* Holds objects with data for each active pointer id. Each object has the following properties:
@@ -187,45 +187,45 @@ this.createjs = this.createjs||{};
187187
* @private
188188
*/
189189
this._pointerData = {};
190-
190+
191191
/**
192192
* Number of active pointers.
193193
* @property _pointerCount
194194
* @type {Object}
195195
* @private
196196
*/
197197
this._pointerCount = 0;
198-
198+
199199
/**
200200
* The ID of the primary pointer.
201201
* @property _primaryPointerID
202202
* @type {Object}
203203
* @private
204204
*/
205205
this._primaryPointerID = null;
206-
206+
207207
/**
208208
* @property _mouseOverIntervalID
209209
* @protected
210210
* @type Number
211211
**/
212212
this._mouseOverIntervalID = null;
213-
213+
214214
/**
215215
* @property _nextStage
216216
* @protected
217217
* @type Stage
218218
**/
219219
this._nextStage = null;
220-
220+
221221
/**
222222
* @property _prevStage
223223
* @protected
224224
* @type Stage
225225
**/
226226
this._prevStage = null;
227-
228-
227+
228+
229229
// initialize:
230230
this.enableDOMEvents(true);
231231
}
@@ -269,35 +269,35 @@ this.createjs = this.createjs||{};
269269
* @event mouseenter
270270
* @since 0.7.0
271271
*/
272-
272+
273273
/**
274274
* Dispatched each update immediately before the tick event is propagated through the display list.
275275
* You can call preventDefault on the event object to cancel propagating the tick event.
276276
* @event tickstart
277277
* @since 0.7.0
278278
*/
279-
279+
280280
/**
281281
* Dispatched each update immediately after the tick event is propagated through the display list. Does not fire if
282282
* tickOnUpdate is false. Precedes the "drawstart" event.
283283
* @event tickend
284284
* @since 0.7.0
285285
*/
286-
286+
287287
/**
288288
* Dispatched each update immediately before the canvas is cleared and the display list is drawn to it.
289289
* You can call preventDefault on the event object to cancel the draw.
290290
* @event drawstart
291291
* @since 0.7.0
292292
*/
293-
293+
294294
/**
295295
* Dispatched each update immediately after the display list is drawn to the canvas and the canvas context is restored.
296296
* @event drawend
297297
* @since 0.7.0
298298
*/
299299

300-
300+
301301
// getter / setters:
302302
/**
303303
* Specifies a target stage that will have mouse / touch interactions relayed to it after this stage handles them.
@@ -307,7 +307,7 @@ this.createjs = this.createjs||{};
307307
* topStage.nextStage = bottomStage;
308308
*
309309
* To disable relaying, set nextStage to null.
310-
*
310+
*
311311
* MouseOver, MouseOut, RollOver, and RollOut interactions are also passed through using the mouse over settings
312312
* of the top-most stage, but are only processed if the target stage has mouse over interactions enabled.
313313
* Considerations when using roll over in relay targets:<OL>
@@ -320,12 +320,12 @@ this.createjs = this.createjs||{};
320320
* topStage.nextStage = targetStage;
321321
* topStage.enableMouseOver(10);
322322
* targetStage.enableMouseOver(30);
323-
*
323+
*
324324
* If the target stage's canvas is completely covered by this stage's canvas, you may also want to disable its
325325
* DOM events using:
326-
*
326+
*
327327
* targetStage.enableDOMEvents(false);
328-
*
328+
*
329329
* @property nextStage
330330
* @type {Stage}
331331
**/
@@ -337,7 +337,7 @@ this.createjs = this.createjs||{};
337337
if (value) { value._prevStage = this; }
338338
this._nextStage = value;
339339
};
340-
340+
341341
try {
342342
Object.defineProperties(p, {
343343
nextStage: { get: p._get_nextStage, set: p._set_nextStage }
@@ -409,18 +409,18 @@ this.createjs = this.createjs||{};
409409
* function handleTick(evtObj) {
410410
* // clone the event object from Ticker, and add some custom data to it:
411411
* var evt = evtObj.clone().set({greeting:"hello", name:"world"});
412-
*
412+
*
413413
* // pass it to stage.update():
414414
* myStage.update(evt); // subsequently calls tick() with the same param
415415
* }
416-
*
416+
*
417417
* // ...
418418
* myDisplayObject.on("tick", handleDisplayObjectTick);
419419
* function handleDisplayObjectTick(evt) {
420420
* console.log(evt.delta); // the delta property from the Ticker tick event object
421421
* console.log(evt.greeting, evt.name); // custom data: "hello world"
422422
* }
423-
*
423+
*
424424
* @method tick
425425
* @param {Object} [props] An object with properties that should be copied to the event object. Should usually be a Ticker event object, or similar object with a delta property.
426426
**/
@@ -482,7 +482,7 @@ this.createjs = this.createjs||{};
482482
data = ctx.getImageData(0, 0, w, h);
483483
var compositeOperation = ctx.globalCompositeOperation;
484484
ctx.globalCompositeOperation = "destination-over";
485-
485+
486486
ctx.fillStyle = backgroundColor;
487487
ctx.fillRect(0, 0, w, h);
488488
}
@@ -632,8 +632,7 @@ this.createjs = this.createjs||{};
632632
* @param {MouseEvent} e
633633
**/
634634
p._handleMouseMove = function(e) {
635-
if(!e){ e = window.event; }
636-
this._handlePointerMove(-1, e, e.pageX, e.pageY);
635+
this._handlePointerMove(-(e.button + 1), e, e.pageX, e.pageY);
637636
};
638637

639638
/**
@@ -656,11 +655,11 @@ this.createjs = this.createjs||{};
656655
if (id === -1 && o.inBounds == !inBounds) {
657656
this._dispatchMouseEvent(this, (inBounds ? "mouseleave" : "mouseenter"), false, id, o, e);
658657
}
659-
658+
660659
this._dispatchMouseEvent(this, "stagemousemove", false, id, o, e);
661660
this._dispatchMouseEvent(o.target, "pressmove", true, id, o, e);
662661
}
663-
662+
664663
nextStage&&nextStage._handlePointerMove(id, e, pageX, pageY, null);
665664
};
666665

@@ -707,7 +706,7 @@ this.createjs = this.createjs||{};
707706
* @param {MouseEvent} e
708707
**/
709708
p._handleMouseUp = function(e) {
710-
this._handlePointerUp(-1, e, false);
709+
this._handlePointerUp(-(e.button + 1), e, false);
711710
};
712711

713712
/**
@@ -721,20 +720,20 @@ this.createjs = this.createjs||{};
721720
p._handlePointerUp = function(id, e, clear, owner) {
722721
var nextStage = this._nextStage, o = this._getPointerData(id);
723722
if (this._prevStage && owner === undefined) { return; } // redundant listener.
724-
723+
725724
var target=null, oTarget = o.target;
726725
if (!owner && (oTarget || nextStage)) { target = this._getObjectsUnderPoint(o.x, o.y, null, true); }
727-
726+
728727
if (o.down) { this._dispatchMouseEvent(this, "stagemouseup", false, id, o, e, target); o.down = false; }
729-
728+
730729
if (target == oTarget) { this._dispatchMouseEvent(oTarget, "click", true, id, o, e); }
731730
this._dispatchMouseEvent(oTarget, "pressup", true, id, o, e);
732-
731+
733732
if (clear) {
734733
if (id==this._primaryPointerID) { this._primaryPointerID = null; }
735734
delete(this._pointerData[id]);
736735
} else { o.target = null; }
737-
736+
738737
nextStage&&nextStage._handlePointerUp(id, e, clear, owner || target && this);
739738
};
740739

@@ -744,7 +743,7 @@ this.createjs = this.createjs||{};
744743
* @param {MouseEvent} e
745744
**/
746745
p._handleMouseDown = function(e) {
747-
this._handlePointerDown(-1, e, e.pageX, e.pageY);
746+
this._handlePointerDown(-(e.button + 1), e, e.pageX, e.pageY);
748747
};
749748

750749
/**
@@ -759,14 +758,14 @@ this.createjs = this.createjs||{};
759758
p._handlePointerDown = function(id, e, pageX, pageY, owner) {
760759
if (this.preventSelection) { e.preventDefault(); }
761760
if (this._primaryPointerID == null || id === -1) { this._primaryPointerID = id; } // mouse always takes over.
762-
761+
763762
if (pageY != null) { this._updatePointerPosition(id, e, pageX, pageY); }
764763
var target = null, nextStage = this._nextStage, o = this._getPointerData(id);
765764
if (!owner) { target = o.target = this._getObjectsUnderPoint(o.x, o.y, null, true); }
766765

767766
if (o.inBounds) { this._dispatchMouseEvent(this, "stagemousedown", false, id, o, e, target); o.down = true; }
768767
this._dispatchMouseEvent(target, "mousedown", true, id, o, e);
769-
768+
770769
nextStage&&nextStage._handlePointerDown(id, e, pageX, pageY, owner || target && this);
771770
};
772771

@@ -779,7 +778,7 @@ this.createjs = this.createjs||{};
779778
**/
780779
p._testMouseOver = function(clear, owner, eventTarget) {
781780
if (this._prevStage && owner === undefined) { return; } // redundant listener.
782-
781+
783782
var nextStage = this._nextStage;
784783
if (!this._mouseOverIntervalID) {
785784
// not enabled for mouseover, but should still relay the event.
@@ -794,7 +793,7 @@ this.createjs = this.createjs||{};
794793
var e = o.posEvtObj;
795794
var isEventTarget = eventTarget || e&&(e.target == this.canvas);
796795
var target=null, common = -1, cursor="", t, i, l;
797-
796+
798797
if (!owner && (clear || this.mouseInBounds && isEventTarget)) {
799798
target = this._getObjectsUnderPoint(this.mouseX, this.mouseY, null, true);
800799
this._mouseOverX = this.mouseX;
@@ -838,7 +837,7 @@ this.createjs = this.createjs||{};
838837
this._dispatchMouseEvent(target, "mouseover", true, -1, o, e, oldTarget);
839838
}
840839
}
841-
840+
842841
nextStage&&nextStage._testMouseOver(clear, owner || target && this, eventTarget || isEventTarget && this);
843842
};
844843

0 commit comments

Comments
 (0)