Fix: propagate resolution scale change to all components

This commit is contained in:
Mathias-Boulay 2024-11-19 20:26:36 +01:00
parent 85e98a98bf
commit dc06417767
11 changed files with 34 additions and 40 deletions

View File

@ -89,8 +89,8 @@ public class JavaGUILauncherActivity extends BaseActivity implements View.OnTouc
mMousePointerImageView.post(() -> { mMousePointerImageView.post(() -> {
ViewGroup.LayoutParams params = mMousePointerImageView.getLayoutParams(); ViewGroup.LayoutParams params = mMousePointerImageView.getLayoutParams();
params.width = (int) (36 / 100f * LauncherPreferences.PREF_MOUSESCALE); params.width = (int) (36 * LauncherPreferences.PREF_MOUSESCALE);
params.height = (int) (54 / 100f * LauncherPreferences.PREF_MOUSESCALE); params.height = (int) (54 * LauncherPreferences.PREF_MOUSESCALE);
}); });
mTouchPad.setOnTouchListener(new View.OnTouchListener() { mTouchPad.setOnTouchListener(new View.OnTouchListener() {

View File

@ -66,8 +66,6 @@ public class MinecraftGLSurface extends View implements GrabListener {
.remapRightTrigger(true) .remapRightTrigger(true)
.remapDpad(true)); .remapDpad(true));
/* Resolution scaler option, allow downsizing a window */
private float mScaleFactor = LauncherPreferences.PREF_SCALE_FACTOR/100f;
/* Sensitivity, adjusted according to screen size */ /* Sensitivity, adjusted according to screen size */
private final double mSensitivityFactor = (1.4 * (1080f/ Tools.getDisplayMetrics((Activity) getContext()).heightPixels)); 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; View mSurface;
private final InGameEventProcessor mIngameProcessor = new InGameEventProcessor(mSensitivityFactor); 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 TouchEventProcessor mCurrentTouchProcessor = mInGUIProcessor;
private AndroidPointerCapture mPointerCapture; private AndroidPointerCapture mPointerCapture;
private boolean mLastGrabState = false; private boolean mLastGrabState = false;
@ -95,7 +93,7 @@ public class MinecraftGLSurface extends View implements GrabListener {
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
private void setUpPointerCapture(AbstractTouchpad touchpad) { private void setUpPointerCapture(AbstractTouchpad touchpad) {
if(mPointerCapture != null) mPointerCapture.detach(); if(mPointerCapture != null) mPointerCapture.detach();
mPointerCapture = new AndroidPointerCapture(touchpad, this, mScaleFactor); mPointerCapture = new AndroidPointerCapture(touchpad, this);
} }
/** Initialize the view and all its settings /** Initialize the view and all its settings
@ -197,7 +195,7 @@ public class MinecraftGLSurface extends View implements GrabListener {
// Mouse found // Mouse found
if(CallbackBridge.isGrabbing()) return false; 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 return true; //mouse event handled successfully
} }
if (mIngameProcessor == null || mInGUIProcessor == null) return true; if (mIngameProcessor == null || mInGUIProcessor == null) return true;
@ -236,8 +234,8 @@ public class MinecraftGLSurface extends View implements GrabListener {
switch(event.getActionMasked()) { switch(event.getActionMasked()) {
case MotionEvent.ACTION_HOVER_MOVE: case MotionEvent.ACTION_HOVER_MOVE:
CallbackBridge.mouseX = (event.getX(mouseCursorIndex) * mScaleFactor); CallbackBridge.mouseX = (event.getX(mouseCursorIndex) * LauncherPreferences.PREF_SCALE_FACTOR);
CallbackBridge.mouseY = (event.getY(mouseCursorIndex) * mScaleFactor); CallbackBridge.mouseY = (event.getY(mouseCursorIndex) * LauncherPreferences.PREF_SCALE_FACTOR);
CallbackBridge.sendCursorPos(CallbackBridge.mouseX, CallbackBridge.mouseY); CallbackBridge.sendCursorPos(CallbackBridge.mouseX, CallbackBridge.mouseY);
return true; return true;
case MotionEvent.ACTION_SCROLL: case MotionEvent.ACTION_SCROLL:
@ -337,12 +335,11 @@ public class MinecraftGLSurface extends View implements GrabListener {
post(this::refreshSize); post(this::refreshSize);
return; return;
} }
mScaleFactor = LauncherPreferences.PREF_SCALE_FACTOR/100f;
// Use the width and height of the View instead of display dimensions to avoid // Use the width and height of the View instead of display dimensions to avoid
// getting squiched/stretched due to inconsistencies between the layout and // getting squiched/stretched due to inconsistencies between the layout and
// screen dimensions. // screen dimensions.
windowWidth = Tools.getDisplayFriendlyRes(getWidth(), mScaleFactor); windowWidth = Tools.getDisplayFriendlyRes(getWidth(), LauncherPreferences.PREF_SCALE_FACTOR);
windowHeight = Tools.getDisplayFriendlyRes(getHeight(), mScaleFactor); windowHeight = Tools.getDisplayFriendlyRes(getHeight(), LauncherPreferences.PREF_SCALE_FACTOR);
if(mSurface == null){ if(mSurface == null){
Log.w("MGLSurface", "Attempt to refresh size on null surface"); Log.w("MGLSurface", "Attempt to refresh size on null surface");
return; return;

View File

@ -10,6 +10,7 @@ import androidx.annotation.RequiresApi;
import net.kdt.pojavlaunch.MinecraftGLSurface; import net.kdt.pojavlaunch.MinecraftGLSurface;
import net.kdt.pojavlaunch.Tools; import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
import org.lwjgl.glfw.CallbackBridge; import org.lwjgl.glfw.CallbackBridge;
@ -18,7 +19,6 @@ public class AndroidPointerCapture implements ViewTreeObserver.OnWindowFocusChan
private static final float TOUCHPAD_SCROLL_THRESHOLD = 1; private static final float TOUCHPAD_SCROLL_THRESHOLD = 1;
private final AbstractTouchpad mTouchpad; private final AbstractTouchpad mTouchpad;
private final View mHostView; private final View mHostView;
private final float mScaleFactor;
private final float mMousePrescale = Tools.dpToPx(1); private final float mMousePrescale = Tools.dpToPx(1);
private final PointerTracker mPointerTracker = new PointerTracker(); private final PointerTracker mPointerTracker = new PointerTracker();
private final Scroller mScroller = new Scroller(TOUCHPAD_SCROLL_THRESHOLD); private final Scroller mScroller = new Scroller(TOUCHPAD_SCROLL_THRESHOLD);
@ -27,8 +27,7 @@ public class AndroidPointerCapture implements ViewTreeObserver.OnWindowFocusChan
private int mInputDeviceIdentifier; private int mInputDeviceIdentifier;
private boolean mDeviceSupportsRelativeAxis; private boolean mDeviceSupportsRelativeAxis;
public AndroidPointerCapture(AbstractTouchpad touchpad, View hostView, float scaleFactor) { public AndroidPointerCapture(AbstractTouchpad touchpad, View hostView) {
this.mScaleFactor = scaleFactor;
this.mTouchpad = touchpad; this.mTouchpad = touchpad;
this.mHostView = hostView; this.mHostView = hostView;
hostView.setOnCapturedPointerListener(this); hostView.setOnCapturedPointerListener(this);
@ -86,8 +85,8 @@ public class AndroidPointerCapture implements ViewTreeObserver.OnWindowFocusChan
} }
} else { } else {
// Position is updated by many events, hence it is send regardless of the event value // Position is updated by many events, hence it is send regardless of the event value
CallbackBridge.mouseX += (mVector[0] * mScaleFactor); CallbackBridge.mouseX += (mVector[0] * LauncherPreferences.PREF_SCALE_FACTOR);
CallbackBridge.mouseY += (mVector[1] * mScaleFactor); CallbackBridge.mouseY += (mVector[1] * LauncherPreferences.PREF_SCALE_FACTOR);
CallbackBridge.sendCursorPos(CallbackBridge.mouseX, CallbackBridge.mouseY); CallbackBridge.sendCursorPos(CallbackBridge.mouseX, CallbackBridge.mouseY);
} }

View File

@ -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_4, LwjglGlfwKeycode.GLFW_KEY_5, LwjglGlfwKeycode.GLFW_KEY_6,
LwjglGlfwKeycode.GLFW_KEY_7, LwjglGlfwKeycode.GLFW_KEY_8, LwjglGlfwKeycode.GLFW_KEY_9}; LwjglGlfwKeycode.GLFW_KEY_7, LwjglGlfwKeycode.GLFW_KEY_8, LwjglGlfwKeycode.GLFW_KEY_9};
private final DropGesture mDropGesture = new DropGesture(new Handler(Looper.getMainLooper())); private final DropGesture mDropGesture = new DropGesture(new Handler(Looper.getMainLooper()));
private final float mScaleFactor = LauncherPreferences.PREF_SCALE_FACTOR/100f;
private int mWidth; private int mWidth;
private int mLastIndex; private int mLastIndex;
private int mGuiScale; private int mGuiScale;
@ -122,7 +121,7 @@ public class HotbarView extends View implements MCOptionUtils.MCOptionListener,
} }
private int mcScale(int input) { private int mcScale(int input) {
return (int)((mGuiScale * input)/ mScaleFactor); return (int)((mGuiScale * input) / LauncherPreferences.PREF_SCALE_FACTOR);
} }
@Override @Override

View File

@ -19,12 +19,10 @@ public class InGUIEventProcessor implements TouchEventProcessor {
private AbstractTouchpad mTouchpad; private AbstractTouchpad mTouchpad;
private boolean mIsMouseDown = false; private boolean mIsMouseDown = false;
private float mStartX, mStartY; private float mStartX, mStartY;
private final float mScaleFactor;
private final Scroller mScroller = new Scroller(FINGER_SCROLL_THRESHOLD); private final Scroller mScroller = new Scroller(FINGER_SCROLL_THRESHOLD);
public InGUIEventProcessor(float scaleFactor) { public InGUIEventProcessor() {
mSingleTapDetector = new TapDetector(1, TapDetector.DETECTION_METHOD_BOTH); mSingleTapDetector = new TapDetector(1, TapDetector.DETECTION_METHOD_BOTH);
mScaleFactor = scaleFactor;
} }
@Override @Override
@ -91,7 +89,7 @@ public class InGUIEventProcessor implements TouchEventProcessor {
} }
private void sendTouchCoordinates(float x, float y) { 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() { private void enableMouse() {
@ -105,8 +103,8 @@ public class InGUIEventProcessor implements TouchEventProcessor {
} }
private void setGestureStart(MotionEvent event) { private void setGestureStart(MotionEvent event) {
mStartX = event.getX() * mScaleFactor; mStartX = event.getX() * LauncherPreferences.PREF_SCALE_FACTOR;
mStartY = event.getY() * mScaleFactor; mStartY = event.getY() * LauncherPreferences.PREF_SCALE_FACTOR;
} }
private void resetGesture() { private void resetGesture() {

View File

@ -2,6 +2,7 @@ package net.kdt.pojavlaunch.customcontrols.mouse;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
import net.kdt.pojavlaunch.prefs.LauncherPreferences; import net.kdt.pojavlaunch.prefs.LauncherPreferences;
@ -32,8 +33,8 @@ public class InGameEventProcessor implements TouchEventProcessor {
case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_MOVE:
mTracker.trackEvent(motionEvent); mTracker.trackEvent(motionEvent);
float[] motionVector = mTracker.getMotionVector(); float[] motionVector = mTracker.getMotionVector();
CallbackBridge.mouseX += motionVector[0] * mSensitivity; CallbackBridge.mouseX += (float) (motionVector[0] * mSensitivity);
CallbackBridge.mouseY += motionVector[1] * mSensitivity; CallbackBridge.mouseY += (float) (motionVector[1] * mSensitivity);
CallbackBridge.sendCursorPos(CallbackBridge.mouseX, CallbackBridge.mouseY); CallbackBridge.sendCursorPos(CallbackBridge.mouseX, CallbackBridge.mouseY);
if(LauncherPreferences.PREF_DISABLE_GESTURES) break; if(LauncherPreferences.PREF_DISABLE_GESTURES) break;
checkGestures(); checkGestures();

View File

@ -93,8 +93,8 @@ public class Touchpad extends View implements GrabListener, AbstractTouchpad {
assert mMousePointerDrawable != null; assert mMousePointerDrawable != null;
mMousePointerDrawable.setBounds( mMousePointerDrawable.setBounds(
0, 0, 0, 0,
(int) (36 / 100f * LauncherPreferences.PREF_MOUSESCALE), (int) (36 * LauncherPreferences.PREF_MOUSESCALE),
(int) (54 / 100f * LauncherPreferences.PREF_MOUSESCALE) (int) (54 * LauncherPreferences.PREF_MOUSESCALE)
); );
setFocusable(false); setFocusable(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

View File

@ -36,7 +36,7 @@ public class LauncherPreferences {
public static boolean PREF_IGNORE_NOTCH = false; public static boolean PREF_IGNORE_NOTCH = false;
public static int PREF_NOTCH_SIZE = 0; public static int PREF_NOTCH_SIZE = 0;
public static float PREF_BUTTONSIZE = 100f; 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 int PREF_LONGPRESS_TRIGGER = 300;
public static String PREF_DEFAULTCTRL_PATH = Tools.CTRLDEF_FILE; public static String PREF_DEFAULTCTRL_PATH = Tools.CTRLDEF_FILE;
public static String PREF_CUSTOM_JAVA_ARGS; 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_ARC_CAPES = false;
public static boolean PREF_USE_ALTERNATE_SURFACE = true; public static boolean PREF_USE_ALTERNATE_SURFACE = true;
public static boolean PREF_JAVA_SANDBOX = 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 boolean PREF_ENABLE_GYRO = false;
public static float PREF_GYRO_SENSITIVITY = 1f; public static float PREF_GYRO_SENSITIVITY = 1f;
public static int PREF_GYRO_SAMPLE_RATE = 16; public static int PREF_GYRO_SAMPLE_RATE = 16;
@ -82,7 +82,7 @@ public class LauncherPreferences {
PREF_RENDERER = DEFAULT_PREF.getString("renderer", "opengles2"); PREF_RENDERER = DEFAULT_PREF.getString("renderer", "opengles2");
PREF_BUTTONSIZE = DEFAULT_PREF.getInt("buttonscale", 100); 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_MOUSESPEED = ((float)DEFAULT_PREF.getInt("mousespeed",100))/100f;
PREF_HIDE_SIDEBAR = DEFAULT_PREF.getBoolean("hideSidebar", false); PREF_HIDE_SIDEBAR = DEFAULT_PREF.getBoolean("hideSidebar", false);
PREF_IGNORE_NOTCH = DEFAULT_PREF.getBoolean("ignoreNotch", 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_ARC_CAPES = DEFAULT_PREF.getBoolean("arc_capes",false);
PREF_USE_ALTERNATE_SURFACE = DEFAULT_PREF.getBoolean("alternate_surface", false); PREF_USE_ALTERNATE_SURFACE = DEFAULT_PREF.getBoolean("alternate_surface", false);
PREF_JAVA_SANDBOX = DEFAULT_PREF.getBoolean("java_sandbox", true); 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_ENABLE_GYRO = DEFAULT_PREF.getBoolean("enableGyro", false);
PREF_GYRO_SENSITIVITY = ((float)DEFAULT_PREF.getInt("gyroSensitivity", 100))/100f; PREF_GYRO_SENSITIVITY = ((float)DEFAULT_PREF.getInt("gyroSensitivity", 100))/100f;
PREF_GYRO_SAMPLE_RATE = DEFAULT_PREF.getInt("gyroSampleRate", 16); PREF_GYRO_SAMPLE_RATE = DEFAULT_PREF.getInt("gyroSampleRate", 16);

View File

@ -35,8 +35,8 @@ public abstract class QuickSettingSideDialog extends com.kdt.SideDialogView<Cons
private TextView mGyroSensitivityText, mGyroSensitivityDisplayText, mMouseSpeedText, mGestureDelayText, mGestureDelayDisplayText, mResolutionText; private TextView mGyroSensitivityText, mGyroSensitivityDisplayText, mMouseSpeedText, mGestureDelayText, mGestureDelayDisplayText, mResolutionText;
private boolean mOriginalGyroEnabled, mOriginalGyroXEnabled, mOriginalGyroYEnabled, mOriginalGestureDisabled; private boolean mOriginalGyroEnabled, mOriginalGyroXEnabled, mOriginalGyroYEnabled, mOriginalGestureDisabled;
private float mOriginalGyroSensitivity, mOriginalMouseSpeed; private float mOriginalGyroSensitivity, mOriginalMouseSpeed, mOriginalResolution;
private int mOriginalGestureDelay, mOriginalResolution; private int mOriginalGestureDelay;
public QuickSettingSideDialog(Context context, ViewGroup parent) { public QuickSettingSideDialog(Context context, ViewGroup parent) {
super(context, parent, R.layout.dialog_quick_setting); 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.setRange(25, 100);
mResolutionBar.setIncrement(5); mResolutionBar.setIncrement(5);
mResolutionBar.setOnSeekBarChangeListener((SimpleSeekBarListener) (seekBar, progress, fromUser) -> { mResolutionBar.setOnSeekBarChangeListener((SimpleSeekBarListener) (seekBar, progress, fromUser) -> {
PREF_SCALE_FACTOR = progress; PREF_SCALE_FACTOR = progress/100f;
LauncherPreferences.DEFAULT_PREF.edit().putInt("resolutionRatio", progress).apply(); LauncherPreferences.DEFAULT_PREF.edit().putInt("resolutionRatio", progress).apply();
mResolutionText.setText(progress + "%"); mResolutionText.setText(progress + "%");
onResolutionChanged(); onResolutionChanged();
}); });
mResolutionBar.setProgress(mOriginalResolution); mResolutionBar.setProgress((int) (mOriginalResolution * 100));
updateGyroVisibility(mOriginalGyroEnabled); updateGyroVisibility(mOriginalGyroEnabled);

View File

@ -19,7 +19,7 @@ public class LauncherPreferenceControlFragment extends LauncherPreferenceFragmen
// Get values // Get values
int longPressTrigger = LauncherPreferences.PREF_LONGPRESS_TRIGGER; int longPressTrigger = LauncherPreferences.PREF_LONGPRESS_TRIGGER;
int prefButtonSize = (int) LauncherPreferences.PREF_BUTTONSIZE; 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; int gyroSampleRate = LauncherPreferences.PREF_GYRO_SAMPLE_RATE;
float mouseSpeed = LauncherPreferences.PREF_MOUSESPEED; float mouseSpeed = LauncherPreferences.PREF_MOUSESPEED;
float gyroSpeed = LauncherPreferences.PREF_GYRO_SENSITIVITY; float gyroSpeed = LauncherPreferences.PREF_GYRO_SENSITIVITY;

View File

@ -355,8 +355,8 @@ public class JREUtils {
//"-Dorg.lwjgl.util.DebugFunctions=true", //"-Dorg.lwjgl.util.DebugFunctions=true",
//"-Dorg.lwjgl.util.DebugLoader=true", //"-Dorg.lwjgl.util.DebugLoader=true",
// GLFW Stub width height // GLFW Stub width height
"-Dglfwstub.windowWidth=" + Tools.getDisplayFriendlyRes(currentDisplayMetrics.widthPixels, 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/100F), "-Dglfwstub.windowHeight=" + Tools.getDisplayFriendlyRes(currentDisplayMetrics.heightPixels, LauncherPreferences.PREF_SCALE_FACTOR),
"-Dglfwstub.initEgl=false", "-Dglfwstub.initEgl=false",
"-Dext.net.resolvPath=" +resolvFile, "-Dext.net.resolvPath=" +resolvFile,
"-Dlog4j2.formatMsgNoLookups=true", //Log4j RCE mitigation "-Dlog4j2.formatMsgNoLookups=true", //Log4j RCE mitigation