diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java index 648c8fc69..560f717fc 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseMainActivity.java @@ -35,7 +35,7 @@ public class BaseMainActivity extends LoggableActivity { LWJGLGLFWKeycode.GLFW_KEY_7, LWJGLGLFWKeycode.GLFW_KEY_8, LWJGLGLFWKeycode.GLFW_KEY_9}; private boolean rightOverride = false; - private int scaleFactor = 1; + private float scaleFactor = 1; private int fingerStillThreshold = 8; private int initialX; private int initialY; @@ -135,8 +135,8 @@ public class BaseMainActivity extends LoggableActivity { isInputStackCall = mVersionInfo.arguments != null; this.displayMetrics = Tools.getDisplayMetrics(this); - CallbackBridge.windowWidth = displayMetrics.widthPixels / scaleFactor; - CallbackBridge.windowHeight = displayMetrics.heightPixels / scaleFactor; + CallbackBridge.windowWidth = (int) ((float)displayMetrics.widthPixels / scaleFactor); + CallbackBridge.windowHeight = (int) ((float)displayMetrics.heightPixels / scaleFactor); System.out.println("WidthHeight: " + CallbackBridge.windowWidth + ":" + CallbackBridge.windowHeight); MCOptionUtils.load(); @@ -221,7 +221,7 @@ public class BaseMainActivity extends LoggableActivity { AndroidLWJGLKeycode.isBackspaceAfterChar = true; // mVersionInfo.minimumLauncherVersion >= 18; */ - placeMouseAt(CallbackBridge.windowWidth / 2, CallbackBridge.windowHeight / 2); + placeMouseAt(CallbackBridge.physicalWidth / 2, CallbackBridge.physicalHeight / 2); new Thread(new Runnable(){ private boolean isCapturing = false; @@ -236,7 +236,7 @@ public class BaseMainActivity extends LoggableActivity { { if (lastGrab && !CallbackBridge.isGrabbing() && lastEnabled) { touchPad.setVisibility(View.VISIBLE); - placeMouseAt(CallbackBridge.windowWidth / 2, CallbackBridge.windowHeight / 2); + placeMouseAt(displayMetrics.widthPixels / 2, displayMetrics.heightPixels / 2); } if (!CallbackBridge.isGrabbing()) { @@ -293,7 +293,7 @@ public class BaseMainActivity extends LoggableActivity { if (gestureDetector.onTouchEvent(event)) { - CallbackBridge.sendCursorPos((int) mouseX, (int) mouseY); + CallbackBridge.sendCursorPos((int) (mouseX / scaleFactor), (int) (mouseY /scaleFactor)); CallbackBridge.sendMouseKeycode(rightOverride ? LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT : LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT); if (!rightOverride) { CallbackBridge.mouseLeft = true; @@ -309,11 +309,11 @@ public class BaseMainActivity extends LoggableActivity { } break; case MotionEvent.ACTION_MOVE: // 2 - mouseX = Math.max(0, Math.min(CallbackBridge.windowWidth, mouseX + x - prevX)); - mouseY = Math.max(0, Math.min(CallbackBridge.windowHeight, mouseY + y - prevY)); + mouseX = Math.max(0, Math.min(displayMetrics.widthPixels, mouseX + x - prevX)); + mouseY = Math.max(0, Math.min(displayMetrics.heightPixels, mouseY + y - prevY)); placeMouseAt(mouseX, mouseY); - CallbackBridge.sendCursorPos((int) mouseX, (int) mouseY); + CallbackBridge.sendCursorPos((int) (mouseX / scaleFactor), (int) (mouseY /scaleFactor)); /* if (!CallbackBridge.isGrabbing()) { CallbackBridge.sendMouseKeycode(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, 0, isLeftMouseDown); @@ -353,8 +353,8 @@ public class BaseMainActivity extends LoggableActivity { } if (mptrIndex != -1) { //handle mouse events by just sending the coords of the new point in touch event - int x = ((int) e.getX(mptrIndex)) / scaleFactor; - int y = ((int) e.getY(mptrIndex)) / scaleFactor; + int x = (int) (e.getX(mptrIndex) / scaleFactor); + int y = (int) (e.getY(mptrIndex) / scaleFactor); CallbackBridge.mouseX = x; CallbackBridge.mouseY = y; CallbackBridge.sendCursorPos(x, y); @@ -370,8 +370,8 @@ public class BaseMainActivity extends LoggableActivity { y += (int)(e.getY() - e.getHistoricalY(0)); } if(!CallbackBridge.isGrabbing()) { - x = (int) e.getX(); - y = (int) e.getY(); + x = (int) (e.getX() / scaleFactor); + y = (int) (e.getY() / scaleFactor); } int hudKeyHandled = handleGuiBar((int)e.getX(), (int)e.getY()); @@ -654,10 +654,13 @@ public class BaseMainActivity extends LoggableActivity { private boolean isCalled = false; @Override public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) { - CallbackBridge.windowWidth = width; - CallbackBridge.windowHeight = height; + scaleFactor = (LauncherPreferences.DEFAULT_PREF.getInt("resolutionRatio",0)/100f) + 1f; + texture.setDefaultBufferSize((int)(width/scaleFactor),(int)(height/scaleFactor)); + CallbackBridge.windowWidth = (int)(width/scaleFactor); + CallbackBridge.windowHeight = (int)(height/scaleFactor); + //CallbackBridge.sendUpdateWindowSize((int)(width/scaleFactor),(int)(height/scaleFactor)); + calculateMcScale(); - // Should we do that? if (!isCalled) { isCalled = true; @@ -686,9 +689,9 @@ public class BaseMainActivity extends LoggableActivity { @Override public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) { - CallbackBridge.windowWidth = width; - CallbackBridge.windowHeight = height; - CallbackBridge.sendUpdateWindowSize(width, height); + CallbackBridge.windowWidth = (int)(width/scaleFactor); + CallbackBridge.windowHeight = (int)(height/scaleFactor); + CallbackBridge.sendUpdateWindowSize((int)(width/scaleFactor),(int)(height/scaleFactor)); calculateMcScale(); // TODO: Implement this method for GLFW window size callback diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java index 72097087a..000af1a0d 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java @@ -333,12 +333,12 @@ public final class Tools public static DisplayMetrics currentDisplayMetrics; public static void updateWindowSize(Activity ctx) { currentDisplayMetrics = getDisplayMetrics(ctx); - CallbackBridge.windowWidth = currentDisplayMetrics.widthPixels; - CallbackBridge.windowHeight = currentDisplayMetrics.heightPixels; + CallbackBridge.physicalWidth = (int) (currentDisplayMetrics.widthPixels); + CallbackBridge.physicalHeight = (int) (currentDisplayMetrics.heightPixels); - if (CallbackBridge.windowWidth < CallbackBridge.windowHeight) { - CallbackBridge.windowWidth = currentDisplayMetrics.heightPixels; - CallbackBridge.windowHeight = currentDisplayMetrics.widthPixels; + if (CallbackBridge.physicalWidth < CallbackBridge.physicalHeight) { + CallbackBridge.physicalWidth = (int) (currentDisplayMetrics.heightPixels); + CallbackBridge.physicalHeight = (int) (currentDisplayMetrics.widthPixels); } } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlButton.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlButton.java index 6be1f6c19..ad25bcb03 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlButton.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlButton.java @@ -113,7 +113,7 @@ public class ControlButton extends Button implements OnLongClickListener, OnTouc if (!mProperties.isDynamicBtn) { mProperties.x = x; - mProperties.dynamicX = Float.toString(x / CallbackBridge.windowWidth) + " * ${screen_width}"; + mProperties.dynamicX = Float.toString(x / CallbackBridge.physicalWidth) + " * ${screen_width}"; setModified(true); } } @@ -124,7 +124,7 @@ public class ControlButton extends Button implements OnLongClickListener, OnTouc if (!mProperties.isDynamicBtn) { mProperties.y = y; - mProperties.dynamicY = Float.toString(y / CallbackBridge.windowHeight) + " * ${screen_height}"; + mProperties.dynamicY = Float.toString(y / CallbackBridge.physicalHeight) + " * ${screen_height}"; setModified(true); } } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlData.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlData.java index 5816bd39c..0daa19452 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlData.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlData.java @@ -151,12 +151,12 @@ public class ControlData implements Cloneable Map keyValueMap = new ArrayMap<>(); keyValueMap.put("top", "0"); keyValueMap.put("left", "0"); - keyValueMap.put("right", Float.toString(CallbackBridge.windowWidth - width)); - keyValueMap.put("bottom", Float.toString(CallbackBridge.windowHeight - height)); + keyValueMap.put("right", Float.toString(CallbackBridge.physicalWidth - width)); + keyValueMap.put("bottom", Float.toString(CallbackBridge.physicalHeight - height)); keyValueMap.put("width", Float.toString(width)); keyValueMap.put("height", Float.toString(height)); - keyValueMap.put("screen_width", Integer.toString(CallbackBridge.windowWidth)); - keyValueMap.put("screen_height", Integer.toString(CallbackBridge.windowHeight)); + keyValueMap.put("screen_width", Integer.toString(CallbackBridge.physicalWidth)); + keyValueMap.put("screen_height", Integer.toString(CallbackBridge.physicalHeight)); keyValueMap.put("margin", Integer.toString((int) Tools.dpToPx(2))); // Insert value to ${variable} diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlLayout.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlLayout.java index 36ecac251..ea98f0cef 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlLayout.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlLayout.java @@ -50,8 +50,8 @@ public class ControlLayout extends FrameLayout button.width = button.width / controlLayout.scaledAt * LauncherPreferences.PREF_BUTTONSIZE; button.height = button.height / controlLayout.scaledAt * LauncherPreferences.PREF_BUTTONSIZE; if (!button.isDynamicBtn) { - button.dynamicX = Float.toString(button.x / CallbackBridge.windowWidth) + " * ${screen_width}"; - button.dynamicY = Float.toString(button.y / CallbackBridge.windowHeight) + " * ${screen_height}"; + button.dynamicX = Float.toString(button.x / CallbackBridge.physicalWidth) + " * ${screen_width}"; + button.dynamicY = Float.toString(button.y / CallbackBridge.physicalHeight) + " * ${screen_height}"; } button.update(); addControlView(button); diff --git a/app_pojavlauncher/src/main/java/org/lwjgl/glfw/CallbackBridge.java b/app_pojavlauncher/src/main/java/org/lwjgl/glfw/CallbackBridge.java index 2b3e6528b..6379272fd 100644 --- a/app_pojavlauncher/src/main/java/org/lwjgl/glfw/CallbackBridge.java +++ b/app_pojavlauncher/src/main/java/org/lwjgl/glfw/CallbackBridge.java @@ -14,6 +14,7 @@ public class CallbackBridge { public static final int CLIPBOARD_PASTE = 2001; public static volatile int windowWidth, windowHeight; + public static volatile int physicalWidth, physicalHeight; public static int mouseX, mouseY; public static boolean mouseLeft; public static StringBuilder DEBUG_STRING = new StringBuilder(); diff --git a/app_pojavlauncher/src/main/res/values/strings.xml b/app_pojavlauncher/src/main/res/values/strings.xml index 14adaf6af..7c6b8a349 100644 --- a/app_pojavlauncher/src/main/res/values/strings.xml +++ b/app_pojavlauncher/src/main/res/values/strings.xml @@ -224,4 +224,6 @@ Enables automatic RAM adjuster Auto RAM Memory set to %d MB + Allows you to decrease the game resolution. Improves framerate. 0 is the default. + Resolution decrease ratio diff --git a/app_pojavlauncher/src/main/res/xml/pref_main.xml b/app_pojavlauncher/src/main/res/xml/pref_main.xml index 7ade628f5..468d67da4 100644 --- a/app_pojavlauncher/src/main/res/xml/pref_main.xml +++ b/app_pojavlauncher/src/main/res/xml/pref_main.xml @@ -18,7 +18,13 @@ app2:showSeekBarValue="true" app2:selectable="false" app2:icon="@drawable/tap_len" /> - +