Browse Source

Improve handling of mouse buttons (#258)

Pascal Peridont 8 years ago
parent
commit
6e59193033
2 changed files with 17 additions and 6 deletions
  1. 7 4
      hxd/Key.hx
  2. 10 2
      hxd/Stage.js.hx

+ 7 - 4
hxd/Key.hx

@@ -92,8 +92,11 @@ class Key {
 
 	public static inline var MOUSE_LEFT = 0;
 	public static inline var MOUSE_RIGHT = 1;
-	public static inline var MOUSE_WHEEL_UP = 2;
-	public static inline var MOUSE_WHEEL_DOWN = 3;
+	public static inline var MOUSE_MIDDLE = 2;
+	public static inline var MOUSE_BACK = 3;
+	public static inline var MOUSE_FORWARD = 4;
+	public static inline var MOUSE_WHEEL_UP = 5;
+	public static inline var MOUSE_WHEEL_DOWN = 6;
 
 	/** a bit that is set for left keys **/
 	public static inline var LOC_LEFT = 256;
@@ -178,9 +181,9 @@ class Key {
 		case EKeyUp:
 			keyPressed[e.keyCode] = -getFrame();
 		case EPush:
-			if( e.button < 2 ) keyPressed[e.button] = getFrame();
+			if( e.button < 5 ) keyPressed[e.button] = getFrame();
 		case ERelease:
-			if( e.button < 2 ) keyPressed[e.button] = -getFrame();
+			if( e.button < 5 ) keyPressed[e.button] = -getFrame();
 		case EWheel:
 			keyPressed[e.wheelDelta > 0 ? MOUSE_WHEEL_DOWN : MOUSE_WHEEL_UP] = getFrame();
 		default:

+ 10 - 2
hxd/Stage.js.hx

@@ -144,13 +144,21 @@ class Stage {
 
 	function onMouseDown(e:js.html.MouseEvent) {
 		var ev = new Event(EPush, mouseX, mouseY);
-		if (e.button == 2) ev.button = 1;
+		ev.button = switch( e.button ) {
+			case 1: 2;
+			case 2: 1;
+			case x: x;
+		};
 		event(ev);
 	}
 
 	function onMouseUp(e:js.html.MouseEvent) {
 		var ev = new Event(ERelease, mouseX, mouseY);
-		if (e.button == 2) ev.button = 1;
+		ev.button = switch( e.button ) {
+			case 1: 2;
+			case 2: 1;
+			case x: x;
+		};
 		event(ev);
 	}