From e5f279443e83d19d683eddd56a5b1dd473ea100c Mon Sep 17 00:00:00 2001 From: extio-de Date: Sun, 28 Dec 2025 15:00:42 +0100 Subject: [PATCH] feat(renderer): refactor position management in control implementations --- .../g2d/control/impl/G2DBaseControlImpl.java | 14 ++++++++++---- .../g2d/control/impl/G2DButtonControlImpl.java | 18 ------------------ .../g2d/control/impl/G2DLabelControlImpl.java | 5 +++++ .../g2d/control/impl/G2DSliderControlImpl.java | 5 +++++ .../g2d/control/impl/G2DTableControlImpl.java | 5 +++++ .../control/impl/G2DTextfieldControlImpl.java | 5 +++++ .../control/impl/G2DTextfieldControlImpl2.java | 5 +++++ .../impl/G2DWindowPanelControlImpl.java | 5 +++++ 8 files changed, 40 insertions(+), 22 deletions(-) diff --git a/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DBaseControlImpl.java b/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DBaseControlImpl.java index 64ee946..4d58761 100644 --- a/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DBaseControlImpl.java +++ b/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DBaseControlImpl.java @@ -48,8 +48,6 @@ public abstract class G2DBaseControlImpl implements BaseControl { protected double scaleFactor; - protected boolean modified; - protected String controlGroup; protected boolean visible; @@ -68,6 +66,10 @@ public abstract class G2DBaseControlImpl implements BaseControl { protected short layer; + protected boolean modified; + + protected boolean positionModified; + @Override public BaseControl setInUse(final boolean inUse) { this.inUse = inUse; @@ -105,14 +107,14 @@ public abstract class G2DBaseControlImpl implements BaseControl { @Override public BaseControl setX(final int x) { - this.modified |= this.x != x; + this.positionModified |= this.x != x; this.x = x; return this; } @Override public BaseControl setY(final int y) { - this.modified |= this.y != y; + this.positionModified |= this.y != y; this.y = y; return this; } @@ -200,12 +202,16 @@ public abstract class G2DBaseControlImpl implements BaseControl { if (this.modified) { this.modified = false; } + if (this.positionModified) { + this.positionModified = false; + } } @Override public void build() { this.rebuildBufferedImage(); this.modified = false; + this.positionModified = false; this.enabled = true; } diff --git a/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DButtonControlImpl.java b/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DButtonControlImpl.java index df7e519..ca28c80 100644 --- a/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DButtonControlImpl.java +++ b/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DButtonControlImpl.java @@ -6,8 +6,6 @@ import de.extio.game_engine.renderer.g2d.G2DRenderer; import de.extio.game_engine.renderer.g2d.control.components.CustomAbstractButton; import de.extio.game_engine.renderer.g2d.control.components.CustomButton; import de.extio.game_engine.renderer.g2d.theme.G2DThemeManager; -import de.extio.game_engine.renderer.g2d.theme.G2DThemeManager; -import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.BaseControl; import de.extio.game_engine.renderer.model.bo.ControlRenderingBo.ButtonControl; import de.extio.game_engine.renderer.model.color.RgbaColor; import de.extio.game_engine.renderer.model.event.UiControlEvent; @@ -21,8 +19,6 @@ public class G2DButtonControlImpl extends G2DBaseControlImpl implements ButtonCo private RgbaColor backgroundColor; - private boolean positionModified; - @Override public void build() { super.build(); @@ -96,20 +92,6 @@ public class G2DButtonControlImpl extends G2DBaseControlImpl implements ButtonCo } } - @Override - public BaseControl setX(final int x) { - this.positionModified |= this.x != x; - this.x = x; - return this; - } - - @Override - public BaseControl setY(final int y) { - this.positionModified |= this.y != y; - this.y = y; - return this; - } - @Override public void setIconResource(final StaticResource iconResource) { this.modified |= !Objects.equals(this.iconResource, iconResource); diff --git a/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DLabelControlImpl.java b/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DLabelControlImpl.java index 49526ef..f74aec4 100644 --- a/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DLabelControlImpl.java +++ b/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DLabelControlImpl.java @@ -78,6 +78,10 @@ public class G2DLabelControlImpl extends G2DBaseControlImpl implements LabelCont this.control.setDirty(false); this.updateAllComponentZOrder(); } + else if (this.positionModified) { + this.control.setLocation(this.x, this.y); + this.positionModified = false; + } if (this.tooltip != null) { this.tooltipMousePosition = this.control.getLastMousePosition(); } @@ -104,6 +108,7 @@ public class G2DLabelControlImpl extends G2DBaseControlImpl implements LabelCont protected void initControl() { this.control.setLocation(this.x, this.y); + this.positionModified = false; this.control.setSize(this.width, this.height); this.control.setCaption(this.caption); this.control.setFontSize(this.fontSize); diff --git a/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DSliderControlImpl.java b/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DSliderControlImpl.java index 5ee5727..e2ca92c 100644 --- a/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DSliderControlImpl.java +++ b/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DSliderControlImpl.java @@ -109,6 +109,10 @@ public class G2DSliderControlImpl extends G2DBaseControlImpl implements SliderCo this.control.setDirty(false); this.updateAllComponentZOrder(); } + else if (this.positionModified) { + this.control.setLocation(this.x, this.y); + this.positionModified = false; + } if (this.tooltip != null) { this.tooltipMousePosition = this.control.getLastMousePosition(); } @@ -143,6 +147,7 @@ public class G2DSliderControlImpl extends G2DBaseControlImpl implements SliderCo protected void initControl() { this.control.setLocation(this.x, this.y); + this.positionModified = false; this.control.setSize(this.width, this.height); this.control.setScaleFactor(this.scaleFactor); this.control.setColor(this.color != null ? this.color.toAwtColor() : null); diff --git a/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DTableControlImpl.java b/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DTableControlImpl.java index 34155f6..33e3a26 100644 --- a/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DTableControlImpl.java +++ b/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DTableControlImpl.java @@ -82,6 +82,10 @@ public class G2DTableControlImpl extends G2DBaseControlImpl implements TableCont this.control.setDirty(false); this.updateAllComponentZOrder(); } + else if (this.positionModified) { + this.control.setLocation(this.x, this.y); + this.positionModified = false; + } this.control.paint(this.bufferedImageGraphics); this.scrollbar.render(); @@ -160,6 +164,7 @@ public class G2DTableControlImpl extends G2DBaseControlImpl implements TableCont this.control.setDrawGraphics(this.bufferedImageGraphics); EventQueue.invokeLater(() -> { this.control.setLocation(this.x, this.y); + this.positionModified = false; // this.control.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); this.control.setSize(this.width - 30, this.height); this.control.setEnabled(this.enabled); diff --git a/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DTextfieldControlImpl.java b/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DTextfieldControlImpl.java index f718420..fc9928a 100644 --- a/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DTextfieldControlImpl.java +++ b/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DTextfieldControlImpl.java @@ -103,6 +103,10 @@ public class G2DTextfieldControlImpl extends G2DBaseControlImpl implements Textf } this.updateAllComponentZOrder(); } + else if (this.positionModified) { + this.safeInvoke(() -> this.textComponent.setLocation(this.x, this.y)); + this.positionModified = false; + } super.render(); } @@ -126,6 +130,7 @@ public class G2DTextfieldControlImpl extends G2DBaseControlImpl implements Textf this.safeInvoke(() -> this.textComponent.setBackground(bgColor)); this.safeInvoke(() -> this.textComponent.setForeground(fgColor)); this.safeInvoke(() -> this.textComponent.setLocation(this.x, this.y)); + this.positionModified = false; this.safeInvoke(() -> this.textComponent.setSize(this.width, this.height)); this.safeInvoke(() -> this.textComponent.setFont(G2DDrawFont.getFont(this.scaleFactor, this.fontSize))); this.safeInvoke(() -> this.textComponent.setVisible(this.visible)); diff --git a/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DTextfieldControlImpl2.java b/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DTextfieldControlImpl2.java index 58cffb2..a88e0d0 100644 --- a/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DTextfieldControlImpl2.java +++ b/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DTextfieldControlImpl2.java @@ -194,6 +194,10 @@ public class G2DTextfieldControlImpl2 extends G2DBaseControlImpl implements Text } this.updateAllComponentZOrder(); } + else if (this.positionModified) { + this.safeInvoke(() -> this.textComponent.setLocation(this.x, this.y)); + this.positionModified = false; + } if (this.multiLine) { // this.safeInvoke(() -> this.scrollPane.paint(this.bufferedImageGraphics)); @@ -243,6 +247,7 @@ public class G2DTextfieldControlImpl2 extends G2DBaseControlImpl implements Text // this.safeInvoke(() -> this.scrollPane.setLocation(this.x, this.y)); // this.safeInvoke(() -> this.scrollPane.setSize(this.width, this.height)); this.safeInvoke(() -> this.textComponent.setLocation(this.x, this.y)); + this.positionModified = false; this.safeInvoke(() -> this.textComponent.setSize(this.width - 30, this.height)); this.safeInvoke(() -> this.textComponent.setEditable(false)); // this.safeInvoke(() -> this.textComponent.setFocusable(false)); diff --git a/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DWindowPanelControlImpl.java b/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DWindowPanelControlImpl.java index 0f4921f..35df17c 100644 --- a/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DWindowPanelControlImpl.java +++ b/src/main/java/de/extio/game_engine/renderer/g2d/control/impl/G2DWindowPanelControlImpl.java @@ -61,6 +61,10 @@ public class G2DWindowPanelControlImpl extends G2DBaseControlImpl implements Win this.control.setDirty(false); this.updateAllComponentZOrder(); } + else if (this.positionModified) { + this.control.setLocation(this.x, this.y); + this.positionModified = false; + } super.render(); } @@ -84,6 +88,7 @@ public class G2DWindowPanelControlImpl extends G2DBaseControlImpl implements Win protected void initControl() { this.control.setLocation(this.x, this.y); + this.positionModified = false; this.control.setSize(this.width, this.height); this.control.setScaleFactor(this.scaleFactor); this.control.setThickBorder(this.thickBorder);