Skip to content

Commit d562f30

Browse files
committed
righ click event handlers added
righ click event handlers added (there was some code i finished)
1 parent e92ac25 commit d562f30

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

cocos2d/touch_dispatcher/CCMouseDispatcher.js

+42-7
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,15 @@ cc.MouseHandler.create = function (delegate, priority) {
349349

350350
cc.MouseDispatcher = cc.Class.extend({
351351
_mousePressed:false,
352+
_rightMousePressed:false,
352353
_mouseDelegateHandlers:null,
353354
_dispatchEvents:false,
354355

355356
init:function () {
356357
this._dispatchEvents = true;
357358
this._mouseDelegateHandlers = [];
358359
this._mousePressed = false;
360+
this._rightMousePressed = false;
359361

360362
cc.MouseDispatcher._registerHtmlElementEvent(cc.canvas);
361363
return true;
@@ -368,6 +370,14 @@ cc.MouseDispatcher = cc.Class.extend({
368370
_getMousePressed:function () {
369371
return this._mousePressed;
370372
},
373+
374+
_setRightMousePressed:function (pressed) {
375+
this._rightMousePressed = pressed;
376+
},
377+
378+
_getRightMousePressed:function () {
379+
return this._rightMousePressed;
380+
},
371381

372382
/**
373383
* Adds a mouse delegate to the dispatcher's list. <br/>
@@ -455,17 +465,32 @@ cc.MouseDispatcher = cc.Class.extend({
455465

456466
switch (index) {
457467
case cc.MOUSE_DOWN:
458-
if (handler.getDelegate().onMouseDown)
459-
handler.getDelegate().onMouseDown(mouseObj);
468+
if (mouseObj.getButton() == cc.MOUSE_RIGHTBUTTON) {
469+
if (handler.getDelegate().onRightMouseDown);
470+
handler.getDelegate().onRightMouseDown(mouseObj);
471+
}
472+
else {
473+
if (handler.getDelegate().onMouseDown)
474+
handler.getDelegate().onMouseDown(mouseObj);
475+
}
460476
break;
461477
case cc.MOUSE_UP:
462-
if (handler.getDelegate().onMouseUp)
463-
handler.getDelegate().onMouseUp(mouseObj);
478+
if (mouseObj.getButton() == cc.MOUSE_RIGHTBUTTON) {
479+
if (handler.getDelegate().onRightMouseUp);
480+
handler.getDelegate().onRightMouseUp(mouseObj);
481+
}
482+
else {
483+
if (handler.getDelegate().onMouseUp)
484+
handler.getDelegate().onMouseUp(mouseObj);
485+
}
464486
break;
465487
case cc.MOUSE_MOVED:
466-
if (this._mousePressed) {
488+
if (this._mousePressed) {
467489
if (handler.getDelegate().onMouseDragged)
468490
handler.getDelegate().onMouseDragged(mouseObj);
491+
} else if (this._rightMousePressed) {
492+
if (handler.getDelegate().onRightMouseDragged)
493+
handler.getDelegate().onRightMouseDragged(mouseObj);
469494
} else {
470495
if (handler.getDelegate().onMouseMoved)
471496
handler.getDelegate().onMouseMoved(mouseObj);
@@ -497,11 +522,21 @@ cc.MouseDispatcher._registerHtmlElementEvent = function (element) {
497522
return;
498523

499524
window.addEventListener('mousedown', function (event) {
500-
cc.Director.getInstance().getMouseDispatcher()._setMousePressed(true);
525+
if (event.button == cc.MOUSE_RIGHTBUTTON) {
526+
cc.Director.getInstance().getMouseDispatcher()._setRightMousePressed(true);
527+
}
528+
else {
529+
cc.Director.getInstance().getMouseDispatcher()._setMousePressed(true);
530+
}
501531
});
502532

503533
window.addEventListener('mouseup', function (event) {
504-
cc.Director.getInstance().getMouseDispatcher()._setMousePressed(false);
534+
if (event.button == cc.MOUSE_RIGHTBUTTON) {
535+
cc.Director.getInstance().getMouseDispatcher()._setRightMousePressed(false);
536+
}
537+
else {
538+
cc.Director.getInstance().getMouseDispatcher()._setMousePressed(false);
539+
}
505540
});
506541

507542
function getMouseByEvent(event) {

0 commit comments

Comments
 (0)