fixed content scaling

This commit is contained in:
LAX1DUDE 2022-08-09 20:42:39 -07:00
parent df30a98a5d
commit cfa65f6e51
5 changed files with 13621 additions and 13599 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -978,6 +978,9 @@ public class EaglerAdapterImpl2 {
public static final int getCanvasHeight() { public static final int getCanvasHeight() {
return daCanvas.getHeight(); return daCanvas.getHeight();
} }
public static final float getContentScaling() {
return 1.0f;
}
public static final void setDisplaySize(int x, int y) { public static final void setDisplaySize(int x, int y) {
try { try {
Display.setDisplayMode(new DisplayMode(x, y)); Display.setDisplayMode(new DisplayMode(x, y));

View File

@ -1,5 +1,7 @@
package net.minecraft.src; package net.minecraft.src;
import net.lax1dude.eaglercraft.EaglerAdapter;
public class ScaledResolution { public class ScaledResolution {
private int scaledWidth; private int scaledWidth;
private int scaledHeight; private int scaledHeight;
@ -8,8 +10,9 @@ public class ScaledResolution {
private int scaleFactor; private int scaleFactor;
public ScaledResolution(GameSettings par1GameSettings, int par2, int par3) { public ScaledResolution(GameSettings par1GameSettings, int par2, int par3) {
this.scaledWidth = par2; float f = EaglerAdapter.getContentScaling();
this.scaledHeight = par3; this.scaledWidth = (int)(par2 / f);
this.scaledHeight = (int)(par3 / f);
this.scaleFactor = 1; this.scaleFactor = 1;
int var4 = par1GameSettings.guiScale; int var4 = par1GameSettings.guiScale;

View File

@ -39,6 +39,7 @@ import org.teavm.jso.browser.TimerHandler;
import org.teavm.jso.browser.Window; import org.teavm.jso.browser.Window;
import org.teavm.jso.canvas.CanvasRenderingContext2D; import org.teavm.jso.canvas.CanvasRenderingContext2D;
import org.teavm.jso.canvas.ImageData; import org.teavm.jso.canvas.ImageData;
import org.teavm.jso.dom.css.CSSStyleDeclaration;
import org.teavm.jso.dom.events.ErrorEvent; import org.teavm.jso.dom.events.ErrorEvent;
import org.teavm.jso.dom.events.Event; import org.teavm.jso.dom.events.Event;
import org.teavm.jso.dom.events.EventListener; import org.teavm.jso.dom.events.EventListener;
@ -230,14 +231,23 @@ public class EaglerAdapterImpl2 {
win = Window.current(); win = Window.current();
doc = win.getDocument(); doc = win.getDocument();
integratedServerScript = serverWorkerURI; integratedServerScript = serverWorkerURI;
double r = win.getDevicePixelRatio();
int iw = parent.getClientWidth();
int ih = parent.getClientHeight();
int sw = (int)(r * iw);
int sh = (int)(r * ih);
canvas = (HTMLCanvasElement)doc.createElement("canvas"); canvas = (HTMLCanvasElement)doc.createElement("canvas");
canvas.setWidth(parent.getClientWidth()); CSSStyleDeclaration canvasStyle = canvas.getStyle();
canvas.setHeight(parent.getClientHeight()); canvasStyle.setProperty("width", "100%");
canvasStyle.setProperty("height", "100%");
canvasStyle.setProperty("image-rendering", "pixelated");
canvas.setWidth(sw);
canvas.setHeight(sh);
SelfDefence.init(canvas); SelfDefence.init(canvas);
rootElement.appendChild(canvas); rootElement.appendChild(canvas);
renderingCanvas = (HTMLCanvasElement)doc.createElement("canvas"); renderingCanvas = (HTMLCanvasElement)doc.createElement("canvas");
renderingCanvas.setWidth(canvas.getWidth()); renderingCanvas.setWidth(sw);
renderingCanvas.setHeight(canvas.getHeight()); renderingCanvas.setHeight(sh);
frameBuffer = (CanvasRenderingContext2D) canvas.getContext("2d"); frameBuffer = (CanvasRenderingContext2D) canvas.getContext("2d");
webgl = (WebGL2RenderingContext) renderingCanvas.getContext("webgl2", youEagler()); webgl = (WebGL2RenderingContext) renderingCanvas.getContext("webgl2", youEagler());
if(webgl == null) { if(webgl == null) {
@ -279,8 +289,8 @@ public class EaglerAdapterImpl2 {
canvas.addEventListener("mousemove", mousemove = new EventListener<MouseEvent>() { canvas.addEventListener("mousemove", mousemove = new EventListener<MouseEvent>() {
@Override @Override
public void handleEvent(MouseEvent evt) { public void handleEvent(MouseEvent evt) {
mouseX = getOffsetX(evt); mouseX = (int)(getOffsetX(evt) * win.getDevicePixelRatio());
mouseY = canvas.getClientHeight() - getOffsetY(evt); mouseY = (int)((canvas.getClientHeight() - getOffsetY(evt)) * win.getDevicePixelRatio());
mouseDX += evt.getMovementX(); mouseDX += evt.getMovementX();
mouseDY += -evt.getMovementY(); mouseDY += -evt.getMovementY();
if(hasBeenActive()) { if(hasBeenActive()) {
@ -1554,10 +1564,10 @@ public class EaglerAdapterImpl2 {
return mouseY; return mouseY;
} }
public static final int mouseGetEventX() { public static final int mouseGetEventX() {
return currentEvent == null ? -1 : currentEvent.getClientX(); return currentEvent == null ? -1 : (int)(currentEvent.getClientX() * win.getDevicePixelRatio());
} }
public static final int mouseGetEventY() { public static final int mouseGetEventY() {
return currentEvent == null ? -1 : canvas.getClientHeight() - currentEvent.getClientY(); return currentEvent == null ? -1 : (int)((canvas.getClientHeight() - currentEvent.getClientY()) * win.getDevicePixelRatio());
} }
public static final boolean keysNext() { public static final boolean keysNext() {
if(unpressCTRL) { //un-press ctrl after copy/paste permission if(unpressCTRL) { //un-press ctrl after copy/paste permission
@ -1610,20 +1620,23 @@ public class EaglerAdapterImpl2 {
public static final void updateDisplay() { public static final void updateDisplay() {
//commitContext(webgl); //commitContext(webgl);
double r = win.getDevicePixelRatio();
int w = parent.getClientWidth(); int w = parent.getClientWidth();
int h = parent.getClientHeight(); int h = parent.getClientHeight();
if(canvas.getWidth() != w) { int w2 = (int)(w * r);
canvas.setWidth(w); int h2 = (int)(h * r);
if(canvas.getWidth() != w2) {
canvas.setWidth(w2);
} }
if(canvas.getHeight() != h) { if(canvas.getHeight() != h2) {
canvas.setHeight(h); canvas.setHeight(h2);
} }
frameBuffer.drawImage(renderingCanvas, 0, 0, w, h); frameBuffer.drawImage(renderingCanvas, 0, 0, w2, h2);
if(renderingCanvas.getWidth() != w) { if(renderingCanvas.getWidth() != w2) {
renderingCanvas.setWidth(w); renderingCanvas.setWidth(w2);
} }
if(renderingCanvas.getHeight() != h) { if(renderingCanvas.getHeight() != h2) {
renderingCanvas.setHeight(h); renderingCanvas.setHeight(h2);
} }
try { try {
Thread.sleep(1l); Thread.sleep(1l);
@ -1631,6 +1644,9 @@ public class EaglerAdapterImpl2 {
; ;
} }
} }
public static final float getContentScaling() {
return (float)win.getDevicePixelRatio();
}
public static final void setVSyncEnabled(boolean p1) { public static final void setVSyncEnabled(boolean p1) {
} }
@ -1867,7 +1883,7 @@ public class EaglerAdapterImpl2 {
SelfDefence.openWindowIgnore(url, "_blank"); SelfDefence.openWindowIgnore(url, "_blank");
} }
public static final void redirectTo(String url) { public static final void redirectTo(String url) {
Window.current().getLocation().setFullURL(url); win.getLocation().setFullURL(url);
} }
@JSBody(params = { }, script = "window.onbeforeunload = function(){javaMethods.get('net.lax1dude.eaglercraft.adapter.EaglerAdapterImpl2.onWindowUnload()V').invoke();return false;};") @JSBody(params = { }, script = "window.onbeforeunload = function(){javaMethods.get('net.lax1dude.eaglercraft.adapter.EaglerAdapterImpl2.onWindowUnload()V').invoke();return false;};")
@ -2081,7 +2097,7 @@ public class EaglerAdapterImpl2 {
voiceAvailableStat = false; voiceAvailableStat = false;
} }
public static void setVoiceSignalHandler(Consumer<byte[]> signalHandler) { //TODO public static void setVoiceSignalHandler(Consumer<byte[]> signalHandler) {
returnSignalHandler = signalHandler; returnSignalHandler = signalHandler;
} }