mirror of
https://github.com/izzy2lost/WeeU.git
synced 2026-07-06 00:19:59 -07:00
Refactored input java code
This commit is contained in:
@@ -59,7 +59,7 @@ namespace JNIUtils
|
||||
public:
|
||||
Scopedjobject() = default;
|
||||
|
||||
Scopedjobject(Scopedjobject&& other)
|
||||
Scopedjobject(Scopedjobject&& other) noexcept
|
||||
{
|
||||
this->m_jobject = other.m_jobject;
|
||||
other.m_jobject = nullptr;
|
||||
@@ -72,7 +72,7 @@ namespace JNIUtils
|
||||
m_jobject = nullptr;
|
||||
}
|
||||
}
|
||||
Scopedjobject& operator=(Scopedjobject&& other)
|
||||
Scopedjobject& operator=(Scopedjobject&& other) noexcept
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
@@ -87,7 +87,7 @@ namespace JNIUtils
|
||||
return m_jobject;
|
||||
}
|
||||
|
||||
Scopedjobject(jobject obj)
|
||||
explicit Scopedjobject(jobject obj)
|
||||
{
|
||||
if (obj)
|
||||
m_jobject = ScopedJNIENV()->NewGlobalRef(obj);
|
||||
@@ -112,13 +112,13 @@ namespace JNIUtils
|
||||
public:
|
||||
Scopedjclass() = default;
|
||||
|
||||
Scopedjclass(Scopedjclass&& other)
|
||||
Scopedjclass(Scopedjclass&& other) noexcept
|
||||
{
|
||||
this->m_jclass = other.m_jclass;
|
||||
other.m_jclass = nullptr;
|
||||
}
|
||||
|
||||
Scopedjclass& operator=(Scopedjclass&& other)
|
||||
Scopedjclass& operator=(Scopedjclass&& other) noexcept
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
@@ -130,7 +130,7 @@ namespace JNIUtils
|
||||
return *this;
|
||||
}
|
||||
|
||||
Scopedjclass(const std::string& className)
|
||||
explicit Scopedjclass(const std::string& className)
|
||||
{
|
||||
ScopedJNIENV scopedEnv;
|
||||
jobject tempObj = scopedEnv->FindClass(className.c_str());
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package info.cemu.Cemu.drawable;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.ColorMatrix;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class DrawableExtensions {
|
||||
private static final ColorMatrix INVERTED_COLOR_MATRIX = new ColorMatrix(
|
||||
new float[]{
|
||||
-1, 0, 0, 0, 255,
|
||||
0, -1, 0, 0, 255,
|
||||
0, 0, -1, 0, 255,
|
||||
0, 0, 0, 1, 0
|
||||
}
|
||||
);
|
||||
|
||||
public static Drawable getInvertedDrawable(Drawable drawable, Resources resources) {
|
||||
var newDrawable = Objects.requireNonNull(drawable.getConstantState())
|
||||
.newDrawable(resources);
|
||||
return applyInvertedColorTransform(newDrawable);
|
||||
}
|
||||
|
||||
public static Drawable applyInvertedColorTransform(Drawable drawable) {
|
||||
drawable = drawable.mutate();
|
||||
drawable.setColorFilter(new ColorMatrixColorFilter(INVERTED_COLOR_MATRIX));
|
||||
return drawable;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@ import androidx.core.content.res.ResourcesCompat;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import info.cemu.Cemu.drawable.DrawableExtensions;
|
||||
|
||||
public abstract class Button extends Input {
|
||||
protected Drawable iconPressed;
|
||||
protected Drawable iconNotPressed;
|
||||
@@ -18,11 +20,11 @@ public abstract class Button extends Input {
|
||||
private final ButtonStateChangeListener buttonStateChangeListener;
|
||||
private final InputOverlaySurfaceView.OverlayButton button;
|
||||
|
||||
public Button(Resources resources, @DrawableRes int pressedButtonId, @DrawableRes int notPressedButtonId, ButtonStateChangeListener buttonStateChangeListener, InputOverlaySurfaceView.OverlayButton button, InputOverlaySettingsProvider.InputOverlaySettings settings) {
|
||||
public Button(Resources resources, @DrawableRes int buttonId, ButtonStateChangeListener buttonStateChangeListener, InputOverlaySurfaceView.OverlayButton button, InputOverlaySettingsProvider.InputOverlaySettings settings) {
|
||||
super(settings);
|
||||
iconPressed = Objects.requireNonNull(ResourcesCompat.getDrawable(resources, pressedButtonId, null));
|
||||
iconNotPressed = Objects.requireNonNull(ResourcesCompat.getDrawable(resources, buttonId, null));
|
||||
iconPressed = DrawableExtensions.getInvertedDrawable(iconNotPressed, resources);
|
||||
iconPressed.setAlpha(settings.getAlpha());
|
||||
iconNotPressed = Objects.requireNonNull(ResourcesCompat.getDrawable(resources, notPressedButtonId, null));
|
||||
iconNotPressed.setAlpha(settings.getAlpha());
|
||||
icon = iconNotPressed;
|
||||
this.buttonStateChangeListener = buttonStateChangeListener;
|
||||
|
||||
@@ -11,6 +11,8 @@ import androidx.core.content.res.ResourcesCompat;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import info.cemu.Cemu.drawable.DrawableExtensions;
|
||||
|
||||
public class DPadInput extends Input {
|
||||
Drawable iconDpadUp;
|
||||
Drawable iconDpadUpPressed;
|
||||
@@ -96,14 +98,14 @@ public class DPadInput extends Input {
|
||||
);
|
||||
}
|
||||
|
||||
public DPadInput(Resources resources, @DrawableRes int backgroundId, @DrawableRes int pressedButtonId, @DrawableRes int notPressedButtonId, ButtonStateChangeListener buttonStateChangeListener, InputOverlaySettingsProvider.InputOverlaySettings settings) {
|
||||
public DPadInput(Resources resources, @DrawableRes int backgroundId, @DrawableRes int buttonId, ButtonStateChangeListener buttonStateChangeListener, InputOverlaySettingsProvider.InputOverlaySettings settings) {
|
||||
super(settings);
|
||||
this.buttonStateChangeListener = buttonStateChangeListener;
|
||||
|
||||
background = Objects.requireNonNull(ResourcesCompat.getDrawable(resources, backgroundId, null));
|
||||
|
||||
Supplier<Drawable> getPressedButtonIcon = () -> Objects.requireNonNull(ResourcesCompat.getDrawable(resources, pressedButtonId, null));
|
||||
Supplier<Drawable> getNotPressedButtonIcon = () -> Objects.requireNonNull(ResourcesCompat.getDrawable(resources, notPressedButtonId, null));
|
||||
Supplier<Drawable> getNotPressedButtonIcon = () -> Objects.requireNonNull(ResourcesCompat.getDrawable(resources, buttonId, null));
|
||||
Supplier<Drawable> getPressedButtonIcon = () -> DrawableExtensions.applyInvertedColorTransform(ResourcesCompat.getDrawable(resources, buttonId, null));
|
||||
|
||||
iconDpadUpPressed = getPressedButtonIcon.get();
|
||||
iconDpadUpNotPressed = getNotPressedButtonIcon.get();
|
||||
|
||||
@@ -36,13 +36,11 @@ public abstract class Input {
|
||||
configure();
|
||||
}
|
||||
|
||||
private static final float MIN_WIDTH_HEIGHT = 100;
|
||||
|
||||
public void resize(int diffX, int diffY, int maxWidth, int maxHeight) {
|
||||
public void resize(int diffX, int diffY, int maxWidth, int maxHeight, int minWidthHeight) {
|
||||
var rect = settings.getRect();
|
||||
int newRight = rect.right + diffX;
|
||||
int newBottom = rect.bottom + diffY;
|
||||
if (newRight - rect.left < MIN_WIDTH_HEIGHT || newBottom - rect.top < MIN_WIDTH_HEIGHT
|
||||
if (newRight - rect.left < minWidthHeight || newBottom - rect.top < minWidthHeight
|
||||
|| newRight > maxWidth || newBottom > maxHeight) {
|
||||
return;
|
||||
}
|
||||
|
||||
+7
-22
@@ -5,6 +5,7 @@ import android.graphics.Canvas;
|
||||
import android.os.VibrationEffect;
|
||||
import android.os.Vibrator;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.View;
|
||||
@@ -45,13 +46,11 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
return;
|
||||
}
|
||||
if (this.inputMode != InputMode.DEFAULT) {
|
||||
for (var input : inputs) {
|
||||
input.saveConfiguration();
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (var input : inputs) {
|
||||
input.reset();
|
||||
input.saveConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,10 +96,13 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
private final Vibrator vibrator;
|
||||
private final VibrationEffect buttonTouchVibrationEffect = VibrationEffect.createPredefined(VibrationEffect.EFFECT_TICK);
|
||||
private final boolean vibrateOnTouch;
|
||||
private static final int INPUTS_MIN_WIDTH_HEIGHT_DP = 40;
|
||||
private final int inputsMinWidthHeight;
|
||||
|
||||
public InputOverlaySurfaceView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
inputsMinWidthHeight = Math.round(INPUTS_MIN_WIDTH_HEIGHT_DP * ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT));
|
||||
vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
setOnTouchListener(this);
|
||||
settingsProvider = new InputOverlaySettingsProvider(context);
|
||||
@@ -311,7 +313,6 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
|
||||
inputs.add(new RoundButton(
|
||||
resources,
|
||||
R.drawable.button_a_pressed,
|
||||
R.drawable.button_a,
|
||||
InputOverlaySurfaceView.this::onButtonStateChange,
|
||||
OverlayButton.A,
|
||||
@@ -319,7 +320,6 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
));
|
||||
inputs.add(new RoundButton(
|
||||
resources,
|
||||
R.drawable.button_b_pressed,
|
||||
R.drawable.button_b,
|
||||
InputOverlaySurfaceView.this::onButtonStateChange,
|
||||
OverlayButton.B,
|
||||
@@ -329,7 +329,6 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
if (nativeControllerType != NativeInput.EMULATED_CONTROLLER_TYPE_WIIMOTE) {
|
||||
inputs.add(new RoundButton(
|
||||
resources,
|
||||
R.drawable.button_x_pressed,
|
||||
R.drawable.button_x,
|
||||
InputOverlaySurfaceView.this::onButtonStateChange,
|
||||
OverlayButton.X,
|
||||
@@ -337,7 +336,6 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
));
|
||||
inputs.add(new RoundButton(
|
||||
resources,
|
||||
R.drawable.button_y_pressed,
|
||||
R.drawable.button_y,
|
||||
InputOverlaySurfaceView.this::onButtonStateChange,
|
||||
OverlayButton.Y,
|
||||
@@ -345,7 +343,6 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
));
|
||||
inputs.add(new RectangleButton(
|
||||
resources,
|
||||
R.drawable.button_zl_pressed,
|
||||
R.drawable.button_zl,
|
||||
InputOverlaySurfaceView.this::onButtonStateChange,
|
||||
OverlayButton.ZL,
|
||||
@@ -353,7 +350,6 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
));
|
||||
inputs.add(new RectangleButton(
|
||||
resources,
|
||||
R.drawable.button_l_pressed,
|
||||
R.drawable.button_l,
|
||||
InputOverlaySurfaceView.this::onButtonStateChange,
|
||||
OverlayButton.L,
|
||||
@@ -361,7 +357,6 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
));
|
||||
inputs.add(new RectangleButton(
|
||||
resources,
|
||||
R.drawable.button_zr_pressed,
|
||||
R.drawable.button_zr,
|
||||
InputOverlaySurfaceView.this::onButtonStateChange,
|
||||
OverlayButton.ZR,
|
||||
@@ -369,7 +364,6 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
));
|
||||
inputs.add(new RectangleButton(
|
||||
resources,
|
||||
R.drawable.button_r_pressed,
|
||||
R.drawable.button_r,
|
||||
InputOverlaySurfaceView.this::onButtonStateChange,
|
||||
OverlayButton.R,
|
||||
@@ -378,7 +372,6 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
inputs.add(new Joystick(
|
||||
resources,
|
||||
R.drawable.stick_background,
|
||||
R.drawable.stick_inner_pressed,
|
||||
R.drawable.stick_inner,
|
||||
InputOverlaySurfaceView.this::onJoystickStateChange,
|
||||
OverlayJoystick.RIGHT,
|
||||
@@ -388,7 +381,6 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
|
||||
inputs.add(new RoundButton(
|
||||
resources,
|
||||
R.drawable.button_minus_pressed,
|
||||
R.drawable.button_minus,
|
||||
InputOverlaySurfaceView.this::onButtonStateChange,
|
||||
OverlayButton.MINUS,
|
||||
@@ -396,7 +388,6 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
));
|
||||
inputs.add(new RoundButton(
|
||||
resources,
|
||||
R.drawable.button_plus_pressed,
|
||||
R.drawable.button_plus,
|
||||
InputOverlaySurfaceView.this::onButtonStateChange,
|
||||
OverlayButton.PLUS,
|
||||
@@ -406,7 +397,6 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
inputs.add(new DPadInput(
|
||||
resources,
|
||||
R.drawable.dpad_background,
|
||||
R.drawable.dpad_button_pressed,
|
||||
R.drawable.dpad_button,
|
||||
InputOverlaySurfaceView.this::onButtonStateChange,
|
||||
getOverlaySettingsForInput(InputOverlaySettingsProvider.Input.DPAD)
|
||||
@@ -414,7 +404,6 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
inputs.add(new Joystick(
|
||||
resources,
|
||||
R.drawable.stick_background,
|
||||
R.drawable.stick_inner_pressed,
|
||||
R.drawable.stick_inner,
|
||||
InputOverlaySurfaceView.this::onJoystickStateChange,
|
||||
OverlayJoystick.LEFT,
|
||||
@@ -424,7 +413,6 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
if (nativeControllerType == NativeInput.EMULATED_CONTROLLER_TYPE_WIIMOTE) {
|
||||
inputs.add(new RoundButton(
|
||||
resources,
|
||||
R.drawable.button_c_pressed,
|
||||
R.drawable.button_c,
|
||||
InputOverlaySurfaceView.this::onButtonStateChange,
|
||||
OverlayButton.C,
|
||||
@@ -432,7 +420,6 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
));
|
||||
inputs.add(new RoundButton(
|
||||
resources,
|
||||
R.drawable.button_z_pressed,
|
||||
R.drawable.button_z,
|
||||
InputOverlaySurfaceView.this::onButtonStateChange,
|
||||
OverlayButton.Z,
|
||||
@@ -440,7 +427,6 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
));
|
||||
inputs.add(new RoundButton(
|
||||
resources,
|
||||
R.drawable.button_home_pressed,
|
||||
R.drawable.button_home,
|
||||
InputOverlaySurfaceView.this::onButtonStateChange,
|
||||
OverlayButton.HOME,
|
||||
@@ -451,7 +437,6 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
&& nativeControllerType != NativeInput.EMULATED_CONTROLLER_TYPE_WIIMOTE) {
|
||||
inputs.add(new RoundButton(
|
||||
resources,
|
||||
R.drawable.button_stick_pressed,
|
||||
R.drawable.button_stick,
|
||||
InputOverlaySurfaceView.this::onButtonStateChange,
|
||||
OverlayButton.L_STICK,
|
||||
@@ -459,7 +444,6 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
));
|
||||
inputs.add(new RoundButton(
|
||||
resources,
|
||||
R.drawable.button_stick_pressed,
|
||||
R.drawable.button_stick,
|
||||
InputOverlaySurfaceView.this::onButtonStateChange,
|
||||
OverlayButton.R_STICK,
|
||||
@@ -550,7 +534,8 @@ public class InputOverlaySurfaceView extends SurfaceView implements View.OnTouch
|
||||
(int) (x2 - x1),
|
||||
(int) (y2 - y1),
|
||||
getWidth(),
|
||||
getHeight());
|
||||
getHeight(),
|
||||
inputsMinWidthHeight);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -10,14 +10,18 @@ import androidx.core.content.res.ResourcesCompat;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import info.cemu.Cemu.drawable.DrawableExtensions;
|
||||
|
||||
public class Joystick extends Input {
|
||||
private final Drawable iconPressed;
|
||||
private final Drawable iconNotPressed;
|
||||
private final Drawable joystickBackground;
|
||||
private Drawable icon;
|
||||
private int currentPointerId = -1;
|
||||
private int centreX = 0;
|
||||
private int centreY = 0;
|
||||
private int centerX = 0;
|
||||
private int centerY = 0;
|
||||
private int originalCenterX = 0;
|
||||
private int originalCenterY = 0;
|
||||
private int radius = 0;
|
||||
private int innerRadius = 0;
|
||||
|
||||
@@ -28,11 +32,11 @@ public class Joystick extends Input {
|
||||
private final StickStateChangeListener stickStateChangeListener;
|
||||
private final InputOverlaySurfaceView.OverlayJoystick joystick;
|
||||
|
||||
public Joystick(Resources resources, @DrawableRes int joystickBackgroundId, @DrawableRes int pressedStickId, @DrawableRes int notPressedStickId, StickStateChangeListener stickStateChangeListener, InputOverlaySurfaceView.OverlayJoystick joystick, InputOverlaySettingsProvider.InputOverlaySettings settings) {
|
||||
public Joystick(Resources resources, @DrawableRes int joystickBackgroundId, @DrawableRes int innerStickId, StickStateChangeListener stickStateChangeListener, InputOverlaySurfaceView.OverlayJoystick joystick, InputOverlaySettingsProvider.InputOverlaySettings settings) {
|
||||
super(settings);
|
||||
joystickBackground = Objects.requireNonNull(ResourcesCompat.getDrawable(resources, joystickBackgroundId, null));
|
||||
iconPressed = Objects.requireNonNull(ResourcesCompat.getDrawable(resources, pressedStickId, null));
|
||||
iconNotPressed = Objects.requireNonNull(ResourcesCompat.getDrawable(resources, notPressedStickId, null));
|
||||
iconNotPressed = Objects.requireNonNull(ResourcesCompat.getDrawable(resources, innerStickId, null));
|
||||
iconPressed = DrawableExtensions.getInvertedDrawable(iconNotPressed, resources);
|
||||
icon = iconNotPressed;
|
||||
this.stickStateChangeListener = stickStateChangeListener;
|
||||
this.joystick = joystick;
|
||||
@@ -46,24 +50,24 @@ public class Joystick extends Input {
|
||||
icon = iconNotPressed;
|
||||
}
|
||||
stickStateChangeListener.onStickStateChange(joystick, x, y);
|
||||
int newCentreX = (int) (centreX + radius * x);
|
||||
int newCentreY = (int) (centreY + radius * y);
|
||||
int newCentreX = (int) (centerX + radius * x);
|
||||
int newCentreY = (int) (centerY + radius * y);
|
||||
iconPressed.setBounds(newCentreX - innerRadius, newCentreY - innerRadius, newCentreX + innerRadius, newCentreY + innerRadius);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
var rect = settings.getRect();
|
||||
this.centreX = rect.centerX();
|
||||
this.centreY = rect.centerY();
|
||||
this.radius = Math.min(rect.width(), rect.height()) / 2;
|
||||
var joystickBounds = settings.getRect();
|
||||
this.originalCenterX = this.centerX = joystickBounds.centerX();
|
||||
this.originalCenterY = this.centerY = joystickBounds.centerY();
|
||||
this.radius = Math.min(joystickBounds.width(), joystickBounds.height()) / 2;
|
||||
this.innerRadius = (int) (radius * 0.65f);
|
||||
joystickBackground.setBounds(centreX - radius, centreY - radius, centreX + radius, centreY + radius);
|
||||
joystickBackground.setBounds(centerX - radius, centerY - radius, centerX + radius, centerY + radius);
|
||||
joystickBackground.setAlpha(settings.getAlpha());
|
||||
iconPressed.setAlpha(settings.getAlpha());
|
||||
iconPressed.setBounds(centreX - innerRadius, centreY - innerRadius, centreX + innerRadius, centreY + innerRadius);
|
||||
iconPressed.setBounds(centerX - innerRadius, centerY - innerRadius, centerX + innerRadius, centerY + innerRadius);
|
||||
iconNotPressed.setAlpha(settings.getAlpha());
|
||||
iconNotPressed.setBounds(centreX - innerRadius, centreY - innerRadius, centreX + innerRadius, centreY + innerRadius);
|
||||
iconNotPressed.setBounds(centerX - innerRadius, centerY - innerRadius, centerX + innerRadius, centerY + innerRadius);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,6 +79,9 @@ public class Joystick extends Input {
|
||||
int x = (int) event.getX(pointerIndex);
|
||||
int y = (int) event.getY(pointerIndex);
|
||||
if (isInside(x, y)) {
|
||||
centerX = x;
|
||||
centerY = y;
|
||||
joystickBackground.setBounds(centerX - radius, centerY - radius, centerX + radius, centerY + radius);
|
||||
currentPointerId = event.getPointerId(pointerIndex);
|
||||
updateState(true, 0.0f, 0.0f);
|
||||
stateUpdated = true;
|
||||
@@ -82,6 +89,9 @@ public class Joystick extends Input {
|
||||
}
|
||||
case MotionEvent.ACTION_UP, MotionEvent.ACTION_POINTER_UP -> {
|
||||
if (currentPointerId == event.getPointerId(event.getActionIndex())) {
|
||||
centerX = originalCenterX;
|
||||
centerY = originalCenterY;
|
||||
joystickBackground.setBounds(centerX - radius, centerY - radius, centerX + radius, centerY + radius);
|
||||
currentPointerId = -1;
|
||||
updateState(false, 0.0f, 0.0f);
|
||||
stateUpdated = true;
|
||||
@@ -95,8 +105,8 @@ public class Joystick extends Input {
|
||||
if (currentPointerId != event.getPointerId(i)) {
|
||||
continue;
|
||||
}
|
||||
float x = (event.getX(i) - centreX) / radius;
|
||||
float y = (event.getY(i) - centreY) / radius;
|
||||
float x = (event.getX(i) - centerX) / radius;
|
||||
float y = (event.getY(i) - centerY) / radius;
|
||||
float norm = (float) Math.sqrt(x * x + y * y);
|
||||
if (norm > 1.0f) {
|
||||
x /= norm;
|
||||
@@ -124,7 +134,7 @@ public class Joystick extends Input {
|
||||
|
||||
@Override
|
||||
public boolean isInside(int x, int y) {
|
||||
return ((x - centreX) * (x - centreX) + (y - centreY) * (y - centreY)) <= radius * radius;
|
||||
return ((x - originalCenterX) * (x - originalCenterX) + (y - originalCenterY) * (y - originalCenterY)) <= radius * radius;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ public class RectangleButton extends Button {
|
||||
int right;
|
||||
int bottom;
|
||||
|
||||
public RectangleButton(Resources resources, @DrawableRes int pressedButtonId, @DrawableRes int notPressedButtonId, ButtonStateChangeListener buttonStateChangeListener, InputOverlaySurfaceView.OverlayButton overlayButton, InputOverlaySettingsProvider.InputOverlaySettings settings) {
|
||||
super(resources, pressedButtonId, notPressedButtonId, buttonStateChangeListener, overlayButton, settings);
|
||||
public RectangleButton(Resources resources, @DrawableRes int buttonId, ButtonStateChangeListener buttonStateChangeListener, InputOverlaySurfaceView.OverlayButton overlayButton, InputOverlaySettingsProvider.InputOverlaySettings settings) {
|
||||
super(resources, buttonId, buttonStateChangeListener, overlayButton, settings);
|
||||
configure();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ public class RoundButton extends Button {
|
||||
int centreY;
|
||||
int radius;
|
||||
|
||||
RoundButton(Resources resources, @DrawableRes int pressedButtonId, @DrawableRes int notPressedButtonId, ButtonStateChangeListener buttonStateChangeListener, InputOverlaySurfaceView.OverlayButton overlayButton, InputOverlaySettingsProvider.InputOverlaySettings settings) {
|
||||
super(resources, pressedButtonId, notPressedButtonId, buttonStateChangeListener, overlayButton, settings);
|
||||
RoundButton(Resources resources, @DrawableRes int buttonId, ButtonStateChangeListener buttonStateChangeListener, InputOverlaySurfaceView.OverlayButton overlayButton, InputOverlaySettingsProvider.InputOverlaySettings settings) {
|
||||
super(resources, buttonId, buttonStateChangeListener, overlayButton, settings);
|
||||
configure();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="95.036dp"
|
||||
android:height="95.036dp"
|
||||
android:viewportWidth="95.036"
|
||||
android:viewportHeight="95.036">
|
||||
<path
|
||||
android:pathData="M47.518,47.518m-47.268,0a47.268,47.268 0,1 1,94.536 0a47.268,47.268 0,1 1,-94.536 0"
|
||||
android:strokeWidth="0.5"
|
||||
android:fillColor="#ffffff"
|
||||
android:strokeColor="#000000"
|
||||
android:fillType="evenOdd"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="m27.626,70.075l5.656,0l14.757,-41.344l-0.585,0l13.911,41.344l6.046,0l-15.862,-45.115l-7.021,0zM36.142,56.684l22.557,0l0,-4.68l-22.557,0z"
|
||||
android:strokeWidth="0.5"/>
|
||||
</vector>
|
||||
@@ -1,16 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="95.036dp"
|
||||
android:height="95.036dp"
|
||||
android:viewportWidth="95.036"
|
||||
android:viewportHeight="95.036">
|
||||
<path
|
||||
android:pathData="M47.518,47.518m-47.268,0a47.268,47.268 0,1 1,94.536 0a47.268,47.268 0,1 1,-94.536 0"
|
||||
android:strokeWidth="0.5"
|
||||
android:fillColor="#ffffff"
|
||||
android:strokeColor="#000000"
|
||||
android:fillType="evenOdd"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="m31.396,70.075l15.732,0c10.401,0 16.512,-4.875 16.512,-13.131 0,-7.606 -5.721,-12.611 -14.366,-12.611l-14.692,0l0,4.485l14.106,0c5.721,0 9.426,3.64 9.426,9.231 0,5.201 -3.12,7.411 -10.336,7.411l-10.986,0l0,-35.884l7.671,0c6.891,0 10.271,2.535 10.271,7.671 0,3.965 -2.21,6.241 -8.191,8.451l7.801,0c3.575,-1.56 5.916,-5.526 5.916,-9.881 0,-6.891 -5.526,-10.856 -15.147,-10.856l-13.716,0z"
|
||||
android:strokeWidth="0.5"/>
|
||||
</vector>
|
||||
@@ -1,16 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="95.036dp"
|
||||
android:height="95.036dp"
|
||||
android:viewportWidth="95.036"
|
||||
android:viewportHeight="95.036">
|
||||
<path
|
||||
android:pathData="M47.518,47.518m-47.268,0a47.268,47.268 0,1 1,94.536 0a47.268,47.268 0,1 1,-94.536 0"
|
||||
android:strokeWidth="0.5"
|
||||
android:fillColor="#ffffff"
|
||||
android:strokeColor="#000000"
|
||||
android:fillType="evenOdd"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="m49.876,70.693c4.355,0 8.906,-0.975 13.196,-2.86l-1.235,-3.965c-3.25,1.3 -7.281,2.08 -10.726,2.08 -10.791,0 -17.942,-7.671 -17.942,-19.177 0,-10.986 6.566,-17.682 17.422,-17.682 3.64,0 7.736,0.78 11.181,2.08l1.56,-4.03c-3.315,-1.755 -7.996,-2.795 -12.416,-2.795 -13.977,0 -23.273,9.491 -23.273,23.662 0,13.586 8.906,22.687 22.232,22.687z"
|
||||
android:strokeWidth="0.5"/>
|
||||
</vector>
|
||||
@@ -1,16 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="95.036dp"
|
||||
android:height="95.036dp"
|
||||
android:viewportWidth="95.036"
|
||||
android:viewportHeight="95.036">
|
||||
<path
|
||||
android:pathData="M47.518,47.518m-47.268,0a47.268,47.268 0,1 1,94.536 0a47.268,47.268 0,1 1,-94.536 0"
|
||||
android:strokeWidth="0.5"
|
||||
android:fillColor="#ffffff"
|
||||
android:strokeColor="#000000"
|
||||
android:fillType="evenOdd"/>
|
||||
<path
|
||||
android:pathData="M41.874,68.172L41.874,54.079h11.275v14.094c0,1.55 1.268,2.819 2.819,2.819h8.456c1.55,0 2.819,-1.268 2.819,-2.819v-19.731h4.792c1.297,0 1.917,-1.607 0.93,-2.452L49.4,24.764c-1.071,-0.958 -2.706,-0.958 -3.777,0l-23.564,21.225c-0.958,0.846 -0.366,2.452 0.93,2.452h4.792v19.731c0,1.55 1.268,2.819 2.819,2.819h8.456c1.55,0 2.819,-1.268 2.819,-2.819z"
|
||||
android:strokeWidth="2.81871"
|
||||
android:fillColor="#000000"/>
|
||||
</vector>
|
||||
@@ -1,15 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="94.033dp"
|
||||
android:height="53.792dp"
|
||||
android:viewportWidth="94.033"
|
||||
android:viewportHeight="53.792">
|
||||
<path
|
||||
android:pathData="M6.828,0.25L87.204,0.25A6.578,6.578 0,0 1,93.783 6.828L93.783,46.964A6.578,6.578 0,0 1,87.204 53.542L6.828,53.542A6.578,6.578 0,0 1,0.25 46.964L0.25,6.828A6.578,6.578 0,0 1,6.828 0.25z"
|
||||
android:strokeWidth="0.5"
|
||||
android:fillColor="#ffffff"
|
||||
android:strokeColor="#000000"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="m38.061,42.67l17.911,0l0,-3.364l-14.138,0l0,-28.185l-3.773,0z"
|
||||
android:strokeWidth="20.98"/>
|
||||
</vector>
|
||||
@@ -1,16 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="95.036dp"
|
||||
android:height="95.036dp"
|
||||
android:viewportWidth="95.036"
|
||||
android:viewportHeight="95.036">
|
||||
<path
|
||||
android:pathData="M47.518,47.518m-47.268,0a47.268,47.268 0,1 1,94.536 0a47.268,47.268 0,1 1,-94.536 0"
|
||||
android:strokeWidth="0.5"
|
||||
android:fillColor="#ffffff"
|
||||
android:strokeColor="#000000"
|
||||
android:fillType="evenOdd"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="m38.092,49.696l18.852,0l0,-4.355l-18.852,0z"
|
||||
android:strokeWidth="0.5"/>
|
||||
</vector>
|
||||
@@ -1,16 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="95.036dp"
|
||||
android:height="95.036dp"
|
||||
android:viewportWidth="95.036"
|
||||
android:viewportHeight="95.036">
|
||||
<path
|
||||
android:pathData="M47.518,47.518m-47.268,0a47.268,47.268 0,1 1,94.536 0a47.268,47.268 0,1 1,-94.536 0"
|
||||
android:strokeWidth="0.5"
|
||||
android:fillColor="#ffffff"
|
||||
android:strokeColor="#000000"
|
||||
android:fillType="evenOdd"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="m47.177,70.238l5.136,0l0,-45.44l-3.12,0l-16.057,8.321 1.95,3.705 13.781,-6.566 -1.69,-1.625z"
|
||||
android:strokeWidth="0.5"/>
|
||||
</vector>
|
||||
@@ -1,16 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="95.036dp"
|
||||
android:height="95.036dp"
|
||||
android:viewportWidth="95.036"
|
||||
android:viewportHeight="95.036">
|
||||
<path
|
||||
android:pathData="M47.518,47.518m-47.268,0a47.268,47.268 0,1 1,94.536 0a47.268,47.268 0,1 1,-94.536 0"
|
||||
android:strokeWidth="0.5"
|
||||
android:fillColor="#ffffff"
|
||||
android:strokeColor="#000000"
|
||||
android:fillType="evenOdd"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="m45.048,62.795l4.941,0l0,-30.553l-4.941,0zM32.242,49.923l30.553,0l0,-4.81l-30.553,0z"
|
||||
android:strokeWidth="0.5"/>
|
||||
</vector>
|
||||
@@ -1,15 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="94.033dp"
|
||||
android:height="53.792dp"
|
||||
android:viewportWidth="94.033"
|
||||
android:viewportHeight="53.792">
|
||||
<path
|
||||
android:pathData="M6.828,0.25L87.204,0.25A6.578,6.578 0,0 1,93.783 6.828L93.783,46.964A6.578,6.578 0,0 1,87.204 53.542L6.828,53.542A6.578,6.578 0,0 1,0.25 46.964L0.25,6.828A6.578,6.578 0,0 1,6.828 0.25z"
|
||||
android:strokeWidth="0.5"
|
||||
android:fillColor="#ffffff"
|
||||
android:strokeColor="#000000"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="m35.606,42.67l3.773,0l0,-28.276l6.228,0c4.5,0 7.137,2.318 7.137,6.228 0,3.864 -2.364,6.092 -6.682,6.092l-8.046,0l0,3.182l7.592,0c6.546,0 11.001,-4.137 11.001,-9.956 0,-5.546 -4.091,-8.819 -10.547,-8.819l-10.456,0zM53.926,42.67l4.5,0l-8.728,-14.911l-4.319,0z"
|
||||
android:strokeWidth="20.98"/>
|
||||
</vector>
|
||||
@@ -1,22 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="95.036dp"
|
||||
android:height="95.036dp"
|
||||
android:viewportWidth="95.036"
|
||||
android:viewportHeight="95.036">
|
||||
<path
|
||||
android:pathData="M47.518,47.518m-47.268,0a47.268,47.268 0,1 1,94.536 0a47.268,47.268 0,1 1,-94.536 0"
|
||||
android:strokeWidth="0.5"
|
||||
android:fillColor="#ffffff"
|
||||
android:strokeColor="#000000"
|
||||
android:fillType="evenOdd"/>
|
||||
<path
|
||||
android:pathData="m41.239,47.518 l-24.749,-24.749 -0.707,0.707 24.042,24.042 -24.042,24.042 0.707,0.707z"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#000000"
|
||||
android:strokeColor="#000000"/>
|
||||
<path
|
||||
android:pathData="m55.211,47.518 l24.749,24.749 0.707,-0.707 -24.042,-24.042 24.042,-24.042 -0.707,-0.707z"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#000000"
|
||||
android:strokeColor="#000000"/>
|
||||
</vector>
|
||||
@@ -1,16 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="95.036dp"
|
||||
android:height="95.036dp"
|
||||
android:viewportWidth="95.036"
|
||||
android:viewportHeight="95.036">
|
||||
<path
|
||||
android:pathData="M47.518,47.518m-47.268,0a47.268,47.268 0,1 1,94.536 0a47.268,47.268 0,1 1,-94.536 0"
|
||||
android:strokeWidth="0.5"
|
||||
android:fillColor="#ffffff"
|
||||
android:strokeColor="#000000"
|
||||
android:fillType="evenOdd"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="m33.574,70.4l28.603,0l0,-4.68l-23.077,0l0.715,1.56c15.407,-14.496 20.607,-22.037 20.607,-29.903 0,-7.931 -5.396,-12.741 -13.716,-12.741 -5.396,0 -10.531,1.95 -13.846,5.136l1.495,3.77c3.445,-2.795 7.736,-4.16 11.246,-4.16 5.786,0 9.361,3.445 9.361,8.841 0,6.566 -5.266,13.391 -21.387,28.603z"
|
||||
android:strokeWidth="0.5"/>
|
||||
</vector>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user