diff options
author | Sven Gothel <[email protected]> | 2011-08-02 14:17:43 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-08-02 14:17:43 +0200 |
commit | ae51b15c98af2ce462cb8ff1a237dd0c51e78e80 (patch) | |
tree | 52d5a819ff4e02a4dabe7661b4add0659e00fd9d /src/newt | |
parent | 332430bd9e2a42b81b509175b43856dc25ae255a (diff) |
Proposal for multi touch
Diffstat (limited to 'src/newt')
-rw-r--r-- | src/newt/classes/com/jogamp/newt/event/InputEvent.java | 57 | ||||
-rw-r--r-- | src/newt/classes/com/jogamp/newt/event/MouseEvent.java | 57 |
2 files changed, 101 insertions, 13 deletions
diff --git a/src/newt/classes/com/jogamp/newt/event/InputEvent.java b/src/newt/classes/com/jogamp/newt/event/InputEvent.java index b0df7b4d1..1d13ee505 100644 --- a/src/newt/classes/com/jogamp/newt/event/InputEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/InputEvent.java @@ -44,6 +44,9 @@ public abstract class InputEvent extends NEWTEvent public static final int BUTTON1_MASK = 1 << 6; public static final int BUTTON2_MASK = 1 << 7; public static final int BUTTON3_MASK = 1 << 8; + public static final int POINTER1_MASK = 1 << 16; + public static final int POINTER2_MASK = 1 << 17; + public static final int POINTER3_MASK = 1 << 18; protected InputEvent(int eventType, Object source, long when, int modifiers) { super(eventType, source, when); @@ -69,18 +72,66 @@ public abstract class InputEvent extends NEWTEvent return (modifiers&SHIFT_MASK)!=0; } - public boolean isButton1Down() { + /** + * @return Array of pressed mouse buttons [{@link MouseEvent#BUTTON1} ..]. + * If none is down, the resulting array is of length 0. + */ + public final int[] getButtonsDown() { + int len = 0; + if(isButton1Down()) { len++; } + if(isButton2Down()) { len++; } + if(isButton3Down()) { len++; } + + int[] res = new int[len]; + int i=0; + if(isButton1Down()) { res[i++] = MouseEvent.BUTTON1; } + if(isButton2Down()) { res[i++] = MouseEvent.BUTTON2; } + if(isButton3Down()) { res[i++] = MouseEvent.BUTTON3; } + return res; + } + + public final boolean isButton1Down() { return (modifiers&BUTTON1_MASK)!=0; } - public boolean isButton2Down() { + public final boolean isButton2Down() { return (modifiers&BUTTON2_MASK)!=0; } - public boolean isButton3Down() { + public final boolean isButton3Down() { return (modifiers&BUTTON3_MASK)!=0; } + /** + * @return Array of involved pointer [{@link MouseEvent#POINTER1} ..]. + * If none is down, the resulting array is of length 0. + */ + public final int[] getPointers() { + int len = 0; + if(isPointer1()) { len++; } + if(isPointer2()) { len++; } + if(isPointer3()) { len++; } + + int[] res = new int[len]; + int i=0; + if(isPointer1()) { res[i++] = MouseEvent.POINTER1; } + if(isPointer2()) { res[i++] = MouseEvent.POINTER2; } + if(isPointer3()) { res[i++] = MouseEvent.POINTER3; } + return res; + } + + public final boolean isPointer1() { + return (modifiers&POINTER1_MASK)!=0; + } + + public final boolean isPointer2() { + return (modifiers&POINTER2_MASK)!=0; + } + + public final boolean isPointer3() { + return (modifiers&POINTER3_MASK)!=0; + } + public String toString() { return "InputEvent[modifiers:"+modifiers+", "+super.toString()+"]"; } diff --git a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java index f3f606115..cb2138b8f 100644 --- a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java @@ -36,14 +36,23 @@ package com.jogamp.newt.event; public class MouseEvent extends InputEvent { + /** Mouse button 1 name. Button names start with 1. */ public static final int BUTTON1 = 1; public static final int BUTTON2 = 2; public static final int BUTTON3 = 3; public static final int BUTTON4 = 4; public static final int BUTTON5 = 5; public static final int BUTTON6 = 6; + /** Maximal number of supported mouse buttons. */ public static final int BUTTON_NUMBER = 6; + /** Pointer device 1 name. Pointer names start with 0. */ + public static final int POINTER1 = 0; + public static final int POINTER2 = 1; + public static final int POINTER3 = 2; + /** Maximal number of supported pointer devices. */ + public static final int POINTER_NUMBER = 3; + public static final int getClickTimeout() { return 300; } @@ -52,25 +61,52 @@ public class MouseEvent extends InputEvent int modifiers, int x, int y, int clickCount, int button, int rotation) { - super(eventType, source, when, modifiers); + super(eventType, source, when, modifiers); + + this.pointerCount=1; + this.x=new int[1]; this.x[0] = x; + this.y=new int[1]; this.y[0] = y; + this.button=new int[1]; this.button[0] = button; + this.clickCount=clickCount; + this.wheelRotation = rotation; + } + + public MouseEvent(int eventType, Object source, long when, + int modifiers, int pointerCount, int[] x, int[] y, int[] button, int[] pressure, + int clickCount, int rotation) + { + super(eventType, source, when, modifiers); + this.pointerCount=pointerCount; this.x=x; this.y=y; - this.clickCount=clickCount; this.button=button; + this.clickCount=clickCount; this.wheelRotation = rotation; } - - public int getButton() { - return button; + + public int getPointerCount() { + return pointerCount; } - public int getClickCount() { - return clickCount; + public int getButton() { + return button[0]; } public int getX() { - return x; + return x[0]; } public int getY() { - return y; + return y[0]; + } + public int getButton(int pointerIdx) { + return button[pointerIdx]; + } + public int getX(int pointerIdx) { + return x[pointerIdx]; + } + public int getY(int pointerIdx) { + return y[pointerIdx]; + } + public int getClickCount() { + return clickCount; } public int getWheelRotation() { return wheelRotation; @@ -97,7 +133,8 @@ public class MouseEvent extends InputEvent } } - private final int x, y, clickCount, button, wheelRotation; + private final int pointerCount, clickCount, wheelRotation; + private final int x[], y[], button[]; public static final int EVENT_MOUSE_CLICKED = 200; public static final int EVENT_MOUSE_ENTERED = 201; |