mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
Android: Enfore correct stick gate in overlay
Currently, the touch controller overlay uses a square gate for sticks. This commit changes that so that it instead uses the stick gate configured in the INI, which ensures that the values sent to the core are appropriately scaled regardless of what is configured in the INI and makes the overlay look nicer if the INI is set to a stick gate that matches the graphics.
This commit is contained in:
@ -269,6 +269,9 @@ public final class NativeLibrary
|
||||
public static native void SetMotionSensorsEnabled(boolean accelerometerEnabled,
|
||||
boolean gyroscopeEnabled);
|
||||
|
||||
// Angle is in radians and should be non-negative
|
||||
public static native double GetInputRadiusAtAngle(int emu_pad_id, int stick, double angle);
|
||||
|
||||
public static native void NewGameIniFile();
|
||||
|
||||
public static native void LoadGameIniFile(String gameId);
|
||||
|
@ -14,6 +14,8 @@ import android.graphics.Rect;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import org.dolphinemu.dolphinemu.NativeLibrary;
|
||||
|
||||
/**
|
||||
* Custom {@link BitmapDrawable} that is capable
|
||||
* of storing it's own ID.
|
||||
@ -214,21 +216,27 @@ public final class InputOverlayDrawableJoystick
|
||||
|
||||
private void SetInnerBounds()
|
||||
{
|
||||
int X = getVirtBounds().centerX() + (int) ((axises[1]) * (getVirtBounds().width() / 2));
|
||||
int Y = getVirtBounds().centerY() + (int) ((axises[0]) * (getVirtBounds().height() / 2));
|
||||
double y = axises[0];
|
||||
double x = axises[1];
|
||||
|
||||
if (X > getVirtBounds().centerX() + (getVirtBounds().width() / 2))
|
||||
X = getVirtBounds().centerX() + (getVirtBounds().width() / 2);
|
||||
if (X < getVirtBounds().centerX() - (getVirtBounds().width() / 2))
|
||||
X = getVirtBounds().centerX() - (getVirtBounds().width() / 2);
|
||||
if (Y > getVirtBounds().centerY() + (getVirtBounds().height() / 2))
|
||||
Y = getVirtBounds().centerY() + (getVirtBounds().height() / 2);
|
||||
if (Y < getVirtBounds().centerY() - (getVirtBounds().height() / 2))
|
||||
Y = getVirtBounds().centerY() - (getVirtBounds().height() / 2);
|
||||
double angle = Math.atan2(y, x) + Math.PI + Math.PI;
|
||||
double radius = Math.hypot(y, x);
|
||||
double maxRadius = NativeLibrary.GetInputRadiusAtAngle(0, mJoystickType, angle);
|
||||
if (radius > maxRadius)
|
||||
{
|
||||
y = maxRadius * Math.sin(angle);
|
||||
x = maxRadius * Math.cos(angle);
|
||||
axises[0] = (float) y;
|
||||
axises[1] = (float) x;
|
||||
}
|
||||
|
||||
int pixelX = getVirtBounds().centerX() + (int) (x * (getVirtBounds().width() / 2));
|
||||
int pixelY = getVirtBounds().centerY() + (int) (y * (getVirtBounds().height() / 2));
|
||||
|
||||
int width = mPressedStateInnerBitmap.getBounds().width() / 2;
|
||||
int height = mPressedStateInnerBitmap.getBounds().height() / 2;
|
||||
mDefaultStateInnerBitmap.setBounds(X - width, Y - height, X + width, Y + height);
|
||||
mDefaultStateInnerBitmap.setBounds(pixelX - width, pixelY - height, pixelX + width,
|
||||
pixelY + height);
|
||||
mPressedStateInnerBitmap.setBounds(mDefaultStateInnerBitmap.getBounds());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user