From dc064177675f1e17110b886e56d6fd0addb8d0af Mon Sep 17 00:00:00 2001 From: Mathias-Boulay Date: Tue, 19 Nov 2024 20:26:36 +0100 Subject: [PATCH] Fix: propagate resolution scale change to all components --- .../pojavlaunch/JavaGUILauncherActivity.java | 4 ++-- .../net/kdt/pojavlaunch/MinecraftGLSurface.java | 17 +++++++---------- .../mouse/AndroidPointerCapture.java | 9 ++++----- .../customcontrols/mouse/HotbarView.java | 3 +-- .../mouse/InGUIEventProcessor.java | 10 ++++------ .../mouse/InGameEventProcessor.java | 5 +++-- .../customcontrols/mouse/Touchpad.java | 4 ++-- .../pojavlaunch/prefs/LauncherPreferences.java | 8 ++++---- .../prefs/QuickSettingSideDialog.java | 8 ++++---- .../LauncherPreferenceControlFragment.java | 2 +- .../net/kdt/pojavlaunch/utils/JREUtils.java | 4 ++-- 11 files changed, 34 insertions(+), 40 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java index 9e7d99c97d..772cdf6079 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java @@ -89,8 +89,8 @@ protected void onCreate(Bundle savedInstanceState) { 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() { diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLSurface.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLSurface.java index d3db34327c..dd9f5f10f2 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLSurface.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MinecraftGLSurface.java @@ -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 MinecraftGLSurface(Context context, AttributeSet attributeSet) { @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 boolean onTouchEvent(MotionEvent e) { // 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 boolean dispatchGenericMotionEvent(MotionEvent event) { 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 void refreshSize(boolean immediate) { 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; diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/AndroidPointerCapture.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/AndroidPointerCapture.java index 695adac110..38f6dd4ca7 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/AndroidPointerCapture.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/AndroidPointerCapture.java @@ -10,6 +10,7 @@ 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 boolean onCapturedPointer(View view, MotionEvent event) { } } 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); } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/HotbarView.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/HotbarView.java index cd2ff5d1ce..39b7690459 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/HotbarView.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/HotbarView.java @@ -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 @@ private boolean isLastEventInGesture(int actionMasked) { } private int mcScale(int input) { - return (int)((mGuiScale * input)/ mScaleFactor); + return (int)((mGuiScale * input) / LauncherPreferences.PREF_SCALE_FACTOR); } @Override diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/InGUIEventProcessor.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/InGUIEventProcessor.java index 16369048a2..21958d6afa 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/InGUIEventProcessor.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/InGUIEventProcessor.java @@ -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 void setAbstractTouchpad(AbstractTouchpad touchpad) { } 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 @@ private void disableMouse() { } 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() { diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/InGameEventProcessor.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/InGameEventProcessor.java index a5838a458f..f4e5fe7639 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/InGameEventProcessor.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/InGameEventProcessor.java @@ -2,6 +2,7 @@ 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 boolean processTouchEvent(MotionEvent motionEvent) { 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(); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/Touchpad.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/Touchpad.java index 1feee772be..8a8c31b341 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/Touchpad.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/Touchpad.java @@ -93,8 +93,8 @@ private void init(){ 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) { diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java index 15d54a4842..5e73275034 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java @@ -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 static void loadPreferences(Context ctx) { 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 static void loadPreferences(Context ctx) { 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); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/QuickSettingSideDialog.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/QuickSettingSideDialog.java index 22e5af838c..942311050a 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/QuickSettingSideDialog.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/QuickSettingSideDialog.java @@ -35,8 +35,8 @@ public abstract class QuickSettingSideDialog extends com.kdt.SideDialogView { - 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); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceControlFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceControlFragment.java index a7400b8922..6f9b5dd095 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceControlFragment.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceControlFragment.java @@ -19,7 +19,7 @@ public void onCreatePreferences(Bundle b, String str) { // 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; diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java index 7ec14dbb4c..da5cfa9c89 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java @@ -355,8 +355,8 @@ public static List getJavaArgs(Context ctx, String runtimeHome, String u //"-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