Skip to content

Commit

Permalink
Fix: propagate resolution scale change to all components
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias-Boulay committed Nov 19, 2024
1 parent 85e98a9 commit dc06417
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -149,12 +149,12 @@ private void setupListeners() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ public static List<String> 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
Expand Down

0 comments on commit dc06417

Please sign in to comment.