v1.2.0: implemented event/button functionality for right/middle click
This commit is contained in:
@@ -90,13 +90,13 @@ public class InputHandler extends InputAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public synchronized boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
public synchronized boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
||||||
Gdx.input.setOnscreenKeyboardVisible(false); //in-game events never need keyboard, so hide it
|
Gdx.input.setOnscreenKeyboardVisible(false); //in-game events never need keyboard, so hide it
|
||||||
PointerEvent.addPointerEvent(new PointerEvent(screenX, screenY, pointer, PointerEvent.Type.DOWN));
|
PointerEvent.addPointerEvent(new PointerEvent(screenX, screenY, pointer, PointerEvent.Type.DOWN, button));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
public synchronized boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
||||||
PointerEvent.addPointerEvent(new PointerEvent(screenX, screenY, pointer, PointerEvent.Type.UP));
|
PointerEvent.addPointerEvent(new PointerEvent(screenX, screenY, pointer, PointerEvent.Type.UP, button));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ public class InputHandler extends InputAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean scrolled(float amountX, float amountY) {
|
public boolean scrolled(float amountX, float amountY) {
|
||||||
ScrollEvent.addScrollEvent( new ScrollEvent(PointerEvent.lastHoverPos, amountY));
|
ScrollEvent.addScrollEvent( new ScrollEvent(PointerEvent.currentHoverPos(), amountY));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
package com.watabou.input;
|
package com.watabou.input;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Input;
|
||||||
import com.watabou.utils.PointF;
|
import com.watabou.utils.PointF;
|
||||||
import com.watabou.utils.Signal;
|
import com.watabou.utils.Signal;
|
||||||
|
|
||||||
@@ -35,17 +36,29 @@ public class PointerEvent {
|
|||||||
HOVER
|
HOVER
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//buttons
|
||||||
|
public static final int NONE = -1;
|
||||||
|
public static final int LEFT = Input.Buttons.LEFT;
|
||||||
|
public static final int RIGHT = Input.Buttons.RIGHT;
|
||||||
|
public static final int MIDDLE = Input.Buttons.MIDDLE;
|
||||||
|
|
||||||
public PointF start;
|
public PointF start;
|
||||||
public PointF current;
|
public PointF current;
|
||||||
public int id;
|
public int id;
|
||||||
public Type type;
|
public Type type;
|
||||||
|
public int button;
|
||||||
public boolean handled; //for hover events, to ensure hover always ends even with overlapping elements
|
public boolean handled; //for hover events, to ensure hover always ends even with overlapping elements
|
||||||
|
|
||||||
public PointerEvent( int x, int y, int id, Type type){
|
public PointerEvent( int x, int y, int id, Type type){
|
||||||
|
this(x, y, id, type, NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PointerEvent( int x, int y, int id, Type type, int button){
|
||||||
start = current = new PointF(x, y);
|
start = current = new PointF(x, y);
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
handled = false;
|
handled = false;
|
||||||
|
this.button = button;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update( PointerEvent other ){
|
public void update( PointerEvent other ){
|
||||||
@@ -87,7 +100,12 @@ public class PointerEvent {
|
|||||||
// Accumulated pointer events
|
// Accumulated pointer events
|
||||||
private static ArrayList<PointerEvent> pointerEvents = new ArrayList<>();
|
private static ArrayList<PointerEvent> pointerEvents = new ArrayList<>();
|
||||||
private static HashMap<Integer, PointerEvent> activePointers = new HashMap<>();
|
private static HashMap<Integer, PointerEvent> activePointers = new HashMap<>();
|
||||||
static PointF lastHoverPos = new PointF();
|
|
||||||
|
private static PointF lastHoverPos = new PointF();
|
||||||
|
|
||||||
|
public static PointF currentHoverPos(){
|
||||||
|
return lastHoverPos.clone();
|
||||||
|
}
|
||||||
|
|
||||||
public static synchronized void addPointerEvent( PointerEvent event ){
|
public static synchronized void addPointerEvent( PointerEvent event ){
|
||||||
pointerEvents.add( event );
|
pointerEvents.add( event );
|
||||||
|
|||||||
@@ -62,7 +62,19 @@ public class Button extends Component {
|
|||||||
@Override
|
@Override
|
||||||
protected void onClick( PointerEvent event ) {
|
protected void onClick( PointerEvent event ) {
|
||||||
if (!processed) {
|
if (!processed) {
|
||||||
Button.this.onClick();
|
killTooltip();
|
||||||
|
switch (event.button){
|
||||||
|
case PointerEvent.LEFT: default:
|
||||||
|
Button.this.onClick();
|
||||||
|
break;
|
||||||
|
case PointerEvent.RIGHT:
|
||||||
|
Button.this.onRightClick();
|
||||||
|
break;
|
||||||
|
case PointerEvent.MIDDLE:
|
||||||
|
Button.this.onMiddleClick();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +143,13 @@ public class Button extends Component {
|
|||||||
|
|
||||||
protected void onPointerDown() {}
|
protected void onPointerDown() {}
|
||||||
protected void onPointerUp() {}
|
protected void onPointerUp() {}
|
||||||
protected void onClick() {}
|
protected void onClick() {} //left click, default key type
|
||||||
|
protected void onRightClick() {
|
||||||
|
onClick();
|
||||||
|
}
|
||||||
|
protected void onMiddleClick() {
|
||||||
|
onClick();
|
||||||
|
}
|
||||||
protected boolean onLongClick() {
|
protected boolean onLongClick() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user