From 80cf16ada57b5a6b847bd2265e2c1e2e8a647bf7 Mon Sep 17 00:00:00 2001 From: Sen Date: Thu, 20 Mar 2025 01:14:54 +0100 Subject: [PATCH] margins, ui fixes --- java/src/game/gui/element/Bar.java | 6 ++++- java/src/game/gui/element/Dropdown.java | 8 +++---- java/src/game/gui/element/Element.java | 24 +++++++++---------- java/src/game/gui/element/Label.java | 6 ++++- java/src/game/gui/element/Slider.java | 4 ++-- java/src/game/gui/element/Textbox.java | 24 +++++++++++-------- java/src/game/gui/element/Toggle.java | 2 +- java/src/game/gui/element/TransparentBox.java | 6 +++-- 8 files changed, 46 insertions(+), 34 deletions(-) diff --git a/java/src/game/gui/element/Bar.java b/java/src/game/gui/element/Bar.java index 1659849..b96c9aa 100644 --- a/java/src/game/gui/element/Bar.java +++ b/java/src/game/gui/element/Bar.java @@ -33,7 +33,11 @@ public class Bar extends Fill { Drawing.drawText(this.text, x1 + this.text_x, y1 + this.text_y, this.gm.style.text_label); } - protected int getMargin() { + protected int getMarginX() { + return 0; + } + + protected int getMarginY() { return 0; } diff --git a/java/src/game/gui/element/Dropdown.java b/java/src/game/gui/element/Dropdown.java index 8957689..716e2b3 100644 --- a/java/src/game/gui/element/Dropdown.java +++ b/java/src/game/gui/element/Dropdown.java @@ -19,7 +19,7 @@ public class Dropdown extends Element { sb.append(value instanceof Displayable ? ((Displayable)value).getDisplay() : value.toString()); } this.setText(sb.toString()); - this.visible = this.r_dirty = false; + this.visible = /* this.r_dirty = */ false; } public void updateText() { @@ -39,7 +39,7 @@ public class Dropdown extends Element { public void deselect() { this.visible = false; - this.r_dirty = true; +// this.r_dirty = true; } public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) { @@ -53,7 +53,7 @@ public class Dropdown extends Element { this.playSound(); } this.visible = false; - this.r_dirty = true; +// this.r_dirty = true; } public void drawHover() { @@ -113,7 +113,7 @@ public class Dropdown extends Element { else if(this.gui != null) { Handle drop = this.handle; drop.visible = true; - drop.r_dirty = true; +// drop.r_dirty = true; this.gui.selected = drop; this.playSound(); } diff --git a/java/src/game/gui/element/Element.java b/java/src/game/gui/element/Element.java index dbbb40b..dcad5f9 100644 --- a/java/src/game/gui/element/Element.java +++ b/java/src/game/gui/element/Element.java @@ -20,27 +20,21 @@ public abstract class Element { protected Formatter format; protected String text = ""; -// String format_text; -// Object aux_data; -// String[] format_data; -// CVar cv_data; - protected int pos_x; protected int pos_y; protected int size_x; protected int size_y; protected int text_x = 0; protected int text_y = 0; - - protected final int margin_x1 = this.getMargin(); - protected final int margin_y1 = this.getMargin(); - protected final int margin_x2 = this.getMargin(); - protected final int margin_y2 = this.getMargin(); + + protected final int margin_x1 = this.getMarginX(); + protected final int margin_y1 = this.getMarginY(); + protected final int margin_x2 = this.getMarginX(); + protected final int margin_y2 = this.getMarginY(); public boolean visible = true; public boolean enabled = true; - public boolean r_dirty = true; - + public Element(int x, int y, int w, int h, Formatter formatter) { this.pos_x = x; @@ -63,7 +57,11 @@ public abstract class Element { this.gui = gui; } - protected int getMargin() { + protected int getMarginX() { + return 1; + } + + protected int getMarginY() { return 1; } diff --git a/java/src/game/gui/element/Label.java b/java/src/game/gui/element/Label.java index 6f356ad..1f283bc 100644 --- a/java/src/game/gui/element/Label.java +++ b/java/src/game/gui/element/Label.java @@ -22,7 +22,11 @@ public class Label extends Fill { Drawing.drawText(this.text, x1 + this.text_x, y1 + this.text_y, this.gm.style.text_label); } - protected int getMargin() { + protected int getMarginX() { + return 0; + } + + protected int getMarginY() { return 0; } } diff --git a/java/src/game/gui/element/Slider.java b/java/src/game/gui/element/Slider.java index 8c9114a..932936c 100644 --- a/java/src/game/gui/element/Slider.java +++ b/java/src/game/gui/element/Slider.java @@ -127,8 +127,8 @@ public class Slider extends Element { public void reformat() { this.position = gui_slider_pixel(); - if(this.visible) - this.r_dirty = true; +// if(this.visible) +// this.r_dirty = true; super.reformat(); } diff --git a/java/src/game/gui/element/Textbox.java b/java/src/game/gui/element/Textbox.java index 44e8135..4710bdf 100644 --- a/java/src/game/gui/element/Textbox.java +++ b/java/src/game/gui/element/Textbox.java @@ -97,6 +97,10 @@ public class Textbox extends Element { return false; } + protected int getMarginX() { + return 4; + } + public void setText(String str) { if(this.validator != null) str = this.validator.filter(str); @@ -115,7 +119,7 @@ public class Textbox extends Element { this.text_y = ExtMath.clampi(this.text_y, -limit, 0); if(this.sel_start >= 0) this.cursorY += (this.text_y - prev); - this.r_dirty = true; +// this.r_dirty = true; } else if(scr_y != 0 || scr_x != 0) { int limit = Font.XGLYPH + this.tsize_x - (this.size_x - (this.margin_x1 + this.margin_x2)); @@ -125,7 +129,7 @@ public class Textbox extends Element { this.text_x = ExtMath.clampi(this.text_x, -limit, 0); if(this.sel_start >= 0) this.cursorX += (this.text_x - prev); - this.r_dirty = true; +// this.r_dirty = true; } } @@ -134,7 +138,7 @@ public class Textbox extends Element { if(!shift && ((Timing.tmr_current - this.tmr_leftmb) <= (((long)this.gm.dclickDelay) * 1000L))) { this.sel_start = this.sel_drag = 0; this.sel_end = this.text.length(); - this.r_dirty = true; +// this.r_dirty = true; } else { gui_text_select(x, y, shift); @@ -168,7 +172,7 @@ public class Textbox extends Element { if(ctrl && key == Keysym.A) { this.sel_start = this.sel_drag = 0; this.sel_end = this.text.length(); - this.r_dirty = true; +// this.r_dirty = true; } else if(ctrl && (key == Keysym.C) || (this.editable && (key == Keysym.X))) { if(this.sel_start >= 0 && this.sel_start != this.sel_end) { // fix empty @@ -293,7 +297,7 @@ public class Textbox extends Element { public void deselect() { this.sel_start = this.sel_end = this.sel_drag = -1; this.tmr_leftmb = 0L; - this.r_dirty = true; +// this.r_dirty = true; if(this.func != null) { this.func.use(this, Action.UNFOCUS); } @@ -308,7 +312,7 @@ public class Textbox extends Element { this.text_y += (n = (int)((float)((float)this.tmr_scroll) / 1000000.0f * 4.0f * ((float)this.scrolly))); if(n != 0) { gui_text_clamp_scroll(); - this.r_dirty = true; +// this.r_dirty = true; } if((((long)n) * 1000000L) <= this.tmr_scroll) this.tmr_scroll -= ((long)n) * 1000000L; @@ -359,9 +363,9 @@ public class Textbox extends Element { this.text_x -= (this.cursorX + Font.XGLYPH) - (x1 + x2); gui_text_update_cur(offset, false); } - else { - this.r_dirty = true; - } +// else { +// this.r_dirty = true; +// } } public void insertText(String str) { @@ -410,7 +414,7 @@ public class Textbox extends Element { this.sel_end = this.sel_drag; } // logd("tst", "@S %d . %d . %d", this.sel_start, this.sel_drag, this.sel_end); - this.r_dirty = true; +// this.r_dirty = true; if(x < x1) this.scrollx = x1 - x; else if(x >= (x1 + x2)) diff --git a/java/src/game/gui/element/Toggle.java b/java/src/game/gui/element/Toggle.java index 604d513..f2acdf3 100644 --- a/java/src/game/gui/element/Toggle.java +++ b/java/src/game/gui/element/Toggle.java @@ -36,7 +36,7 @@ public class Toggle extends Element { if((this.value = (ctrl || (btn == Button.MOUSE_MIDDLE)) ? this.def : !this.value) != prev) { // this.type = this.value != 0 ? ElemType.TOGGLE_ON : ElemType.TOGGLE_OFF; // gui_update_style(this, 1); - this.r_dirty = true; +// this.r_dirty = true; this.func.use(this, this.value); this.formatText(); this.playSound(); diff --git a/java/src/game/gui/element/TransparentBox.java b/java/src/game/gui/element/TransparentBox.java index 3f7ac25..7a59963 100644 --- a/java/src/game/gui/element/TransparentBox.java +++ b/java/src/game/gui/element/TransparentBox.java @@ -1,12 +1,14 @@ package game.gui.element; +import game.renderer.Drawing; + public class TransparentBox extends Textbox { public TransparentBox(int x, int y, int w, int h, String text) { super(x, y, w, h, text); } protected void drawBackground() { -// Drawing.drawGradient2Border(this.pos_x, this.pos_y, this.size_x, this.size_y, -// this.gm.style.field_top & 0x80ffffff, this.gm.style.field_btm & 0x80ffffff, this.gm.style.brdr_top & 0x80ffffff, this.gm.style.brdr_btm & 0x80ffffff); + if(this.gm.theWorld != null) + Drawing.drawRect(this.pos_x, this.pos_y, this.size_x, this.size_y, 0x3f000000); } }