feat(renderer): refactor position management in control implementations

This commit is contained in:
extio-de
2025-12-28 15:00:42 +01:00
parent 00acf2296f
commit e5f279443e
8 changed files with 40 additions and 22 deletions

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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));

View File

@@ -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));

View File

@@ -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);