Refactor button rendering methods to use boolean flags for state management

- Updated the drawCloseButton and drawButton methods in various PatternRenderer implementations to replace the integer state parameter with individual boolean parameters for pressed, hovered, and toggled states.
- This change enhances code readability and maintainability by making the button states explicit.
- Adjusted the logic in each renderer to accommodate the new method signatures and ensure consistent behavior across different themes.
This commit is contained in:
extio-de
2026-01-28 21:21:27 +01:00
parent 60715a9ef1
commit bb4d8ffd61
18 changed files with 162 additions and 276 deletions

View File

@@ -0,0 +1,39 @@
package de.extio.game_engine.renderer.g2d.control.components;
public class ButtonState {
private volatile boolean toggled;
private volatile boolean pressed;
private volatile boolean hovered;
public boolean isToggled() {
return this.toggled;
}
public void setToggled(final boolean toggled) {
this.toggled = toggled;
}
public boolean isPressed() {
return this.pressed;
}
public void setPressed(final boolean pressed) {
this.pressed = pressed;
}
public boolean isHovered() {
return this.hovered;
}
public void setHovered(final boolean hovered) {
this.hovered = hovered;
}
public void toggleToggled() {
this.toggled = !this.toggled;
}
}

View File

@@ -37,17 +37,9 @@ public abstract class CustomAbstractButton extends Component {
} }
}; };
protected static final int STATE_NORMAL = 0;
protected static final int STATE_TOGGLED = 1;
protected static final int STATE_PRESSED = 2;
protected static final int STATE_HOVERED = 4;
protected String caption; protected String caption;
protected int state = STATE_NORMAL; protected final ButtonState state = new ButtonState();
protected int fontSize; protected int fontSize;
@@ -82,17 +74,11 @@ public abstract class CustomAbstractButton extends Component {
} }
public boolean isToggled() { public boolean isToggled() {
return (this.state & STATE_TOGGLED) != 0; return this.state.isToggled();
} }
public void setToggled(final boolean toggled) { public void setToggled(final boolean toggled) {
if (toggled) { this.state.setToggled(toggled);
this.state |= STATE_TOGGLED;
}
else {
this.state &= ~STATE_TOGGLED;
}
this.dirty = true; this.dirty = true;
} }
@@ -142,7 +128,7 @@ public abstract class CustomAbstractButton extends Component {
return; return;
} }
CustomAbstractButton.this.state |= STATE_PRESSED; CustomAbstractButton.this.state.setPressed(true);
CustomAbstractButton.this.dirty = true; CustomAbstractButton.this.dirty = true;
e.consume(); e.consume();
} }
@@ -154,13 +140,13 @@ public abstract class CustomAbstractButton extends Component {
return; return;
} }
CustomAbstractButton.this.state &= ~STATE_PRESSED; CustomAbstractButton.this.state.setPressed(false);
if (CustomAbstractButton.this.toggle) { if (CustomAbstractButton.this.toggle) {
CustomAbstractButton.this.state ^= STATE_TOGGLED; CustomAbstractButton.this.state.toggleToggled();
} }
CustomAbstractButton.this.dirty = true; CustomAbstractButton.this.dirty = true;
listener.actionPerformed(new ActionEvent(this, CustomAbstractButton.this.state & STATE_TOGGLED, null)); listener.actionPerformed(new ActionEvent(this, CustomAbstractButton.this.state.isToggled() ? 1 : 0, null));
e.consume(); e.consume();
} }
@@ -171,7 +157,7 @@ public abstract class CustomAbstractButton extends Component {
return; return;
} }
CustomAbstractButton.this.state |= STATE_HOVERED; CustomAbstractButton.this.state.setHovered(true);
CustomAbstractButton.this.dirty = true; CustomAbstractButton.this.dirty = true;
CustomAbstractButton.this.lastMousePosition = ImmutableCoordI2.create(e.getX(), e.getY()); CustomAbstractButton.this.lastMousePosition = ImmutableCoordI2.create(e.getX(), e.getY());
e.consume(); e.consume();
@@ -180,7 +166,7 @@ public abstract class CustomAbstractButton extends Component {
@Override @Override
public void mouseExited(final MouseEvent e) { public void mouseExited(final MouseEvent e) {
CustomAbstractButton.this.lastMousePosition = null; CustomAbstractButton.this.lastMousePosition = null;
CustomAbstractButton.this.state &= ~STATE_HOVERED; CustomAbstractButton.this.state.setHovered(false);
CustomAbstractButton.this.dirty = true; CustomAbstractButton.this.dirty = true;
e.consume(); e.consume();
} }

View File

@@ -29,7 +29,7 @@ public class CustomButton extends CustomAbstractButton {
final var patternRenderer = this.themeManager.getPatternRenderer(theme.getPatternRendererName()); final var patternRenderer = this.themeManager.getPatternRenderer(theme.getPatternRendererName());
if (patternRenderer != null) { if (patternRenderer != null) {
patternRenderer.drawButton(g2d, 0, 0, this.getWidth(), this.getHeight(), this.isEnabled(), this.state, this.backgroundColor, this.scaleFactor, theme); patternRenderer.drawButton(g2d, 0, 0, this.getWidth(), this.getHeight(), this.isEnabled(), this.state.isPressed(), this.state.isHovered(), this.state.isToggled(), this.backgroundColor, this.scaleFactor, theme);
} }
final var bgrStrength = (this.getWidth() < 48 || this.getHeight() < 48) ? 0 : 2; final var bgrStrength = (this.getWidth() < 48 || this.getHeight() < 48) ? 0 : 2;
@@ -41,10 +41,10 @@ public class CustomButton extends CustomAbstractButton {
g2d.drawImage(this.icon, 4 + bgrStrength, 4 + bgrStrength, this.getWidth() - 4 - bgrStrength, this.getHeight() - 4 - bgrStrength, 0, 0, this.icon.getWidth(), this.icon.getHeight(), null); g2d.drawImage(this.icon, 4 + bgrStrength, 4 + bgrStrength, this.getWidth() - 4 - bgrStrength, this.getHeight() - 4 - bgrStrength, 0, 0, this.icon.getWidth(), this.icon.getHeight(), null);
} }
else if (this.caption != null) { else if (this.caption != null) {
if ((this.state & STATE_HOVERED) != 0) { if (this.state.isHovered()) {
g2d.setColor(theme.getTextNormal().adjustBrightness(theme.getHoverBrightnessAdjustment()).toColor()); g2d.setColor(theme.getTextNormal().adjustBrightness(theme.getHoverBrightnessAdjustment()).toColor());
} }
else if ((this.state & STATE_TOGGLED) != 0) { else if (this.state.isToggled()) {
g2d.setColor(theme.getTextNormal().adjustBrightness(theme.getHoverBrightnessAdjustment()).toColor()); g2d.setColor(theme.getTextNormal().adjustBrightness(theme.getHoverBrightnessAdjustment()).toColor());
} }
else if (this.isEnabled()) { else if (this.isEnabled()) {

View File

@@ -32,21 +32,21 @@ public class CustomSwitch extends CustomAbstractButton {
final var dimY = this.getHeight() - 1; final var dimY = this.getHeight() - 1;
final var dimX = (int) (dimY * 1.5); final var dimX = (int) (dimY * 1.5);
if ((this.state & STATE_TOGGLED) == 0) { if (!this.state.isToggled()) {
if (patternRenderer != null) { if (patternRenderer != null) {
patternRenderer.drawButton(g2d, 6, 4, (int) (dimX / 1.5) - 6, this.getHeight() - 9, this.isEnabled(), this.state, null, this.scaleFactor, theme); patternRenderer.drawButton(g2d, 6, 4, (int) (dimX / 1.5) - 6, this.getHeight() - 9, this.isEnabled(), this.state.isPressed(), this.state.isHovered(), this.state.isToggled(), null, this.scaleFactor, theme);
} }
} }
else { else {
if (patternRenderer != null) { if (patternRenderer != null) {
patternRenderer.drawButton(g2d, dimX - (int) (dimX / 1.5) - 3, 4, (int) (dimX / 1.5) - 6, this.getHeight() - 9, this.isEnabled(), this.state, null, this.scaleFactor, theme); patternRenderer.drawButton(g2d, dimX - (int) (dimX / 1.5) - 3, 4, (int) (dimX / 1.5) - 6, this.getHeight() - 9, this.isEnabled(), this.state.isPressed(), this.state.isHovered(), this.state.isToggled(), null, this.scaleFactor, theme);
} }
} }
if ((this.state & STATE_HOVERED) != 0) { if (this.state.isHovered()) {
g2d.setColor(theme.getTextNormal().adjustBrightness(theme.getHoverBrightnessAdjustment()).toColor()); g2d.setColor(theme.getTextNormal().adjustBrightness(theme.getHoverBrightnessAdjustment()).toColor());
} }
else if ((this.state & STATE_TOGGLED) != 0) { else if (this.state.isToggled()) {
g2d.setColor(theme.getTextNormal().adjustBrightness(theme.getHoverBrightnessAdjustment()).toColor()); g2d.setColor(theme.getTextNormal().adjustBrightness(theme.getHoverBrightnessAdjustment()).toColor());
} }
else if (this.isEnabled()) { else if (this.isEnabled()) {
@@ -65,7 +65,7 @@ public class CustomSwitch extends CustomAbstractButton {
this.caption); this.caption);
if (this.drawBorder) { if (this.drawBorder) {
final var borderColor1 = (this.state & STATE_HOVERED) != 0 ? theme.getSelectionPrimary().toColor() : theme.getBorderOuter().toColor(); final var borderColor1 = this.state.isHovered() ? theme.getSelectionPrimary().toColor() : theme.getBorderOuter().toColor();
if (patternRenderer != null) { if (patternRenderer != null) {
patternRenderer.drawDecorativeBorder(g2d, 0, 0, this.getWidth() - 1, this.getHeight() - 1, 2, borderColor1); patternRenderer.drawDecorativeBorder(g2d, 0, 0, this.getWidth() - 1, this.getHeight() - 1, 2, borderColor1);

View File

@@ -27,7 +27,7 @@ public class CustomWindowCloseButton extends CustomAbstractButton {
final var patternRenderer = this.themeManager.getPatternRenderer(theme.getPatternRendererName()); final var patternRenderer = this.themeManager.getPatternRenderer(theme.getPatternRendererName());
if (patternRenderer != null) { if (patternRenderer != null) {
patternRenderer.drawCloseButton(g2d, this.getWidth(), this.getHeight(), this.isEnabled(), this.state, this.backgroundColor, this.scaleFactor, theme); patternRenderer.drawCloseButton(g2d, this.getWidth(), this.getHeight(), this.isEnabled(), this.state.isPressed(), this.state.isHovered(), this.state.isToggled(), this.backgroundColor, this.scaleFactor, theme);
} }
} }

View File

@@ -53,9 +53,7 @@ public class BevelPatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final var STATE_PRESSED = 2;
final var pressed = (state & STATE_PRESSED) != 0;
// Button background // Button background
final Color btnBg = backgroundColor != null ? backgroundColor : theme.getBackgroundNormal().toColor(); final Color btnBg = backgroundColor != null ? backgroundColor : theme.getBackgroundNormal().toColor();
@@ -129,23 +127,19 @@ public class BevelPatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final int STATE_TOGGLED = 1;
final int STATE_PRESSED = 2;
final int STATE_HOVERED = 4;
float h, s, b; float h, s, b;
if (backgroundColor == null) { if (backgroundColor == null) {
final var baseColor = (state & STATE_TOGGLED) == 0 ? theme.getBackgroundNormal() : theme.getBackgroundSelected(); final var baseColor = !toggled ? theme.getBackgroundNormal() : theme.getBackgroundSelected();
h = baseColor.getHue(); h = baseColor.getHue();
s = baseColor.getSaturation(); s = baseColor.getSaturation();
b = baseColor.getBrightness(); b = baseColor.getBrightness();
if ((state & STATE_PRESSED) != 0) { if (pressed) {
b += theme.getPressedBrightnessAdjustment(); b += theme.getPressedBrightnessAdjustment();
} }
else if ((state & STATE_HOVERED) != 0) { else if (hovered) {
b += theme.getHoverBrightnessAdjustment(); b += theme.getHoverBrightnessAdjustment();
} }
} }
@@ -155,16 +149,16 @@ public class BevelPatternRenderer implements PatternRenderer {
h = hsb[0]; h = hsb[0];
s = hsb[1]; s = hsb[1];
if ((state & STATE_TOGGLED) == 0) { if (!toggled) {
b = 0.30F; b = 0.30F;
} }
else { else {
b = 0.50F; b = 0.50F;
} }
if ((state & STATE_PRESSED) != 0) { if (pressed) {
b += theme.getPressedBrightnessAdjustment(); b += theme.getPressedBrightnessAdjustment();
} }
else if ((state & STATE_HOVERED) != 0) { else if (hovered) {
b += theme.getHoverBrightnessAdjustment(); b += theme.getHoverBrightnessAdjustment();
} }
} }
@@ -178,10 +172,9 @@ public class BevelPatternRenderer implements PatternRenderer {
if (bevelStrength < 1) if (bevelStrength < 1)
bevelStrength = 1; bevelStrength = 1;
final boolean pressed = (state & STATE_PRESSED) != 0; final Color highlight = hovered ? theme.getSelectionPrimary().toColor() : theme.getBorderOuter().toColor();
final Color highlight = (state & STATE_HOVERED) != 0 ? theme.getSelectionPrimary().toColor() : theme.getBorderOuter().toColor();
final Color shadow = enabled ? final Color shadow = enabled ?
(state & STATE_HOVERED) != 0 ? theme.getSelectionSecondary().toColor() : theme.getBorderInner().toColor() : hovered ? theme.getSelectionSecondary().toColor() : theme.getBorderInner().toColor() :
theme.getBorderInnerDisabled().toColor(); theme.getBorderInnerDisabled().toColor();
drawBevel(g2d, x, y, width, height, bevelStrength, !pressed, highlight, shadow); drawBevel(g2d, x, y, width, height, bevelStrength, !pressed, highlight, shadow);

View File

@@ -84,9 +84,7 @@ public class BlueprintPatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final var STATE_PRESSED = 2;
final var pressed = (state & STATE_PRESSED) != 0;
// Button background (transparent or slightly lighter blue) // Button background (transparent or slightly lighter blue)
Color btnBg = backgroundColor; Color btnBg = backgroundColor;
@@ -143,23 +141,19 @@ public class BlueprintPatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final int STATE_TOGGLED = 1;
final int STATE_PRESSED = 2;
final int STATE_HOVERED = 4;
float h, s, b; float h, s, b;
if (backgroundColor == null) { if (backgroundColor == null) {
final var baseColor = (state & STATE_TOGGLED) == 0 ? theme.getBackgroundNormal() : theme.getBackgroundSelected(); final var baseColor = !toggled ? theme.getBackgroundNormal() : theme.getBackgroundSelected();
h = baseColor.getHue(); h = baseColor.getHue();
s = baseColor.getSaturation(); s = baseColor.getSaturation();
b = baseColor.getBrightness(); b = baseColor.getBrightness();
if ((state & STATE_PRESSED) != 0) { if (pressed) {
b += theme.getPressedBrightnessAdjustment(); b += theme.getPressedBrightnessAdjustment();
} }
else if ((state & STATE_HOVERED) != 0) { else if (hovered) {
b += theme.getHoverBrightnessAdjustment(); b += theme.getHoverBrightnessAdjustment();
} }
} }
@@ -169,16 +163,16 @@ public class BlueprintPatternRenderer implements PatternRenderer {
h = hsb[0]; h = hsb[0];
s = hsb[1]; s = hsb[1];
if ((state & STATE_TOGGLED) == 0) { if (!toggled) {
b = 0.30F; b = 0.30F;
} }
else { else {
b = 0.50F; b = 0.50F;
} }
if ((state & STATE_PRESSED) != 0) { if (pressed) {
b += theme.getPressedBrightnessAdjustment(); b += theme.getPressedBrightnessAdjustment();
} }
else if ((state & STATE_HOVERED) != 0) { else if (hovered) {
b += theme.getHoverBrightnessAdjustment(); b += theme.getHoverBrightnessAdjustment();
} }
} }
@@ -201,7 +195,7 @@ public class BlueprintPatternRenderer implements PatternRenderer {
} }
final var borderStrength = Math.max(1, (int) (2 * scaleFactor)); final var borderStrength = Math.max(1, (int) (2 * scaleFactor));
final var borderColor = (state & STATE_HOVERED) != 0 ? theme.getSelectionPrimary().toColor() : final var borderColor = hovered ? theme.getSelectionPrimary().toColor() :
enabled ? theme.getBorderOuter().toColor() : theme.getBorderInnerDisabled().toColor(); enabled ? theme.getBorderOuter().toColor() : theme.getBorderInnerDisabled().toColor();
this.drawDecorativeBorder(g2d, x, y, width, height, borderStrength, borderColor); this.drawDecorativeBorder(g2d, x, y, width, height, borderStrength, borderColor);
} }

View File

@@ -92,14 +92,7 @@ public class ChroniclePatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final int STATE_HOVERED = 4;
final int STATE_TOGGLED = 1;
final int STATE_PRESSED = 2;
final boolean hovered = (state & STATE_HOVERED) != 0;
final boolean pressed = (state & STATE_PRESSED) != 0;
final boolean toggled = (state & STATE_TOGGLED) != 0;
Color base = backgroundColor; Color base = backgroundColor;
if (base == null) { if (base == null) {
@@ -199,15 +192,7 @@ public class ChroniclePatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final int STATE_TOGGLED = 1;
final int STATE_PRESSED = 2;
final int STATE_HOVERED = 4;
final boolean toggled = (state & STATE_TOGGLED) != 0;
final boolean pressed = (state & STATE_PRESSED) != 0;
final boolean hovered = (state & STATE_HOVERED) != 0;
float h, s, b; float h, s, b;
if (backgroundColor == null) { if (backgroundColor == null) {

View File

@@ -109,14 +109,7 @@ public class ContemporaryPatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final int STATE_HOVERED = 4;
final int STATE_TOGGLED = 1;
final int STATE_PRESSED = 2;
final boolean hovered = (state & STATE_HOVERED) != 0;
final boolean pressed = (state & STATE_PRESSED) != 0;
final boolean toggled = (state & STATE_TOGGLED) != 0;
Color base = backgroundColor; Color base = backgroundColor;
if (base == null) { if (base == null) {
@@ -219,15 +212,7 @@ public class ContemporaryPatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final int STATE_TOGGLED = 1;
final int STATE_PRESSED = 2;
final int STATE_HOVERED = 4;
final boolean toggled = (state & STATE_TOGGLED) != 0;
final boolean pressed = (state & STATE_PRESSED) != 0;
final boolean hovered = (state & STATE_HOVERED) != 0;
float h, s, b; float h, s, b;
if (backgroundColor == null) { if (backgroundColor == null) {

View File

@@ -46,13 +46,8 @@ public class DreamPatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final var STATE_HOVERED = 4; final var highlight = (hovered || toggled);
final var STATE_TOGGLED = 1;
final var STATE_PRESSED = 2;
final var highlight = (state & (STATE_HOVERED | STATE_TOGGLED)) != 0;
final var pressed = (state & STATE_PRESSED) != 0;
Color bg = backgroundColor; Color bg = backgroundColor;
if (bg == null) { if (bg == null) {
@@ -131,27 +126,19 @@ public class DreamPatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final int STATE_TOGGLED = 1;
final int STATE_PRESSED = 2;
final int STATE_HOVERED = 4;
final boolean toggled = (state & STATE_TOGGLED) != 0;
final boolean pressed = (state & STATE_PRESSED) != 0;
final boolean hovered = (state & STATE_HOVERED) != 0;
float h, s, b; float h, s, b;
if (backgroundColor == null) { if (backgroundColor == null) {
final var baseColor = (state & STATE_TOGGLED) == 0 ? theme.getBackgroundNormal() : theme.getBackgroundSelected(); final var baseColor = !toggled ? theme.getBackgroundNormal() : theme.getBackgroundSelected();
h = baseColor.getHue(); h = baseColor.getHue();
s = baseColor.getSaturation(); s = baseColor.getSaturation();
b = baseColor.getBrightness(); b = baseColor.getBrightness();
if ((state & STATE_PRESSED) != 0) { if (pressed) {
b += theme.getPressedBrightnessAdjustment(); b += theme.getPressedBrightnessAdjustment();
} }
else if ((state & STATE_HOVERED) != 0) { else if (hovered) {
b += theme.getHoverBrightnessAdjustment(); b += theme.getHoverBrightnessAdjustment();
} }
} }
@@ -161,16 +148,16 @@ public class DreamPatternRenderer implements PatternRenderer {
h = hsb[0]; h = hsb[0];
s = hsb[1]; s = hsb[1];
if ((state & STATE_TOGGLED) == 0) { if (!toggled) {
b = 0.30F; b = 0.30F;
} }
else { else {
b = 0.50F; b = 0.50F;
} }
if ((state & STATE_PRESSED) != 0) { if (pressed) {
b += theme.getPressedBrightnessAdjustment(); b += theme.getPressedBrightnessAdjustment();
} }
else if ((state & STATE_HOVERED) != 0) { else if (hovered) {
b += theme.getHoverBrightnessAdjustment(); b += theme.getHoverBrightnessAdjustment();
} }
} }

View File

@@ -55,13 +55,8 @@ public class FantasyPatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final var STATE_HOVERED = 4; final var highlight = (hovered || toggled);
final var STATE_TOGGLED = 1;
final var STATE_PRESSED = 2;
final var highlight = (state & (STATE_HOVERED | STATE_TOGGLED)) != 0;
final var pressed = (state & STATE_PRESSED) != 0;
Color bg = backgroundColor; Color bg = backgroundColor;
if (bg == null) { if (bg == null) {
@@ -141,27 +136,19 @@ public class FantasyPatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final int STATE_TOGGLED = 1;
final int STATE_PRESSED = 2;
final int STATE_HOVERED = 4;
final boolean toggled = (state & STATE_TOGGLED) != 0;
final boolean pressed = (state & STATE_PRESSED) != 0;
final boolean hovered = (state & STATE_HOVERED) != 0;
float h, s, b; float h, s, b;
if (backgroundColor == null) { if (backgroundColor == null) {
final var baseColor = (state & STATE_TOGGLED) == 0 ? theme.getBackgroundNormal() : theme.getBackgroundSelected(); final var baseColor = !toggled ? theme.getBackgroundNormal() : theme.getBackgroundSelected();
h = baseColor.getHue(); h = baseColor.getHue();
s = baseColor.getSaturation(); s = baseColor.getSaturation();
b = baseColor.getBrightness(); b = baseColor.getBrightness();
if ((state & STATE_PRESSED) != 0) { if (pressed) {
b += theme.getPressedBrightnessAdjustment(); b += theme.getPressedBrightnessAdjustment();
} }
else if ((state & STATE_HOVERED) != 0) { else if (hovered) {
b += theme.getHoverBrightnessAdjustment(); b += theme.getHoverBrightnessAdjustment();
} }
} }
@@ -171,16 +158,16 @@ public class FantasyPatternRenderer implements PatternRenderer {
h = hsb[0]; h = hsb[0];
s = hsb[1]; s = hsb[1];
if ((state & STATE_TOGGLED) == 0) { if (!toggled) {
b = 0.30F; b = 0.30F;
} }
else { else {
b = 0.50F; b = 0.50F;
} }
if ((state & STATE_PRESSED) != 0) { if (pressed) {
b += theme.getPressedBrightnessAdjustment(); b += theme.getPressedBrightnessAdjustment();
} }
else if ((state & STATE_HOVERED) != 0) { else if (hovered) {
b += theme.getHoverBrightnessAdjustment(); b += theme.getHoverBrightnessAdjustment();
} }
} }

View File

@@ -68,13 +68,8 @@ public class MetroPatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final var STATE_HOVERED = 4; final var highlight = (hovered || toggled);
final var STATE_TOGGLED = 1;
final var STATE_PRESSED = 2;
final var highlight = (state & (STATE_HOVERED | STATE_TOGGLED)) != 0;
final var pressed = (state & STATE_PRESSED) != 0;
Color bg = backgroundColor; Color bg = backgroundColor;
if (bg == null) { if (bg == null) {
@@ -143,27 +138,19 @@ public class MetroPatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final int STATE_TOGGLED = 1;
final int STATE_PRESSED = 2;
final int STATE_HOVERED = 4;
final boolean toggled = (state & STATE_TOGGLED) != 0;
final boolean pressed = (state & STATE_PRESSED) != 0;
final boolean hovered = (state & STATE_HOVERED) != 0;
float h, s, b; float h, s, b;
if (backgroundColor == null) { if (backgroundColor == null) {
final var baseColor = (state & STATE_TOGGLED) == 0 ? theme.getBackgroundNormal() : theme.getBackgroundSelected(); final var baseColor = !toggled ? theme.getBackgroundNormal() : theme.getBackgroundSelected();
h = baseColor.getHue(); h = baseColor.getHue();
s = baseColor.getSaturation(); s = baseColor.getSaturation();
b = baseColor.getBrightness(); b = baseColor.getBrightness();
if ((state & STATE_PRESSED) != 0) { if (pressed) {
b += theme.getPressedBrightnessAdjustment(); b += theme.getPressedBrightnessAdjustment();
} }
else if ((state & STATE_HOVERED) != 0) { else if (hovered) {
b += theme.getHoverBrightnessAdjustment(); b += theme.getHoverBrightnessAdjustment();
} }
} }
@@ -173,16 +160,16 @@ public class MetroPatternRenderer implements PatternRenderer {
h = hsb[0]; h = hsb[0];
s = hsb[1]; s = hsb[1];
if ((state & STATE_TOGGLED) == 0) { if (!toggled) {
b = 0.30F; b = 0.30F;
} }
else { else {
b = 0.50F; b = 0.50F;
} }
if ((state & STATE_PRESSED) != 0) { if (pressed) {
b += theme.getPressedBrightnessAdjustment(); b += theme.getPressedBrightnessAdjustment();
} }
else if ((state & STATE_HOVERED) != 0) { else if (hovered) {
b += theme.getHoverBrightnessAdjustment(); b += theme.getHoverBrightnessAdjustment();
} }
} }

View File

@@ -48,13 +48,8 @@ public class ModernPatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final var STATE_HOVERED = 4; final var highlight = (hovered || toggled);
final var STATE_TOGGLED = 1;
final var STATE_PRESSED = 2;
final var highlight = (state & (STATE_HOVERED | STATE_TOGGLED)) != 0;
final var pressed = (state & STATE_PRESSED) != 0;
Color bgColor = backgroundColor; Color bgColor = backgroundColor;
if (bgColor == null) { if (bgColor == null) {
@@ -133,27 +128,19 @@ public class ModernPatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final int STATE_TOGGLED = 1;
final int STATE_PRESSED = 2;
final int STATE_HOVERED = 4;
final boolean toggled = (state & STATE_TOGGLED) != 0;
final boolean pressed = (state & STATE_PRESSED) != 0;
final boolean hovered = (state & STATE_HOVERED) != 0;
float h, s, b; float h, s, b;
if (backgroundColor == null) { if (backgroundColor == null) {
final var baseColor = (state & STATE_TOGGLED) == 0 ? theme.getBackgroundNormal() : theme.getBackgroundSelected(); final var baseColor = !toggled ? theme.getBackgroundNormal() : theme.getBackgroundSelected();
h = baseColor.getHue(); h = baseColor.getHue();
s = baseColor.getSaturation(); s = baseColor.getSaturation();
b = baseColor.getBrightness(); b = baseColor.getBrightness();
if ((state & STATE_PRESSED) != 0) { if (pressed) {
b += theme.getPressedBrightnessAdjustment(); b += theme.getPressedBrightnessAdjustment();
} }
else if ((state & STATE_HOVERED) != 0) { else if (hovered) {
b += theme.getHoverBrightnessAdjustment(); b += theme.getHoverBrightnessAdjustment();
} }
} }
@@ -163,16 +150,16 @@ public class ModernPatternRenderer implements PatternRenderer {
h = hsb[0]; h = hsb[0];
s = hsb[1]; s = hsb[1];
if ((state & STATE_TOGGLED) == 0) { if (!toggled) {
b = 0.30F; b = 0.30F;
} }
else { else {
b = 0.50F; b = 0.50F;
} }
if ((state & STATE_PRESSED) != 0) { if (pressed) {
b += theme.getPressedBrightnessAdjustment(); b += theme.getPressedBrightnessAdjustment();
} }
else if ((state & STATE_HOVERED) != 0) { else if (hovered) {
b += theme.getHoverBrightnessAdjustment(); b += theme.getHoverBrightnessAdjustment();
} }
} }

View File

@@ -60,12 +60,14 @@ public interface PatternRenderer {
* @param width Width of the button * @param width Width of the button
* @param height Height of the button * @param height Height of the button
* @param enabled Whether the button is enabled * @param enabled Whether the button is enabled
* @param state Button state flags (hovered, pressed, toggled) * @param pressed Whether the button is pressed
* @param hovered Whether the button is hovered
* @param toggled Whether the button is toggled
* @param backgroundColor Optional background color override (null to use theme defaults) * @param backgroundColor Optional background color override (null to use theme defaults)
* @param scaleFactor UI scale factor * @param scaleFactor UI scale factor
* @param theme Theme to use for colors * @param theme Theme to use for colors
*/ */
void drawCloseButton(Graphics2D g2d, int width, int height, boolean enabled, int state, Color backgroundColor, double scaleFactor, Theme theme); void drawCloseButton(Graphics2D g2d, int width, int height, boolean enabled, boolean pressed, boolean hovered, boolean toggled, Color backgroundColor, double scaleFactor, Theme theme);
/** /**
* Draws a background pattern for the UI on layer BACKGROUND1 * Draws a background pattern for the UI on layer BACKGROUND1
@@ -85,10 +87,12 @@ public interface PatternRenderer {
* @param width Width of the button * @param width Width of the button
* @param height Height of the button * @param height Height of the button
* @param enabled Whether the button is enabled * @param enabled Whether the button is enabled
* @param state Button state flags (normal, hovered, pressed, toggled) * @param pressed Whether the button is pressed
* @param hovered Whether the button is hovered
* @param toggled Whether the button is toggled
* @param backgroundColor Optional background color override (null to use theme defaults) * @param backgroundColor Optional background color override (null to use theme defaults)
* @param scaleFactor UI scale factor * @param scaleFactor UI scale factor
* @param theme Theme to use for colors * @param theme Theme to use for colors
*/ */
void drawButton(Graphics2D g2d, int x, int y, int width, int height, boolean enabled, int state, Color backgroundColor, double scaleFactor, Theme theme); void drawButton(Graphics2D g2d, int x, int y, int width, int height, boolean enabled, boolean pressed, boolean hovered, boolean toggled, Color backgroundColor, double scaleFactor, Theme theme);
} }

View File

@@ -64,13 +64,8 @@ public class SpacecraftPatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final var STATE_HOVERED = 4; final var highlight = (hovered || toggled);
final var STATE_TOGGLED = 1;
final var STATE_PRESSED = 2;
final var highlight = (state & (STATE_HOVERED | STATE_TOGGLED)) != 0;
final var pressed = (state & STATE_PRESSED) != 0;
Color bgColor = null; Color bgColor = null;
if (pressed) { if (pressed) {
@@ -165,23 +160,19 @@ public class SpacecraftPatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final int STATE_TOGGLED = 1;
final int STATE_PRESSED = 2;
final int STATE_HOVERED = 4;
float h, s, b; float h, s, b;
if (backgroundColor == null) { if (backgroundColor == null) {
final var baseColor = (state & STATE_TOGGLED) == 0 ? theme.getBackgroundNormal() : theme.getBackgroundSelected(); final var baseColor = !toggled ? theme.getBackgroundNormal() : theme.getBackgroundSelected();
h = baseColor.getHue(); h = baseColor.getHue();
s = baseColor.getSaturation(); s = baseColor.getSaturation();
b = baseColor.getBrightness(); b = baseColor.getBrightness();
if ((state & STATE_PRESSED) != 0) { if (pressed) {
b += theme.getPressedBrightnessAdjustment(); b += theme.getPressedBrightnessAdjustment();
} }
else if ((state & STATE_HOVERED) != 0) { else if (hovered) {
b += theme.getHoverBrightnessAdjustment(); b += theme.getHoverBrightnessAdjustment();
} }
} }
@@ -191,16 +182,16 @@ public class SpacecraftPatternRenderer implements PatternRenderer {
h = hsb[0]; h = hsb[0];
s = hsb[1]; s = hsb[1];
if ((state & STATE_TOGGLED) == 0) { if (!toggled) {
b = 0.30F; b = 0.30F;
} }
else { else {
b = 0.50F; b = 0.50F;
} }
if ((state & STATE_PRESSED) != 0) { if (pressed) {
b += theme.getPressedBrightnessAdjustment(); b += theme.getPressedBrightnessAdjustment();
} }
else if ((state & STATE_HOVERED) != 0) { else if (hovered) {
b += theme.getHoverBrightnessAdjustment(); b += theme.getHoverBrightnessAdjustment();
} }
} }
@@ -211,7 +202,7 @@ public class SpacecraftPatternRenderer implements PatternRenderer {
g2d.fillRect(x, y, width, height); g2d.fillRect(x, y, width, height);
final var borderStrength = Math.max(2, (int) (3 * scaleFactor)); final var borderStrength = Math.max(2, (int) (3 * scaleFactor));
final var borderColor = (state & STATE_HOVERED) != 0 ? theme.getSelectionPrimary().toColor() : final var borderColor = hovered ? theme.getSelectionPrimary().toColor() :
enabled ? theme.getBorderInner().toColor() : theme.getBorderInnerDisabled().toColor(); enabled ? theme.getBorderInner().toColor() : theme.getBorderInnerDisabled().toColor();
this.drawDecorativeBorder(g2d, x, y, width, height, borderStrength, borderColor); this.drawDecorativeBorder(g2d, x, y, width, height, borderStrength, borderColor);
} }

View File

@@ -85,13 +85,8 @@ public class SteampunkPatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final var STATE_HOVERED = 4; final var highlight = (hovered || toggled);
final var STATE_TOGGLED = 1;
final var STATE_PRESSED = 2;
final var highlight = (state & (STATE_HOVERED | STATE_TOGGLED)) != 0;
final var pressed = (state & STATE_PRESSED) != 0;
final var base = (backgroundColor != null) ? backgroundColor : theme.getBorderInner().toColor(); final var base = (backgroundColor != null) ? backgroundColor : theme.getBorderInner().toColor();
final var hsb = Color.RGBtoHSB(base.getRed(), base.getGreen(), base.getBlue(), null); final var hsb = Color.RGBtoHSB(base.getRed(), base.getGreen(), base.getBlue(), null);
@@ -196,27 +191,19 @@ public class SteampunkPatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final int STATE_TOGGLED = 1;
final int STATE_PRESSED = 2;
final int STATE_HOVERED = 4;
final boolean toggled = (state & STATE_TOGGLED) != 0;
final boolean pressed = (state & STATE_PRESSED) != 0;
final boolean hovered = (state & STATE_HOVERED) != 0;
float h, s, b; float h, s, b;
if (backgroundColor == null) { if (backgroundColor == null) {
final var baseColor = (state & STATE_TOGGLED) == 0 ? theme.getBackgroundNormal() : theme.getBackgroundSelected(); final var baseColor = !toggled ? theme.getBackgroundNormal() : theme.getBackgroundSelected();
h = baseColor.getHue(); h = baseColor.getHue();
s = baseColor.getSaturation(); s = baseColor.getSaturation();
b = baseColor.getBrightness(); b = baseColor.getBrightness();
if ((state & STATE_PRESSED) != 0) { if (pressed) {
b += theme.getPressedBrightnessAdjustment(); b += theme.getPressedBrightnessAdjustment();
} }
else if ((state & STATE_HOVERED) != 0) { else if (hovered) {
b += theme.getHoverBrightnessAdjustment(); b += theme.getHoverBrightnessAdjustment();
} }
} }
@@ -226,16 +213,16 @@ public class SteampunkPatternRenderer implements PatternRenderer {
h = hsb[0]; h = hsb[0];
s = hsb[1]; s = hsb[1];
if ((state & STATE_TOGGLED) == 0) { if (!toggled) {
b = 0.30F; b = 0.30F;
} }
else { else {
b = 0.50F; b = 0.50F;
} }
if ((state & STATE_PRESSED) != 0) { if (pressed) {
b += theme.getPressedBrightnessAdjustment(); b += theme.getPressedBrightnessAdjustment();
} }
else if ((state & STATE_HOVERED) != 0) { else if (hovered) {
b += theme.getHoverBrightnessAdjustment(); b += theme.getHoverBrightnessAdjustment();
} }
} }

View File

@@ -54,13 +54,8 @@ public class UrbanPatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final var STATE_HOVERED = 4; final var highlight = (hovered || toggled);
final var STATE_TOGGLED = 1;
final var STATE_PRESSED = 2;
final var highlight = (state & (STATE_HOVERED | STATE_TOGGLED)) != 0;
final var pressed = (state & STATE_PRESSED) != 0;
final var base = (backgroundColor != null) ? backgroundColor : theme.getBorderInner().toColor(); final var base = (backgroundColor != null) ? backgroundColor : theme.getBorderInner().toColor();
final var hsb = Color.RGBtoHSB(base.getRed(), base.getGreen(), base.getBlue(), null); final var hsb = Color.RGBtoHSB(base.getRed(), base.getGreen(), base.getBlue(), null);
@@ -124,27 +119,19 @@ public class UrbanPatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final int STATE_TOGGLED = 1;
final int STATE_PRESSED = 2;
final int STATE_HOVERED = 4;
final boolean toggled = (state & STATE_TOGGLED) != 0;
final boolean pressed = (state & STATE_PRESSED) != 0;
final boolean hovered = (state & STATE_HOVERED) != 0;
float h, s, b; float h, s, b;
if (backgroundColor == null) { if (backgroundColor == null) {
final var baseColor = (state & STATE_TOGGLED) == 0 ? theme.getBackgroundNormal() : theme.getBackgroundSelected(); final var baseColor = !toggled ? theme.getBackgroundNormal() : theme.getBackgroundSelected();
h = baseColor.getHue(); h = baseColor.getHue();
s = baseColor.getSaturation(); s = baseColor.getSaturation();
b = baseColor.getBrightness(); b = baseColor.getBrightness();
if ((state & STATE_PRESSED) != 0) { if (pressed) {
b += theme.getPressedBrightnessAdjustment(); b += theme.getPressedBrightnessAdjustment();
} }
else if ((state & STATE_HOVERED) != 0) { else if (hovered) {
b += theme.getHoverBrightnessAdjustment(); b += theme.getHoverBrightnessAdjustment();
} }
} }
@@ -154,16 +141,16 @@ public class UrbanPatternRenderer implements PatternRenderer {
h = hsb[0]; h = hsb[0];
s = hsb[1]; s = hsb[1];
if ((state & STATE_TOGGLED) == 0) { if (!toggled) {
b = 0.30F; b = 0.30F;
} }
else { else {
b = 0.50F; b = 0.50F;
} }
if ((state & STATE_PRESSED) != 0) { if (pressed) {
b += theme.getPressedBrightnessAdjustment(); b += theme.getPressedBrightnessAdjustment();
} }
else if ((state & STATE_HOVERED) != 0) { else if (hovered) {
b += theme.getHoverBrightnessAdjustment(); b += theme.getHoverBrightnessAdjustment();
} }
} }

View File

@@ -87,13 +87,8 @@ public class VintagePatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawCloseButton(final Graphics2D g2d, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final var STATE_HOVERED = 4; final var highlight = (hovered || toggled);
final var STATE_TOGGLED = 1;
final var STATE_PRESSED = 2;
final var highlight = (state & (STATE_HOVERED | STATE_TOGGLED)) != 0;
final var pressed = (state & STATE_PRESSED) != 0;
final var size = Math.max(2, (int) (3 * scaleFactor)); final var size = Math.max(2, (int) (3 * scaleFactor));
@@ -167,27 +162,19 @@ public class VintagePatternRenderer implements PatternRenderer {
} }
@Override @Override
public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final int state, final Color backgroundColor, final double scaleFactor, final Theme theme) { public void drawButton(final Graphics2D g2d, final int x, final int y, final int width, final int height, final boolean enabled, final boolean pressed, final boolean hovered, final boolean toggled, final Color backgroundColor, final double scaleFactor, final Theme theme) {
final int STATE_TOGGLED = 1;
final int STATE_PRESSED = 2;
final int STATE_HOVERED = 4;
final boolean toggled = (state & STATE_TOGGLED) != 0;
final boolean pressed = (state & STATE_PRESSED) != 0;
final boolean hovered = (state & STATE_HOVERED) != 0;
float h, s, b; float h, s, b;
if (backgroundColor == null) { if (backgroundColor == null) {
final var baseColor = (state & STATE_TOGGLED) == 0 ? theme.getBackgroundNormal() : theme.getBackgroundSelected(); final var baseColor = !toggled ? theme.getBackgroundNormal() : theme.getBackgroundSelected();
h = baseColor.getHue(); h = baseColor.getHue();
s = baseColor.getSaturation(); s = baseColor.getSaturation();
b = baseColor.getBrightness(); b = baseColor.getBrightness();
if ((state & STATE_PRESSED) != 0) { if (pressed) {
b += theme.getPressedBrightnessAdjustment(); b += theme.getPressedBrightnessAdjustment();
} }
else if ((state & STATE_HOVERED) != 0) { else if (hovered) {
b += theme.getHoverBrightnessAdjustment(); b += theme.getHoverBrightnessAdjustment();
} }
} }
@@ -197,16 +184,16 @@ public class VintagePatternRenderer implements PatternRenderer {
h = hsb[0]; h = hsb[0];
s = hsb[1]; s = hsb[1];
if ((state & STATE_TOGGLED) == 0) { if (!toggled) {
b = 0.30F; b = 0.30F;
} }
else { else {
b = 0.50F; b = 0.50F;
} }
if ((state & STATE_PRESSED) != 0) { if (pressed) {
b += theme.getPressedBrightnessAdjustment(); b += theme.getPressedBrightnessAdjustment();
} }
else if ((state & STATE_HOVERED) != 0) { else if (hovered) {
b += theme.getHoverBrightnessAdjustment(); b += theme.getHoverBrightnessAdjustment();
} }
} }