25
25
****************************************************************************/
26
26
27
27
/** Layer will receive all the touches at once The onTouchesXXX API will be called
28
- */
28
+ */
29
29
cc . TOUCH_ALL_AT_ONCE = 0 ;
30
30
31
31
/** Layer will receive only one touch at the time. The onTouchXXX API will be called */
@@ -45,6 +45,7 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{
45
45
_touchPriority :0 ,
46
46
_touchMode :cc . TOUCH_ALL_AT_ONCE ,
47
47
_isMouseEnabled :false ,
48
+ _mousePriority :0 ,
48
49
49
50
/**
50
51
* Constructor
@@ -88,25 +89,43 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{
88
89
* If isTouchEnabled, this method is called onEnter.
89
90
*/
90
91
registerWithTouchDispatcher :function ( ) {
91
- if ( this . _touchMode === cc . TOUCH_ALL_AT_ONCE )
92
+ if ( this . _touchMode === cc . TOUCH_ALL_AT_ONCE )
92
93
cc . Director . getInstance ( ) . getTouchDispatcher ( ) . addStandardDelegate ( this , this . _touchPriority ) ;
93
94
else
94
95
cc . Director . getInstance ( ) . getTouchDispatcher ( ) . addTargetedDelegate ( this , this . _touchPriority , true ) ;
95
96
} ,
96
97
97
- isMouseEnabled :function ( ) {
98
- return this . _isMouseEnabled ;
98
+ isMouseEnabled :function ( ) {
99
+ return this . _isMouseEnabled ;
99
100
} ,
100
101
101
- setMouseEnabled :function ( enabled ) {
102
- if ( this . _isMouseEnabled != enabled ) {
102
+ setMouseEnabled :function ( enabled ) {
103
+ if ( this . _isMouseEnabled != enabled ) {
103
104
this . _isMouseEnabled = enabled ;
104
- if ( this . _isRunning ) {
105
+ if ( this . _isRunning ) {
106
+ if ( enabled )
107
+ cc . Director . getInstance ( ) . getMouseDispatcher ( ) . addMouseDelegate ( this , this . _mousePriority ) ;
108
+ else
109
+ cc . Director . getInstance ( ) . getMouseDispatcher ( ) . removeMouseDelegate ( this ) ;
110
+ }
111
+ }
112
+ } ,
105
113
114
+ setMousePriority :function ( priority ) {
115
+ if ( this . _mousePriority != priority ) {
116
+ this . _mousePriority = priority ;
117
+ // Update touch priority with handler
118
+ if ( this . _isMouseEnabled ) {
119
+ this . setMouseEnabled ( false ) ;
120
+ this . setMouseEnabled ( true ) ;
106
121
}
107
122
}
108
123
} ,
109
124
125
+ getMousePriority :function ( ) {
126
+ return this . _mousePriority ;
127
+ } ,
128
+
110
129
/**
111
130
* whether or not it will receive Touch events.<br/>
112
131
* You can enable / disable touch events with this property.<br/>
@@ -139,41 +158,41 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{
139
158
/** returns the priority of the touch event handler
140
159
* @return {Number }
141
160
*/
142
- getTouchPriority :function ( ) {
161
+ getTouchPriority :function ( ) {
143
162
return this . _touchPriority ;
144
163
} ,
145
164
146
165
/** Sets the touch event handler priority. Default is 0.
147
166
* @param {Number } priority
148
167
*/
149
- setTouchPriority :function ( priority ) {
150
- if ( this . _touchPriority != priority ) {
168
+ setTouchPriority :function ( priority ) {
169
+ if ( this . _touchPriority != priority ) {
151
170
this . _touchPriority = priority ;
152
171
// Update touch priority with handler
153
- if ( this . _isTouchEnabled ) {
154
- this . setTouchEnabled ( false ) ;
155
- this . setTouchEnabled ( true ) ;
172
+ if ( this . _isTouchEnabled ) {
173
+ this . setTouchEnabled ( false ) ;
174
+ this . setTouchEnabled ( true ) ;
156
175
}
157
176
}
158
177
} ,
159
178
160
179
/** returns the touch mode.
161
180
* @return {Number }
162
181
*/
163
- getTouchMode :function ( ) {
182
+ getTouchMode :function ( ) {
164
183
return this . _touchMode ;
165
184
} ,
166
185
167
186
/** Sets the touch mode.
168
187
* @param {Number } mode
169
188
*/
170
- setTouchMode :function ( mode ) {
171
- if ( this . _touchMode != mode ) {
189
+ setTouchMode :function ( mode ) {
190
+ if ( this . _touchMode != mode ) {
172
191
this . _touchMode = mode ;
173
192
// update the mode with handler
174
- if ( this . _isTouchEnabled ) {
175
- this . setTouchEnabled ( false ) ;
176
- this . setTouchEnabled ( true ) ;
193
+ if ( this . _isTouchEnabled ) {
194
+ this . setTouchEnabled ( false ) ;
195
+ this . setTouchEnabled ( true ) ;
177
196
}
178
197
}
179
198
} ,
@@ -249,14 +268,15 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{
249
268
this . _super ( ) ;
250
269
251
270
// add this layer to concern the Accelerometer Sensor
252
- if ( this . _isAccelerometerEnabled ) {
271
+ if ( this . _isAccelerometerEnabled )
253
272
director . getAccelerometer ( ) . setDelegate ( this ) ;
254
- }
255
273
256
274
// add this layer to concern the kaypad msg
257
- if ( this . _isKeyboardEnabled ) {
275
+ if ( this . _isKeyboardEnabled )
258
276
director . getKeyboardDispatcher ( ) . addDelegate ( this ) ;
259
- }
277
+
278
+ if ( this . _isMouseEnabled )
279
+ director . getMouseDispatcher ( ) . addMouseDelegate ( this , this . _mousePriority ) ;
260
280
} ,
261
281
262
282
/**
@@ -278,6 +298,9 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{
278
298
director . getKeyboardDispatcher ( ) . removeDelegate ( this ) ;
279
299
}
280
300
301
+ if ( this . _isMouseEnabled )
302
+ director . getMouseDispatcher ( ) . removeMouseDelegate ( this ) ;
303
+
281
304
this . _super ( ) ;
282
305
} ,
283
306
@@ -362,52 +385,138 @@ cc.Layer = cc.Node.extend(/** @lends cc.Layer# */{
362
385
363
386
// ---------------------CCMouseEventDelegate interface------------------------------
364
387
365
- //
366
- // left
367
- //
368
- onMouseDown :function ( event ) {
388
+ /**
389
+ * <p>called when the "mouseDown" event is received. <br/>
390
+ * Return YES to avoid propagating the event to other delegates. </p>
391
+ * @param event
392
+ * @return {Boolean }
393
+ */
394
+ onMouseDown :function ( event ) {
395
+ return false ;
369
396
} ,
370
397
371
- onMouseDragged :function ( event ) {
398
+ /**
399
+ * <p>called when the "mouseDragged" event is received. <br/>
400
+ * Return YES to avoid propagating the event to other delegates.</p>
401
+ * @param event
402
+ * @return {Boolean }
403
+ */
404
+ onMouseDragged :function ( event ) {
405
+ return false ;
372
406
} ,
373
407
374
- onMouseMoved : function ( event ) {
408
+ /**
409
+ * <p> called when the "mouseMoved" event is received. <br/>
410
+ * Return YES to avoid propagating the event to other delegates. </p>
411
+ * @param event
412
+ * @return {Boolean }
413
+ */
414
+ onMouseMoved :function ( event ) {
415
+ return false ;
375
416
} ,
376
417
377
- onMouseUp :function ( event ) {
418
+ /**
419
+ * <p> called when the "mouseUp" event is received. <br/>
420
+ * Return YES to avoid propagating the event to other delegates. </p>
421
+ * @param event
422
+ * @return {Boolean }
423
+ */
424
+ onMouseUp :function ( event ) {
425
+ return false ;
378
426
} ,
379
427
380
428
//right
381
-
382
- onRightMouseDown : function ( event ) {
429
+ /**
430
+ * <p> called when the "rightMouseDown" event is received. <br/>
431
+ * Return YES to avoid propagating the event to other delegates. </p>
432
+ * @param event
433
+ * @return {Boolean }
434
+ */
435
+ onRightMouseDown :function ( event ) {
436
+ return false ;
383
437
} ,
384
438
385
- onRightMouseDragged : function ( event ) {
439
+ /**
440
+ * <p> called when the "rightMouseDragged" event is received. <br/>
441
+ * Return YES to avoid propagating the event to other delegates. </p>
442
+ * @param event
443
+ * @return {Boolean }
444
+ */
445
+ onRightMouseDragged :function ( event ) {
446
+ return false ;
386
447
} ,
387
448
388
- onRightMouseUp : function ( event ) {
449
+ /**
450
+ * <p> called when the "rightMouseUp" event is received. <br/>
451
+ * Return YES to avoid propagating the event to other delegates. </p>
452
+ * @param event
453
+ * @return {Boolean }
454
+ */
455
+ onRightMouseUp :function ( event ) {
456
+ return false ;
389
457
} ,
390
458
391
459
//other
392
- onOtherMouseDown : function ( event ) {
460
+ /**
461
+ * <p>called when the "otherMouseDown" event is received. <br/>
462
+ * Return YES to avoid propagating the event to other delegates. </p>
463
+ * @param event
464
+ * @return {Boolean }
465
+ */
466
+ onOtherMouseDown :function ( event ) {
467
+ return false ;
393
468
} ,
394
469
395
- onOtherMouseDragged : function ( event ) {
470
+ /**
471
+ * <p> called when the "otherMouseDragged" event is received. <br/>
472
+ * Return YES to avoid propagating the event to other delegates. </p>
473
+ * @param event
474
+ * @return {Boolean }
475
+ */
476
+ onOtherMouseDragged :function ( event ) {
477
+ return false ;
396
478
} ,
397
479
398
- onOtherMouseUp :function ( event ) {
480
+ /**
481
+ * <p> called when the "otherMouseUp" event is received. <br/>
482
+ * Return YES to avoid propagating the event to other delegates. </p>
483
+ * @param event
484
+ * @return {Boolean }
485
+ */
486
+ onOtherMouseUp :function ( event ) {
487
+ return false ;
399
488
} ,
400
489
401
490
//scroll wheel
402
- onScrollWheel : function ( event ) {
491
+ /**
492
+ * <p> called when the "scrollWheel" event is received. <br/>
493
+ * Return YES to avoid propagating the event to other delegates. </p>
494
+ * @param event
495
+ * @return {Boolean }
496
+ */
497
+ onScrollWheel :function ( event ) {
498
+ return false ;
403
499
} ,
404
500
405
501
// enter / exit
406
-
407
- onMouseEntered :function ( theEvent ) {
502
+ /**
503
+ * <p> called when the "mouseEntered" event is received. <br/>
504
+ * Return YES to avoid propagating the event to other delegates. </p>
505
+ * @param theEvent
506
+ * @return {Boolean }
507
+ */
508
+ onMouseEntered :function ( theEvent ) {
509
+ return false ;
408
510
} ,
409
511
410
- onMouseExited :function ( theEvent ) {
512
+ /**
513
+ * <p> called when the "mouseExited" event is received. <br/>
514
+ * Return YES to avoid propagating the event to other delegates. </p>
515
+ * @param theEvent
516
+ * @return {Boolean }
517
+ */
518
+ onMouseExited :function ( theEvent ) {
519
+ return false ;
411
520
}
412
521
} ) ;
413
522
@@ -709,7 +818,7 @@ cc.LayerGradient = cc.LayerColor.extend(/** @lends cc.LayerGradient# */{
709
818
layerWidth = layerWidth || this . getContentSize ( ) . width ;
710
819
layerHeight = layerHeight || this . getContentSize ( ) . height ;
711
820
712
- if ( ! this . _sourceGradientCanvas )
821
+ if ( ! this . _sourceGradientCanvas )
713
822
this . _sourceGradientCanvas = document . createElement ( 'canvas' ) ;
714
823
this . _sourceGradientCanvas . width = 2 ;
715
824
this . _sourceGradientCanvas . height = 2 ;
@@ -721,7 +830,7 @@ cc.LayerGradient = cc.LayerColor.extend(/** @lends cc.LayerGradient# */{
721
830
var image_colors = context_colors . getImageData ( 0 , 0 , 2 , 2 ) ;
722
831
var data = image_colors . data ;
723
832
724
- if ( ! this . _drawGradientCanvas )
833
+ if ( ! this . _drawGradientCanvas )
725
834
this . _drawGradientCanvas = document . createElement ( 'canvas' ) ;
726
835
this . _drawGradientCanvas . width = layerWidth ;
727
836
this . _drawGradientCanvas . height = layerHeight ;
0 commit comments