fix ui scaling

This commit is contained in:
Sen 2025-06-12 21:30:36 +02:00
parent 836094a00b
commit 17bb2e57ab
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
6 changed files with 53 additions and 43 deletions

View file

@ -278,6 +278,8 @@ public class Client implements IThreadListener {
public static final String VERSION = Version.NAME + " Client " + Util.VERSION;
public static final int LOG_BUFFER = 32768;
public static final int MIN_WIDTH = 800;
public static final int MIN_HEIGHT = 450;
private static final LazyLoader<NioEventLoopGroup> CLIENT_NIO_EVENTLOOP = new LazyLoader<NioEventLoopGroup>()
{
protected NioEventLoopGroup load()
@ -409,9 +411,9 @@ public class Client implements IThreadListener {
@Variable(name = "win_sync", category = CVarCategory.WINDOW, min = -1, max = 16384, callback = SyncFunction.class, display = "Maximale Bildrate")
public int sync = 0;
@Variable(name = "win_width", category = CVarCategory.WINDOW, min = 1, max = 65536, display = "Fensterbreite")
@Variable(name = "win_width", category = CVarCategory.WINDOW, min = MIN_WIDTH, max = 65536, display = "Fensterbreite")
public int xsize = 1280;
@Variable(name = "win_height", category = CVarCategory.WINDOW, min = 1, max = 65536, display = "Fensterhöhe")
@Variable(name = "win_height", category = CVarCategory.WINDOW, min = MIN_HEIGHT, max = 65536, display = "Fensterhöhe")
public int ysize = 800;
@Variable(name = "win_pos_x", category = CVarCategory.WINDOW, min = -65536, max = 65536, display = "Fenster X-Position")
public int saved_xpos = 0x80000000;
@ -426,9 +428,10 @@ public class Client implements IThreadListener {
public int fb_y;
public int mouse_x;
public int mouse_y;
private int scale = 1;
@Variable(name = "gui_scale", category = CVarCategory.GUI, min = 1, max = 5, display = "Skalierung", unit = "x", callback = RedrawFunction.class)
private int scale = 1;
private int scaleVar = 1;
@Variable(name = "phy_sensitivity", category = CVarCategory.INPUT, min = 0.01f, max = 10.0f, display = "Mausempfindlichkeit", precision = 2, unit = "%")
public float sensitivity = 1.0f;
@ -575,7 +578,7 @@ public class Client implements IThreadListener {
Log.NETWORK.error(e, "Konnte nicht zu Server verbinden");
Client.this.schedule(new Runnable() {
public void run() {
Client.this.disconnected(e.toString());
Client.this.disconnected((e instanceof RuntimeException && !(e.getCause() instanceof RuntimeException) ? e.getCause() : e).toString());
}
});
return;
@ -1999,13 +2002,7 @@ public class Client implements IThreadListener {
GL11.glViewport(0, 0, x, y);
fb_raw_x = x;
fb_raw_y = y;
fb_x = Math.max(x / this.scale, 1);
fb_y = Math.max(y / this.scale, 1);
if(this.open != null) {
this.refreshing = true;
this.displayGuiScreen(this.open);
this.refreshing = false;
}
this.rescale();
if(!fullscreen) {
xsize = x;
ysize = y;
@ -2109,8 +2106,12 @@ public class Client implements IThreadListener {
}
private void rescale() {
this.fb_x = Math.max(this.fb_raw_x / this.scale, 1);
this.fb_y = Math.max(this.fb_raw_y / this.scale, 1);
this.scale = this.scaleVar;
while(this.scale > 1 && (this.fb_raw_x / this.scale < MIN_WIDTH || this.fb_raw_y / this.scale < MIN_HEIGHT)) {
this.scale--;
}
this.fb_x = Math.max(this.fb_raw_x / this.scale, MIN_WIDTH);
this.fb_y = Math.max(this.fb_raw_y / this.scale, MIN_HEIGHT);
if(this.open != null) {
this.refreshing = true;
this.displayGuiScreen(this.open);
@ -2269,7 +2270,9 @@ public class Client implements IThreadListener {
this.initConsole();
this.startSound(true);
this.vidMode = Window.getDisplayMode();
Window.initWindow(this.saved_xpos, this.saved_ypos, this.xsize, this.ysize);
if(this.vidMode != null && (this.vidMode.width() < MIN_WIDTH || this.vidMode.height() < MIN_HEIGHT))
this.vidMode = null;
Window.initWindow(this.saved_xpos, this.saved_ypos, this.xsize, this.ysize, MIN_WIDTH, MIN_HEIGHT);
Window.setIcon(genTriwave(64, 64, 0x00000000, 0xffff0000, 0xff00ff00, 0xff0000ff, 0xff7f00ff, 0xff000000), 64, 64);
this.sync(this.sync);
// this.startSound(true);

View file

@ -30,9 +30,9 @@ public class GuiConfirm extends Gui implements ButtonCallback {
public void init(int width, int height) {
this.add(new Label(0, 0, 700, 0, this.messageLine1));
this.add(new MultiLabel(0, 80, 700, 300, this.messageLine2, true));
this.confirmBtn = this.add(new ActButton(100, 450, 245, 0, this, this.confirmButtonText));
this.cancelBtn = this.add(new ActButton(355, 450, 245, 0, this, this.cancelButtonText));
this.add(new MultiLabel(0, 40, 700, 300, this.messageLine2, true));
this.confirmBtn = this.add(new ActButton(100, 400, 245, 0, this, this.confirmButtonText));
this.cancelBtn = this.add(new ActButton(355, 400, 245, 0, this, this.cancelButtonText));
this.shift();
}

View file

@ -104,7 +104,7 @@ public class GuiMenu extends Gui {
}
}, "Client schließen"));
this.shift();
this.add(new Label(4, /* this.gm.fb_y - 2 */ 0, 200, 0, TextColor.VIOLET + Client.VERSION, true));
this.add(new Label(4, 4, 200, 0, TextColor.VIOLET + Client.VERSION, true));
this.splashLabel = this.add(new Label(0, 100, width, 0, ""));
this.pickSplash();
}

View file

@ -1,5 +1,8 @@
package client.gui.options;
import java.util.List;
import client.Client;
import client.gui.Font;
import client.gui.Formatter;
import client.gui.element.Dropdown;
@ -13,6 +16,7 @@ import client.gui.element.ToggleCallback;
import client.window.Button;
import client.window.DisplayMode;
import client.window.Window;
import common.collect.Lists;
import common.color.TextColor;
import common.util.ExtMath;
@ -32,31 +36,32 @@ public class GuiDisplay extends GuiOptions {
}, "Vollbild"));
int maxModes = ExtMath.clampi((height - 120) / Font.YGLYPH, 4, 28);
DisplayMode[] dmodes = Window.getDisplayModes();
if(dmodes != null && dmodes.length > 0) {
int offset = 0;
int pos = 0;
int num = dmodes.length;
if(dmodes.length > maxModes) {
offset = dmodes.length - maxModes;
num = maxModes;
if(dmodes != null) {
List<DisplayMode> modes = Lists.newArrayList();
for(int z = dmodes.length - 1; z >= 0 && modes.size() < maxModes; z--) {
DisplayMode mode = dmodes[z];
if(mode.width() >= Client.MIN_WIDTH && mode.height() >= Client.MIN_HEIGHT)
modes.add(0, mode);
}
DisplayMode[] modes = new DisplayMode[num];
DisplayMode selected = dmodes[num + offset - 1];
for(int z = 0; z < num; z++) {
modes[z] = dmodes[z + offset];
if(modes[z].equals(this.gm.vidMode))
selected = modes[z];
if(modes.isEmpty()) {
dmodes = null;
}
this.add(new Dropdown<DisplayMode>(242, 0, 240, 0, false, modes, modes[modes.length - 1], selected, new DropdownCallback<DisplayMode>() {
else {
DisplayMode selected = modes.get(modes.size() - 1);
for(DisplayMode mode : modes) {
if(mode.equals(this.gm.vidMode))
selected = mode;
}
this.add(new Dropdown<DisplayMode>(242, 0, 240, 0, false, modes.toArray(new DisplayMode[modes.size()]), modes.get(modes.size() - 1), selected, new DropdownCallback<DisplayMode>() {
public void use(Dropdown<DisplayMode> elem, DisplayMode value) {
GuiDisplay.this.gm.vidMode = value;
GuiDisplay.this.gm.full(true);
}
}, (String)null));
}
else {
this.add(new Fill(242, 0, 240, 0, TextColor.RED + "<?>"));
}
if(dmodes == null)
this.add(new Fill(242, 0, 240, 0, TextColor.RED + "<?>"));
this.add(new Slider(0, 20, 240, 0, 0, 0, 360 - 8, 0, (this.gm.sync < 0) ? (360 - 8) : (this.gm.sync != 0 ? ((this.gm.sync < 10) ? 1 : (this.gm.sync - 9)) : 0), new SliderCallback() {
public void use(Slider elem, int value) {

View file

@ -92,7 +92,7 @@ public class ClientLoginHandler implements IClientLoginHandler {
return;
}
else if(!this.server.getServerKey().equals(pubkey)) {
this.connection.closeChannel("Die Identität des Servers hat sich geändert\n\nDer Server hat einen anderen öffentlichen Schlüssel als vorher bekannt war,\ndies kann bedeuten dass der Inhaber jetzt einen anderen Schlüssel verwendet\noder sich ein anderer Server als dieser ausgibt (\"Man-in-the-middle-attack\").\n\nDie Pubkey-ID des Servers lautet: RSA-4096 " + EncryptUtil.getXorSha512Hash(pubkey.getEncoded()) + "\n\nDer öffentliche Schlüssel des Servers lautet:\n" + Util.breakString(Base64.getEncoder().encodeToString(pubkey.getEncoded()), 96) + "\n\nDie vertrauenswürdige Pubkey-ID lautet: RSA-4096 " + EncryptUtil.getXorSha512Hash(this.server.getServerKey().getEncoded()) + "\n\nDer vertrauenswürdige Schlüssel lautet:\n" + Util.breakString(Base64.getEncoder().encodeToString(this.server.getServerKey().getEncoded()), 96) +
this.connection.closeChannel("Die Identität des Servers hat sich geändert\n\nDer Server hat einen anderen öffentlichen Schlüssel als vorher bekannt war,\ndies kann bedeuten dass der Inhaber jetzt einen anderen Schlüssel verwendet\noder sich ein anderer Server als dieser ausgibt (\"Man-in-the-middle-attack\").\n\nDie Pubkey-ID des Servers lautet: RSA-4096 " + EncryptUtil.getXorSha512Hash(pubkey.getEncoded()) + "\n\nDer öffentliche Schlüssel des Servers lautet:\n" + Util.breakString(Base64.getEncoder().encodeToString(pubkey.getEncoded()), 64) + "\n\nDie vertrauenswürdige Pubkey-ID lautet: RSA-4096 " + EncryptUtil.getXorSha512Hash(this.server.getServerKey().getEncoded()) +
"\n\nFalls der Server trotzdem vertrauenswürdig wirkt, kann die Server-Identifizierung\nin den Einstellungen von '" + this.server.getName() + "' zurückgesetzt werden.");
return;
}
@ -166,7 +166,7 @@ public class ClientLoginHandler implements IClientLoginHandler {
boolean passwordAuth = packet.canUsePassword();
boolean pubkeyAuth = packet.canUsePubkey() && this.state == LoginState.ENCRYPTED;
if(auth && (!passwordAuth || this.server.getPassword().isEmpty()) && (!pubkeyAuth || this.server.getKeypair() == null)) {
this.connection.closeChannel("Der Server unterstützt keine der vorhandenen Authentifizierungsmethoden\n\nUnterstützt vom Server: " +
this.connection.closeChannel("Der Server unterstützt keine der vorhandenen\nAuthentifizierungsmethoden\n\nUnterstützt vom Server: " +
(!passwordAuth && !pubkeyAuth ? "Keine" : ((passwordAuth ? "Passwort" : "") + (passwordAuth && pubkeyAuth ? " und " : "") + (pubkeyAuth ? "Pubkey" : ""))) +
"\n\nVorhanden in Konfiguration für '" + this.server.getName() + "': " + (this.server.getPassword().isEmpty() && this.server.getKeypair() == null ? "Keine" :
((this.server.getPassword().isEmpty() ? "Passwort" : "") +

View file

@ -43,6 +43,7 @@ import static org.lwjgl.glfw.GLFW.glfwSetWindowPos;
import static org.lwjgl.glfw.GLFW.glfwSetWindowPosCallback;
import static org.lwjgl.glfw.GLFW.glfwSetWindowRefreshCallback;
import static org.lwjgl.glfw.GLFW.glfwSetWindowSize;
import static org.lwjgl.glfw.GLFW.glfwSetWindowSizeLimits;
import static org.lwjgl.glfw.GLFW.glfwSetWindowTitle;
import static org.lwjgl.glfw.GLFW.glfwShowWindow;
import static org.lwjgl.glfw.GLFW.glfwSwapBuffers;
@ -212,7 +213,7 @@ public abstract class Window {
window = NULL;
}
}
public static void initWindow(int sx, int sy, int wx, int wy) {
public static void initWindow(int sx, int sy, int wx, int wy, int mx, int my) {
if(window == NULL)
return;
long monitor = glfwGetPrimaryMonitor();
@ -221,8 +222,8 @@ public abstract class Window {
int[] y = new int[1];
if(monitor != NULL)
glfwGetMonitorPos(monitor, x, y);
int xsize = (mode != null && wx > mode.width()) ? mode.width() : wx;
int ysize = (mode != null && wy > mode.height()) ? mode.height() : wy;
int xsize = (mode != null && mode.width() >= mx && wx > mode.width()) ? mode.width() : wx;
int ysize = (mode != null && mode.height() >= my && wy > mode.height()) ? mode.height() : wy;
int xpos = x[0] + (mode != null ? mode.width() / 2 - xsize / 2 : 0);
int ypos = y[0] + (mode != null ? mode.height() / 2 - ysize / 2 : 0);
xsize = xsize < 1 ? 1 : xsize;
@ -236,6 +237,7 @@ public abstract class Window {
ysize = wy;
}
glfwSetWindowSize(window, xsize, ysize);
glfwSetWindowSizeLimits(window, mx, my, GLFW_DONT_CARE, GLFW_DONT_CARE);
glfwSetWindowPos(window, xpos, ypos);
// wcf_windowed(win, xpos, ypos, xsize, ysize);
// wcf_fullscreen does not move while hidden ...