mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-10 21:25:30 -04:00
Fix: propagate resolution scale change to all components
This commit is contained in:
parent
85e98a98bf
commit
dc06417767
@ -89,8 +89,8 @@ public class JavaGUILauncherActivity extends BaseActivity implements View.OnTouc
|
||||
|
||||
mMousePointerImageView.post(() -> {
|
||||
ViewGroup.LayoutParams params = mMousePointerImageView.getLayoutParams();
|
||||
params.width = (int) (36 / 100f * LauncherPreferences.PREF_MOUSESCALE);
|
||||
params.height = (int) (54 / 100f * LauncherPreferences.PREF_MOUSESCALE);
|
||||
params.width = (int) (36 * LauncherPreferences.PREF_MOUSESCALE);
|
||||
params.height = (int) (54 * LauncherPreferences.PREF_MOUSESCALE);
|
||||
});
|
||||
|
||||
mTouchPad.setOnTouchListener(new View.OnTouchListener() {
|
||||
|
@ -66,8 +66,6 @@ public class MinecraftGLSurface extends View implements GrabListener {
|
||||
.remapRightTrigger(true)
|
||||
.remapDpad(true));
|
||||
|
||||
/* Resolution scaler option, allow downsizing a window */
|
||||
private float mScaleFactor = LauncherPreferences.PREF_SCALE_FACTOR/100f;
|
||||
/* Sensitivity, adjusted according to screen size */
|
||||
private final double mSensitivityFactor = (1.4 * (1080f/ Tools.getDisplayMetrics((Activity) getContext()).heightPixels));
|
||||
|
||||
@ -78,7 +76,7 @@ public class MinecraftGLSurface extends View implements GrabListener {
|
||||
View mSurface;
|
||||
|
||||
private final InGameEventProcessor mIngameProcessor = new InGameEventProcessor(mSensitivityFactor);
|
||||
private final InGUIEventProcessor mInGUIProcessor = new InGUIEventProcessor(mScaleFactor);
|
||||
private final InGUIEventProcessor mInGUIProcessor = new InGUIEventProcessor();
|
||||
private TouchEventProcessor mCurrentTouchProcessor = mInGUIProcessor;
|
||||
private AndroidPointerCapture mPointerCapture;
|
||||
private boolean mLastGrabState = false;
|
||||
@ -95,7 +93,7 @@ public class MinecraftGLSurface extends View implements GrabListener {
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
private void setUpPointerCapture(AbstractTouchpad touchpad) {
|
||||
if(mPointerCapture != null) mPointerCapture.detach();
|
||||
mPointerCapture = new AndroidPointerCapture(touchpad, this, mScaleFactor);
|
||||
mPointerCapture = new AndroidPointerCapture(touchpad, this);
|
||||
}
|
||||
|
||||
/** Initialize the view and all its settings
|
||||
@ -197,7 +195,7 @@ public class MinecraftGLSurface extends View implements GrabListener {
|
||||
|
||||
// Mouse found
|
||||
if(CallbackBridge.isGrabbing()) return false;
|
||||
CallbackBridge.sendCursorPos( e.getX(i) * mScaleFactor, e.getY(i) * mScaleFactor);
|
||||
CallbackBridge.sendCursorPos( e.getX(i) * LauncherPreferences.PREF_SCALE_FACTOR, e.getY(i) * LauncherPreferences.PREF_SCALE_FACTOR);
|
||||
return true; //mouse event handled successfully
|
||||
}
|
||||
if (mIngameProcessor == null || mInGUIProcessor == null) return true;
|
||||
@ -236,8 +234,8 @@ public class MinecraftGLSurface extends View implements GrabListener {
|
||||
|
||||
switch(event.getActionMasked()) {
|
||||
case MotionEvent.ACTION_HOVER_MOVE:
|
||||
CallbackBridge.mouseX = (event.getX(mouseCursorIndex) * mScaleFactor);
|
||||
CallbackBridge.mouseY = (event.getY(mouseCursorIndex) * mScaleFactor);
|
||||
CallbackBridge.mouseX = (event.getX(mouseCursorIndex) * LauncherPreferences.PREF_SCALE_FACTOR);
|
||||
CallbackBridge.mouseY = (event.getY(mouseCursorIndex) * LauncherPreferences.PREF_SCALE_FACTOR);
|
||||
CallbackBridge.sendCursorPos(CallbackBridge.mouseX, CallbackBridge.mouseY);
|
||||
return true;
|
||||
case MotionEvent.ACTION_SCROLL:
|
||||
@ -337,12 +335,11 @@ public class MinecraftGLSurface extends View implements GrabListener {
|
||||
post(this::refreshSize);
|
||||
return;
|
||||
}
|
||||
mScaleFactor = LauncherPreferences.PREF_SCALE_FACTOR/100f;
|
||||
// Use the width and height of the View instead of display dimensions to avoid
|
||||
// getting squiched/stretched due to inconsistencies between the layout and
|
||||
// screen dimensions.
|
||||
windowWidth = Tools.getDisplayFriendlyRes(getWidth(), mScaleFactor);
|
||||
windowHeight = Tools.getDisplayFriendlyRes(getHeight(), mScaleFactor);
|
||||
windowWidth = Tools.getDisplayFriendlyRes(getWidth(), LauncherPreferences.PREF_SCALE_FACTOR);
|
||||
windowHeight = Tools.getDisplayFriendlyRes(getHeight(), LauncherPreferences.PREF_SCALE_FACTOR);
|
||||
if(mSurface == null){
|
||||
Log.w("MGLSurface", "Attempt to refresh size on null surface");
|
||||
return;
|
||||
|
@ -10,6 +10,7 @@ import androidx.annotation.RequiresApi;
|
||||
|
||||
import net.kdt.pojavlaunch.MinecraftGLSurface;
|
||||
import net.kdt.pojavlaunch.Tools;
|
||||
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
|
||||
|
||||
import org.lwjgl.glfw.CallbackBridge;
|
||||
|
||||
@ -18,7 +19,6 @@ public class AndroidPointerCapture implements ViewTreeObserver.OnWindowFocusChan
|
||||
private static final float TOUCHPAD_SCROLL_THRESHOLD = 1;
|
||||
private final AbstractTouchpad mTouchpad;
|
||||
private final View mHostView;
|
||||
private final float mScaleFactor;
|
||||
private final float mMousePrescale = Tools.dpToPx(1);
|
||||
private final PointerTracker mPointerTracker = new PointerTracker();
|
||||
private final Scroller mScroller = new Scroller(TOUCHPAD_SCROLL_THRESHOLD);
|
||||
@ -27,8 +27,7 @@ public class AndroidPointerCapture implements ViewTreeObserver.OnWindowFocusChan
|
||||
private int mInputDeviceIdentifier;
|
||||
private boolean mDeviceSupportsRelativeAxis;
|
||||
|
||||
public AndroidPointerCapture(AbstractTouchpad touchpad, View hostView, float scaleFactor) {
|
||||
this.mScaleFactor = scaleFactor;
|
||||
public AndroidPointerCapture(AbstractTouchpad touchpad, View hostView) {
|
||||
this.mTouchpad = touchpad;
|
||||
this.mHostView = hostView;
|
||||
hostView.setOnCapturedPointerListener(this);
|
||||
@ -86,8 +85,8 @@ public class AndroidPointerCapture implements ViewTreeObserver.OnWindowFocusChan
|
||||
}
|
||||
} else {
|
||||
// Position is updated by many events, hence it is send regardless of the event value
|
||||
CallbackBridge.mouseX += (mVector[0] * mScaleFactor);
|
||||
CallbackBridge.mouseY += (mVector[1] * mScaleFactor);
|
||||
CallbackBridge.mouseX += (mVector[0] * LauncherPreferences.PREF_SCALE_FACTOR);
|
||||
CallbackBridge.mouseY += (mVector[1] * LauncherPreferences.PREF_SCALE_FACTOR);
|
||||
CallbackBridge.sendCursorPos(CallbackBridge.mouseX, CallbackBridge.mouseY);
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,6 @@ public class HotbarView extends View implements MCOptionUtils.MCOptionListener,
|
||||
LwjglGlfwKeycode.GLFW_KEY_4, LwjglGlfwKeycode.GLFW_KEY_5, LwjglGlfwKeycode.GLFW_KEY_6,
|
||||
LwjglGlfwKeycode.GLFW_KEY_7, LwjglGlfwKeycode.GLFW_KEY_8, LwjglGlfwKeycode.GLFW_KEY_9};
|
||||
private final DropGesture mDropGesture = new DropGesture(new Handler(Looper.getMainLooper()));
|
||||
private final float mScaleFactor = LauncherPreferences.PREF_SCALE_FACTOR/100f;
|
||||
private int mWidth;
|
||||
private int mLastIndex;
|
||||
private int mGuiScale;
|
||||
@ -122,7 +121,7 @@ public class HotbarView extends View implements MCOptionUtils.MCOptionListener,
|
||||
}
|
||||
|
||||
private int mcScale(int input) {
|
||||
return (int)((mGuiScale * input)/ mScaleFactor);
|
||||
return (int)((mGuiScale * input) / LauncherPreferences.PREF_SCALE_FACTOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,12 +19,10 @@ public class InGUIEventProcessor implements TouchEventProcessor {
|
||||
private AbstractTouchpad mTouchpad;
|
||||
private boolean mIsMouseDown = false;
|
||||
private float mStartX, mStartY;
|
||||
private final float mScaleFactor;
|
||||
private final Scroller mScroller = new Scroller(FINGER_SCROLL_THRESHOLD);
|
||||
|
||||
public InGUIEventProcessor(float scaleFactor) {
|
||||
public InGUIEventProcessor() {
|
||||
mSingleTapDetector = new TapDetector(1, TapDetector.DETECTION_METHOD_BOTH);
|
||||
mScaleFactor = scaleFactor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -91,7 +89,7 @@ public class InGUIEventProcessor implements TouchEventProcessor {
|
||||
}
|
||||
|
||||
private void sendTouchCoordinates(float x, float y) {
|
||||
CallbackBridge.sendCursorPos( x * mScaleFactor, y * mScaleFactor);
|
||||
CallbackBridge.sendCursorPos( x * LauncherPreferences.PREF_SCALE_FACTOR, y * LauncherPreferences.PREF_SCALE_FACTOR);
|
||||
}
|
||||
|
||||
private void enableMouse() {
|
||||
@ -105,8 +103,8 @@ public class InGUIEventProcessor implements TouchEventProcessor {
|
||||
}
|
||||
|
||||
private void setGestureStart(MotionEvent event) {
|
||||
mStartX = event.getX() * mScaleFactor;
|
||||
mStartY = event.getY() * mScaleFactor;
|
||||
mStartX = event.getX() * LauncherPreferences.PREF_SCALE_FACTOR;
|
||||
mStartY = event.getY() * LauncherPreferences.PREF_SCALE_FACTOR;
|
||||
}
|
||||
|
||||
private void resetGesture() {
|
||||
|
@ -2,6 +2,7 @@ package net.kdt.pojavlaunch.customcontrols.mouse;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
|
||||
@ -32,8 +33,8 @@ public class InGameEventProcessor implements TouchEventProcessor {
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
mTracker.trackEvent(motionEvent);
|
||||
float[] motionVector = mTracker.getMotionVector();
|
||||
CallbackBridge.mouseX += motionVector[0] * mSensitivity;
|
||||
CallbackBridge.mouseY += motionVector[1] * mSensitivity;
|
||||
CallbackBridge.mouseX += (float) (motionVector[0] * mSensitivity);
|
||||
CallbackBridge.mouseY += (float) (motionVector[1] * mSensitivity);
|
||||
CallbackBridge.sendCursorPos(CallbackBridge.mouseX, CallbackBridge.mouseY);
|
||||
if(LauncherPreferences.PREF_DISABLE_GESTURES) break;
|
||||
checkGestures();
|
||||
|
@ -93,8 +93,8 @@ public class Touchpad extends View implements GrabListener, AbstractTouchpad {
|
||||
assert mMousePointerDrawable != null;
|
||||
mMousePointerDrawable.setBounds(
|
||||
0, 0,
|
||||
(int) (36 / 100f * LauncherPreferences.PREF_MOUSESCALE),
|
||||
(int) (54 / 100f * LauncherPreferences.PREF_MOUSESCALE)
|
||||
(int) (36 * LauncherPreferences.PREF_MOUSESCALE),
|
||||
(int) (54 * LauncherPreferences.PREF_MOUSESCALE)
|
||||
);
|
||||
setFocusable(false);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
|
@ -36,7 +36,7 @@ public class LauncherPreferences {
|
||||
public static boolean PREF_IGNORE_NOTCH = false;
|
||||
public static int PREF_NOTCH_SIZE = 0;
|
||||
public static float PREF_BUTTONSIZE = 100f;
|
||||
public static float PREF_MOUSESCALE = 100f;
|
||||
public static float PREF_MOUSESCALE = 1f;
|
||||
public static int PREF_LONGPRESS_TRIGGER = 300;
|
||||
public static String PREF_DEFAULTCTRL_PATH = Tools.CTRLDEF_FILE;
|
||||
public static String PREF_CUSTOM_JAVA_ARGS;
|
||||
@ -53,7 +53,7 @@ public class LauncherPreferences {
|
||||
public static boolean PREF_ARC_CAPES = false;
|
||||
public static boolean PREF_USE_ALTERNATE_SURFACE = true;
|
||||
public static boolean PREF_JAVA_SANDBOX = true;
|
||||
public static int PREF_SCALE_FACTOR = 100;
|
||||
public static float PREF_SCALE_FACTOR = 1f;
|
||||
public static boolean PREF_ENABLE_GYRO = false;
|
||||
public static float PREF_GYRO_SENSITIVITY = 1f;
|
||||
public static int PREF_GYRO_SAMPLE_RATE = 16;
|
||||
@ -82,7 +82,7 @@ public class LauncherPreferences {
|
||||
|
||||
PREF_RENDERER = DEFAULT_PREF.getString("renderer", "opengles2");
|
||||
PREF_BUTTONSIZE = DEFAULT_PREF.getInt("buttonscale", 100);
|
||||
PREF_MOUSESCALE = DEFAULT_PREF.getInt("mousescale", 100);
|
||||
PREF_MOUSESCALE = DEFAULT_PREF.getInt("mousescale", 100)/100f;
|
||||
PREF_MOUSESPEED = ((float)DEFAULT_PREF.getInt("mousespeed",100))/100f;
|
||||
PREF_HIDE_SIDEBAR = DEFAULT_PREF.getBoolean("hideSidebar", false);
|
||||
PREF_IGNORE_NOTCH = DEFAULT_PREF.getBoolean("ignoreNotch", false);
|
||||
@ -103,7 +103,7 @@ public class LauncherPreferences {
|
||||
PREF_ARC_CAPES = DEFAULT_PREF.getBoolean("arc_capes",false);
|
||||
PREF_USE_ALTERNATE_SURFACE = DEFAULT_PREF.getBoolean("alternate_surface", false);
|
||||
PREF_JAVA_SANDBOX = DEFAULT_PREF.getBoolean("java_sandbox", true);
|
||||
PREF_SCALE_FACTOR = DEFAULT_PREF.getInt("resolutionRatio", 100);
|
||||
PREF_SCALE_FACTOR = DEFAULT_PREF.getInt("resolutionRatio", 100)/100f;
|
||||
PREF_ENABLE_GYRO = DEFAULT_PREF.getBoolean("enableGyro", false);
|
||||
PREF_GYRO_SENSITIVITY = ((float)DEFAULT_PREF.getInt("gyroSensitivity", 100))/100f;
|
||||
PREF_GYRO_SAMPLE_RATE = DEFAULT_PREF.getInt("gyroSampleRate", 16);
|
||||
|
@ -35,8 +35,8 @@ public abstract class QuickSettingSideDialog extends com.kdt.SideDialogView<Cons
|
||||
private TextView mGyroSensitivityText, mGyroSensitivityDisplayText, mMouseSpeedText, mGestureDelayText, mGestureDelayDisplayText, mResolutionText;
|
||||
|
||||
private boolean mOriginalGyroEnabled, mOriginalGyroXEnabled, mOriginalGyroYEnabled, mOriginalGestureDisabled;
|
||||
private float mOriginalGyroSensitivity, mOriginalMouseSpeed;
|
||||
private int mOriginalGestureDelay, mOriginalResolution;
|
||||
private float mOriginalGyroSensitivity, mOriginalMouseSpeed, mOriginalResolution;
|
||||
private int mOriginalGestureDelay;
|
||||
|
||||
public QuickSettingSideDialog(Context context, ViewGroup parent) {
|
||||
super(context, parent, R.layout.dialog_quick_setting);
|
||||
@ -149,12 +149,12 @@ public abstract class QuickSettingSideDialog extends com.kdt.SideDialogView<Cons
|
||||
mResolutionBar.setRange(25, 100);
|
||||
mResolutionBar.setIncrement(5);
|
||||
mResolutionBar.setOnSeekBarChangeListener((SimpleSeekBarListener) (seekBar, progress, fromUser) -> {
|
||||
PREF_SCALE_FACTOR = progress;
|
||||
PREF_SCALE_FACTOR = progress/100f;
|
||||
LauncherPreferences.DEFAULT_PREF.edit().putInt("resolutionRatio", progress).apply();
|
||||
mResolutionText.setText(progress + "%");
|
||||
onResolutionChanged();
|
||||
});
|
||||
mResolutionBar.setProgress(mOriginalResolution);
|
||||
mResolutionBar.setProgress((int) (mOriginalResolution * 100));
|
||||
|
||||
|
||||
updateGyroVisibility(mOriginalGyroEnabled);
|
||||
|
@ -19,7 +19,7 @@ public class LauncherPreferenceControlFragment extends LauncherPreferenceFragmen
|
||||
// Get values
|
||||
int longPressTrigger = LauncherPreferences.PREF_LONGPRESS_TRIGGER;
|
||||
int prefButtonSize = (int) LauncherPreferences.PREF_BUTTONSIZE;
|
||||
int mouseScale = (int) LauncherPreferences.PREF_MOUSESCALE;
|
||||
int mouseScale = (int) LauncherPreferences.PREF_MOUSESCALE * 100;
|
||||
int gyroSampleRate = LauncherPreferences.PREF_GYRO_SAMPLE_RATE;
|
||||
float mouseSpeed = LauncherPreferences.PREF_MOUSESPEED;
|
||||
float gyroSpeed = LauncherPreferences.PREF_GYRO_SENSITIVITY;
|
||||
|
@ -355,8 +355,8 @@ public class JREUtils {
|
||||
//"-Dorg.lwjgl.util.DebugFunctions=true",
|
||||
//"-Dorg.lwjgl.util.DebugLoader=true",
|
||||
// GLFW Stub width height
|
||||
"-Dglfwstub.windowWidth=" + Tools.getDisplayFriendlyRes(currentDisplayMetrics.widthPixels, LauncherPreferences.PREF_SCALE_FACTOR/100F),
|
||||
"-Dglfwstub.windowHeight=" + Tools.getDisplayFriendlyRes(currentDisplayMetrics.heightPixels, LauncherPreferences.PREF_SCALE_FACTOR/100F),
|
||||
"-Dglfwstub.windowWidth=" + Tools.getDisplayFriendlyRes(currentDisplayMetrics.widthPixels, LauncherPreferences.PREF_SCALE_FACTOR),
|
||||
"-Dglfwstub.windowHeight=" + Tools.getDisplayFriendlyRes(currentDisplayMetrics.heightPixels, LauncherPreferences.PREF_SCALE_FACTOR),
|
||||
"-Dglfwstub.initEgl=false",
|
||||
"-Dext.net.resolvPath=" +resolvFile,
|
||||
"-Dlog4j2.formatMsgNoLookups=true", //Log4j RCE mitigation
|
||||
|
Loading…
x
Reference in New Issue
Block a user