Remove odd numbers from the screen scaling

This commit is contained in:
SerpentSpirale 2021-08-25 22:34:39 +02:00 committed by ArtDev
parent 5ba7a0cfe9
commit bdb969d073
2 changed files with 22 additions and 13 deletions

View file

@ -2,6 +2,9 @@ package net.kdt.pojavlaunch;
import static net.kdt.pojavlaunch.Architecture.ARCH_X86; import static net.kdt.pojavlaunch.Architecture.ARCH_X86;
import static org.lwjgl.glfw.CallbackBridge.windowHeight;
import static org.lwjgl.glfw.CallbackBridge.windowWidth;
import android.app.*; import android.app.*;
import android.content.*; import android.content.*;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
@ -157,9 +160,9 @@ public class BaseMainActivity extends LoggableActivity {
displayMetrics = Tools.getDisplayMetrics(this); displayMetrics = Tools.getDisplayMetrics(this);
sensitivityFactor = 1.4 * (1080f/ displayMetrics.heightPixels); sensitivityFactor = 1.4 * (1080f/ displayMetrics.heightPixels);
CallbackBridge.windowWidth = (int) ((float)displayMetrics.widthPixels * scaleFactor); windowWidth = Tools.getDisplayFriendlyRes(displayMetrics.widthPixels, scaleFactor);
CallbackBridge.windowHeight = (int) ((float)displayMetrics.heightPixels * scaleFactor); windowHeight = Tools.getDisplayFriendlyRes(displayMetrics.heightPixels, scaleFactor);
System.out.println("WidthHeight: " + CallbackBridge.windowWidth + ":" + CallbackBridge.windowHeight); System.out.println("WidthHeight: " + windowWidth + ":" + windowHeight);
gestureDetector = new GestureDetector(this, new SingleTapConfirm()); gestureDetector = new GestureDetector(this, new SingleTapConfirm());
@ -527,14 +530,14 @@ public class BaseMainActivity extends LoggableActivity {
@Override @Override
public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) { public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) {
scaleFactor = (LauncherPreferences.DEFAULT_PREF.getInt("resolutionRatio",100)/100f); scaleFactor = (LauncherPreferences.DEFAULT_PREF.getInt("resolutionRatio",100)/100f);
texture.setDefaultBufferSize((int)(width*scaleFactor),(int)(height*scaleFactor)); windowWidth = Tools.getDisplayFriendlyRes(width, scaleFactor);
CallbackBridge.windowWidth = (int)(width*scaleFactor); windowHeight = Tools.getDisplayFriendlyRes(height, scaleFactor);
CallbackBridge.windowHeight = (int)(height*scaleFactor); texture.setDefaultBufferSize(windowWidth, windowHeight);
//Load Minecraft options: //Load Minecraft options:
MCOptionUtils.load(); MCOptionUtils.load();
MCOptionUtils.set("overrideWidth", String.valueOf(CallbackBridge.windowWidth)); MCOptionUtils.set("overrideWidth", String.valueOf(windowWidth));
MCOptionUtils.set("overrideHeight", String.valueOf(CallbackBridge.windowHeight)); MCOptionUtils.set("overrideHeight", String.valueOf(windowHeight));
MCOptionUtils.save(); MCOptionUtils.save();
getMcScale(); getMcScale();
// Should we do that? // Should we do that?
@ -561,15 +564,15 @@ public class BaseMainActivity extends LoggableActivity {
@Override @Override
public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) { public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) {
CallbackBridge.windowWidth = (int)(width*scaleFactor); windowWidth = Tools.getDisplayFriendlyRes(width, scaleFactor);
CallbackBridge.windowHeight = (int)(height*scaleFactor); windowHeight = Tools.getDisplayFriendlyRes(height, scaleFactor);
CallbackBridge.sendUpdateWindowSize((int)(width*scaleFactor),(int)(height*scaleFactor)); CallbackBridge.sendUpdateWindowSize(windowWidth, windowHeight);
getMcScale(); getMcScale();
} }
@Override @Override
public void onSurfaceTextureUpdated(SurfaceTexture texture) { public void onSurfaceTextureUpdated(SurfaceTexture texture) {
texture.setDefaultBufferSize(CallbackBridge.windowWidth,CallbackBridge.windowHeight); texture.setDefaultBufferSize(windowWidth, windowHeight);
} }
}); });
} catch (Throwable e) { } catch (Throwable e) {
@ -941,7 +944,7 @@ public class BaseMainActivity extends LoggableActivity {
this.guiScale = (str == null ? 0 :Integer.parseInt(str)); this.guiScale = (str == null ? 0 :Integer.parseInt(str));
int scale = Math.max(Math.min(CallbackBridge.windowWidth / 320, CallbackBridge.windowHeight / 240), 1); int scale = Math.max(Math.min(windowWidth / 320, windowHeight / 240), 1);
if(scale < this.guiScale || guiScale == 0){ if(scale < this.guiScale || guiScale == 0){
this.guiScale = scale; this.guiScale = scale;
} }

View file

@ -852,4 +852,10 @@ public final class Tools {
actManager.getMemoryInfo(memInfo); actManager.getMemoryInfo(memInfo);
return (int) (memInfo.availMem / 1048576L); return (int) (memInfo.availMem / 1048576L);
} }
public static int getDisplayFriendlyRes(int displaySideRes, float scaling){
displaySideRes *= scaling;
if(displaySideRes % 2 != 0) displaySideRes ++;
return displaySideRes;
}
} }