From 2fb0464ca8c2273ebc1e1e7ad6a79639dd17bcab Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 27 Apr 2012 01:19:20 +0200 Subject: NEWT Input- Mouse-Event: Consitency of mouse button number; Add button -> button-mask func. --- .../classes/com/jogamp/newt/event/InputEvent.java | 48 +++++++++++++--------- .../classes/com/jogamp/newt/event/MouseEvent.java | 7 ++++ 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/newt/classes/com/jogamp/newt/event/InputEvent.java b/src/newt/classes/com/jogamp/newt/event/InputEvent.java index d8a9235c1..819338ccb 100644 --- a/src/newt/classes/com/jogamp/newt/event/InputEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/InputEvent.java @@ -45,9 +45,27 @@ 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 BUTTON4_MASK = 1 << 9; + public static final int BUTTON5_MASK = 1 << 10; + public static final int BUTTON6_MASK = 1 << 11; public static final int CONFINED_MASK = 1 << 16; public static final int INVISIBLE_MASK = 1 << 17; + /** + * Returns the corresponding button mask for the given button. + *

+ * In case the given button lies outside + * of the valid range [{@link MouseEvent#BUTTON1} .. {@link MouseEvent#BUTTON6}], + * null is returned. + *

+ */ + public static final int getButtonMask(int button) { + if( 0 < button && button <= MouseEvent.BUTTON_NUMBER ) { + return 1 << ( 5 + button ) ; + } + return 0; + } + /** Object when attached via {@link #setAttachment(Object)} marks the event consumed, * ie. stops propagating the event any further to the event listener. */ @@ -84,35 +102,27 @@ public abstract class InputEvent extends NEWTEvent } /** - * @return Array of pressed mouse buttons [{@link MouseEvent#BUTTON1} ..]. + * @return Array of pressed mouse buttons [{@link MouseEvent#BUTTON1} .. {@link MouseEvent#BUTTON6}]. * 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++; } + for(int i=1; i<=MouseEvent.BUTTON_NUMBER; i++) { + if(isButtonDown(i)) { 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; } + int j = 0; + for(int i=1; i<=MouseEvent.BUTTON_NUMBER; i++) { + if(isButtonDown(i)) { res[j++] = ( MouseEvent.BUTTON1 - 1 ) + i; } + } return res; } - public final boolean isButton1Down() { - return (modifiers&BUTTON1_MASK)!=0; - } - - public final boolean isButton2Down() { - return (modifiers&BUTTON2_MASK)!=0; + public final boolean isButtonDown(int button) { + return ( modifiers & getButtonMask(button) ) != 0; } - - public final boolean isButton3Down() { - return (modifiers&BUTTON3_MASK)!=0; - } - + public String toString() { return "InputEvent[modifiers: 0x"+Integer.toHexString(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 d8ebe6607..ceaf7d47a 100644 --- a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java @@ -37,12 +37,19 @@ package com.jogamp.newt.event; @SuppressWarnings("serial") public class MouseEvent extends InputEvent { + /** ID for button 1, value 1 */ public static final int BUTTON1 = 1; + /** ID for button 2, value 2 */ public static final int BUTTON2 = 2; + /** ID for button 3, value 3 */ public static final int BUTTON3 = 3; + /** ID for button 4, value 4 */ public static final int BUTTON4 = 4; + /** ID for button 5, value 5 */ public static final int BUTTON5 = 5; + /** ID for button 6, value 6 */ public static final int BUTTON6 = 6; + /** Number of buttons, value 6 */ public static final int BUTTON_NUMBER = 6; public static final int getClickTimeout() { -- cgit v1.2.3