From 94b08d25e10d66190a704df9a5813f0252cd183b Mon Sep 17 00:00:00 2001 From: Bart Date: Thu, 5 Jul 2018 03:24:23 +0200 Subject: [PATCH] Added possibility to center one of the axis only --- .../joystick/android/JoystickView.java | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/virtualjoystick/src/main/java/io/github/controlwear/virtual/joystick/android/JoystickView.java b/virtualjoystick/src/main/java/io/github/controlwear/virtual/joystick/android/JoystickView.java index dd5ac2e..0d82877 100644 --- a/virtualjoystick/src/main/java/io/github/controlwear/virtual/joystick/android/JoystickView.java +++ b/virtualjoystick/src/main/java/io/github/controlwear/virtual/joystick/android/JoystickView.java @@ -212,6 +212,16 @@ public interface OnMultipleLongPressListener { private int mButtonDirection = 0; + public enum AxisToCenter { + BOTH, X, Y + } + + /** + * axis to be centered + */ + private AxisToCenter axisToCenter = AxisToCenter.BOTH; + + /* CONSTRUCTORS */ @@ -540,8 +550,18 @@ private int getStrength() { * Reset the button position to the center. */ public void resetButtonPosition() { - mPosX = mCenterX; - mPosY = mCenterY; + switch (axisToCenter) { + case BOTH: + mPosX = mCenterX; + mPosY = mCenterY; + break; + case X: + mPosX = mCenterX; + break; + case Y: + mPosY = mCenterY; + break; + } } @@ -800,6 +820,21 @@ public void setButtonDirection(int direction) { mButtonDirection = direction; } + /** + * get axis to be centered + * @return + */ + public AxisToCenter getAxisToCenter() { + return axisToCenter; + } + + /** + * set axis to be centered + * @param axisToCenter + */ + public void setAxisToCenter(AxisToCenter axisToCenter) { + this.axisToCenter = axisToCenter; + } /* IMPLEMENTS