add float scaling

This commit is contained in:
Sen 2025-05-29 16:40:33 +02:00
parent f3117767fd
commit be0ab15153
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
2 changed files with 23 additions and 13 deletions

View file

@ -238,8 +238,8 @@ public class Client implements IThreadListener {
} }
} }
public static class RedrawFunction implements IntFunction { public static class RedrawFunction implements FloatFunction {
public void apply(IntVar cv, int value) { public void apply(FloatVar cv, float value) {
Client.CLIENT.rescale(); Client.CLIENT.rescale();
} }
} }
@ -414,8 +414,8 @@ public class Client implements IThreadListener {
public int mouse_x; public int mouse_x;
public int mouse_y; public int mouse_y;
@Variable(name = "gui_scale", category = CVarCategory.GUI, min = 1, max = 5, display = "Skalierung der Benutzeroberfläche", unit = "x", callback = RedrawFunction.class) @Variable(name = "gui_scale", category = CVarCategory.GUI, min = 1.0f, max = 5.0f, display = "Skalierung der Benutzeroberfläche", precision = 1, unit = "%", callback = RedrawFunction.class)
private int scale = 1; private float scale = 1.0f;
@Variable(name = "phy_sensitivity", category = CVarCategory.INPUT, min = 0.01f, max = 10.0f, display = "Mausempfindlichkeit", precision = 2, unit = "%") @Variable(name = "phy_sensitivity", category = CVarCategory.INPUT, min = 0.01f, max = 10.0f, display = "Mausempfindlichkeit", precision = 2, unit = "%")
public float sensitivity = 1.0f; public float sensitivity = 1.0f;
@ -1963,8 +1963,8 @@ public class Client implements IThreadListener {
GL11.glViewport(0, 0, x, y); GL11.glViewport(0, 0, x, y);
fb_raw_x = x; fb_raw_x = x;
fb_raw_y = y; fb_raw_y = y;
fb_x = Math.max(x / this.scale, 1); fb_x = Math.max((int)((float)x / this.scale), 1);
fb_y = Math.max(y / this.scale, 1); fb_y = Math.max((int)((float)y / this.scale), 1);
if(this.open != null) { if(this.open != null) {
this.refreshing = true; this.refreshing = true;
this.displayGuiScreen(this.open); this.displayGuiScreen(this.open);
@ -1988,8 +1988,8 @@ public class Client implements IThreadListener {
this.moveCamera((float)(x - mouse_raw_x) * sensitivity, (float)(mouse_raw_y - y) * sensitivity); this.moveCamera((float)(x - mouse_raw_x) * sensitivity, (float)(mouse_raw_y - y) * sensitivity);
mouse_raw_x = x; mouse_raw_x = x;
mouse_raw_y = y; mouse_raw_y = y;
mouse_x = x / this.scale; mouse_x = (int)((float)x / this.scale);
mouse_y = y / this.scale; mouse_y = (int)((float)y / this.scale);
mouseFirst = false; mouseFirst = false;
if(open != null && Bind.isInputEnabled() && Button.isMouseDown() /* && !(win->mouse & 0xfc) */ && !ctrl()) { if(open != null && Bind.isInputEnabled() && Button.isMouseDown() /* && !(win->mouse & 0xfc) */ && !ctrl()) {
// if(mouse_clickx < 0 || mouse_clicky < 0) { // if(mouse_clickx < 0 || mouse_clicky < 0) {
@ -2073,8 +2073,9 @@ public class Client implements IThreadListener {
} }
private void rescale() { private void rescale() {
this.fb_x = Math.max(this.fb_raw_x / this.scale, 1); Font.setScale(this.scale);
this.fb_y = Math.max(this.fb_raw_y / this.scale, 1); this.fb_x = Math.max((int)((float)this.fb_raw_x / this.scale), 1);
this.fb_y = Math.max((int)((float)this.fb_raw_y / this.scale), 1);
if(this.open != null) { if(this.open != null) {
this.refreshing = true; this.refreshing = true;
this.displayGuiScreen(this.open); this.displayGuiScreen(this.open);
@ -2172,12 +2173,12 @@ public class Client implements IThreadListener {
GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity(); GL11.glLoadIdentity();
GL11.glTranslatef(0.0F, 0.0F, -2000.0F); GL11.glTranslatef(0.0F, 0.0F, -2000.0F);
if(this.scale != 1) if(this.scale != 1.0f)
GL11.glScalef((float)this.scale, (float)this.scale, 1.0f); GL11.glScalef(this.scale, this.scale, 1.0f);
} }
public void scissor(int x, int y, int width, int height) { public void scissor(int x, int y, int width, int height) {
GL11.glScissor(x * this.scale, y * this.scale, width * this.scale, height * this.scale); GL11.glScissor((int)((float)x * this.scale), (int)((float)y * this.scale), (int)((float)width * this.scale), (int)((float)height * this.scale));
} }
private void addFrame(long runningTime) private void addFrame(long runningTime)

View file

@ -104,4 +104,13 @@ public class Font {
texture = 0; texture = 0;
} }
} }
public static void setScale(float scale) {
if(texture != 0) {
GlState.bindTexture(texture);
boolean linear = scale % 1.0f > 0.0f;
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, linear ? GL11.GL_LINEAR : GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, linear ? GL11.GL_LINEAR : GL11.GL_NEAREST);
}
}
} }