feat(renderer): enhance button rendering with gradient effects and improved state handling across pattern renderers
This commit is contained in:
@@ -70,10 +70,10 @@ public class CustomSwitch extends CustomAbstractButton {
|
||||
if (patternRenderer != null) {
|
||||
patternRenderer.drawDecorativeBorder(g2d, 0, 0, this.getWidth() - 1, this.getHeight() - 1, 2, borderColor1);
|
||||
|
||||
final var borderColor2 = this.isEnabled() ?
|
||||
(this.state & STATE_HOVERED) != 0 ? theme.getSelectionSecondary().toColor() : theme.getBorderInner().toColor() :
|
||||
theme.getBorderInnerDisabled().toColor();
|
||||
patternRenderer.drawDecorativeBorder(g2d, 2, 2, this.getWidth() - 5, this.getHeight() - 5, 2, borderColor2);
|
||||
// final var borderColor2 = this.isEnabled() ?
|
||||
// (this.state & STATE_HOVERED) != 0 ? theme.getSelectionSecondary().toColor() : theme.getBorderInner().toColor() :
|
||||
// theme.getBorderInnerDisabled().toColor();
|
||||
// patternRenderer.drawDecorativeBorder(g2d, 2, 2, this.getWidth() - 5, this.getHeight() - 5, 2, borderColor2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,9 +98,9 @@ public class DreamPatternRenderer implements PatternRenderer {
|
||||
final var textDim = G2DDrawFont.getTextDimensions("X", g2d, 15, scaleFactor);
|
||||
G2DDrawFont.renderText(g2d, textDim, 1.0, ((width - textDim.getX()) / 2), ((height - textDim.getY()) / 2), fontSize, "X");
|
||||
}
|
||||
|
||||
|
||||
private java.awt.image.BufferedImage patternCache;
|
||||
|
||||
|
||||
private java.awt.image.BufferedImage getPatternCache() {
|
||||
if (this.patternCache == null) {
|
||||
final int cellSize = 100;
|
||||
@@ -120,7 +120,7 @@ public class DreamPatternRenderer implements PatternRenderer {
|
||||
}
|
||||
return this.patternCache;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawBackgroundPattern(final Graphics2D g2d, final CoordI2 offset, final CoordI2 viewPort) {
|
||||
final var cache = this.getPatternCache();
|
||||
@@ -135,13 +135,17 @@ public class DreamPatternRenderer implements PatternRenderer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@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) {
|
||||
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;
|
||||
|
||||
if (backgroundColor == null) {
|
||||
@@ -184,31 +188,36 @@ public class DreamPatternRenderer implements PatternRenderer {
|
||||
final var arc = Math.max(6, (int) (10 * scaleFactor));
|
||||
g2d.setColor(bgColor2);
|
||||
g2d.fillRoundRect(x, y, width, height, arc, arc);
|
||||
// Add vertical gradient overlay for depth
|
||||
|
||||
// Add vertical gradient overlay for depth
|
||||
if (height > 20) {
|
||||
final var gradientColor = new Color(255, 255, 255, 20);
|
||||
for (int i = 0; i < height / 3; i++) {
|
||||
g2d.setColor(new Color(255, 255, 255, (int) (20 - (i * 20.0 / (height / 3)))));
|
||||
g2d.fillRect(x + arc / 2, y + i, width - arc, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Add dreamy bubble decorations for toggled buttons
|
||||
if ((state & STATE_TOGGLED) != 0 && width > 35 && height > 35) {
|
||||
if (toggled && width > 35 && height > 35) {
|
||||
g2d.setColor(new Color(255, 255, 255, 80));
|
||||
g2d.fillOval(x + width / 4, y + height / 4, 5, 5);
|
||||
g2d.fillOval(x + width * 2 / 3, y + height / 3, 3, 3);
|
||||
g2d.fillOval(x + width / 3, y + height * 2 / 3, 4, 4);
|
||||
}
|
||||
|
||||
// Add soft shimmer effect when hovered
|
||||
if ((state & STATE_HOVERED) != 0) {
|
||||
g2d.setColor(new Color(255, 255, 255, 30));
|
||||
g2d.fillRoundRect(x + 2, y + 2, width - 4, height / 2, arc, arc);
|
||||
int shimmerAlpha = hovered ? 30 : 18;
|
||||
if (pressed) {
|
||||
shimmerAlpha = 12;
|
||||
}
|
||||
final var borderStrength = Math.max(1, (int) (2 * scaleFactor));
|
||||
final var borderColor = (state & STATE_HOVERED) != 0 ? theme.getSelectionPrimary().toColor() :
|
||||
enabled ? theme.getBorderInner().toColor() : theme.getBorderInnerDisabled().toColor();
|
||||
if (!enabled) {
|
||||
shimmerAlpha = 8;
|
||||
}
|
||||
if (shimmerAlpha > 0 && width > 8 && height > 8) {
|
||||
g2d.setColor(new Color(255, 255, 255, shimmerAlpha));
|
||||
final int shimmerHeight = hovered ? height / 2 : Math.max(3, height / 3);
|
||||
g2d.fillRoundRect(x + 2, y + 2, width - 4, shimmerHeight, arc, arc);
|
||||
}
|
||||
final var borderStrength = Math.max(1, (int) (2 * scaleFactor));
|
||||
final var borderColor = hovered ? theme.getSelectionPrimary().toColor() : enabled ? theme.getBorderOuter().toColor() : theme.getBorderInnerDisabled().toColor();
|
||||
this.drawDecorativeBorder(g2d, x, y, width, height, borderStrength, borderColor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.extio.game_engine.renderer.g2d.theme;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.GradientPaint;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
@@ -150,6 +151,10 @@ public class FantasyPatternRenderer implements PatternRenderer {
|
||||
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;
|
||||
|
||||
if (backgroundColor == null) {
|
||||
@@ -186,13 +191,59 @@ public class FantasyPatternRenderer implements PatternRenderer {
|
||||
}
|
||||
|
||||
b = Math.max(0.0f, Math.min(1.0f, b));
|
||||
final var bgColor = Color.getHSBColor(h, s, b);
|
||||
g2d.setColor(bgColor);
|
||||
Color bgColor = Color.getHSBColor(h, s, b);
|
||||
if (!enabled) {
|
||||
final var hsb = Color.RGBtoHSB(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), null);
|
||||
bgColor = Color.getHSBColor(hsb[0], Math.min(1.0f, hsb[1] * 0.18f), Math.min(1.0f, hsb[2] * 0.55f));
|
||||
}
|
||||
|
||||
final var bgHsb = Color.RGBtoHSB(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), null);
|
||||
final float topB = pressed ? Math.max(0.0f, bgHsb[2] - 0.12f) : Math.min(1.0f, bgHsb[2] + 0.14f);
|
||||
final float bottomB = pressed ? Math.min(1.0f, bgHsb[2] + 0.05f) : Math.max(0.0f, bgHsb[2] - 0.11f);
|
||||
final var top = Color.getHSBColor(bgHsb[0], Math.min(1.0f, bgHsb[1] * 0.95f), topB);
|
||||
final var bottom = Color.getHSBColor(bgHsb[0], bgHsb[1], bottomB);
|
||||
|
||||
final var oldPaint = g2d.getPaint();
|
||||
g2d.setPaint(new GradientPaint(x, y, top, x, y + height, bottom));
|
||||
g2d.fillRect(x, y, width, height);
|
||||
g2d.setPaint(oldPaint);
|
||||
|
||||
final var t = Math.max(1, (int) (1 * scaleFactor));
|
||||
final var shine = new Color(255, 255, 255, pressed ? 16 : 44);
|
||||
g2d.setColor(shine);
|
||||
g2d.fillRect(x + t, y + t, Math.max(0, width - t * 2), Math.max(0, t));
|
||||
|
||||
final var sparkleBase = hovered || toggled ? theme.getSelectionSecondary().toColor() : theme.getBorderOuter().toColor();
|
||||
final var sparkle = new Color(sparkleBase.getRed(), sparkleBase.getGreen(), sparkleBase.getBlue(), pressed ? 45 : 70);
|
||||
g2d.setColor(sparkle);
|
||||
final int px1 = x + (width / 3);
|
||||
final int py1 = y + (height / 3);
|
||||
final int px2 = x + (width * 2 / 3);
|
||||
final int py2 = y + (height * 2 / 3);
|
||||
final int dot = Math.max(1, (int) (2 * scaleFactor));
|
||||
if (width >= 16 && height >= 12) {
|
||||
g2d.fillRect(px1, py1, dot, dot);
|
||||
g2d.fillRect(px2, py1 + dot, dot, dot);
|
||||
g2d.fillRect(px1 + dot, py2, dot, dot);
|
||||
}
|
||||
|
||||
final var borderStrength = Math.max(1, (int) (2 * scaleFactor));
|
||||
final var borderColor = (state & STATE_HOVERED) != 0 ? theme.getSelectionPrimary().toColor() :
|
||||
enabled ? theme.getBorderInner().toColor() : theme.getBorderInnerDisabled().toColor();
|
||||
this.drawDecorativeBorder(g2d, x, y, width, height, borderStrength, borderColor);
|
||||
final var outerBorderColor = hovered ? theme.getSelectionPrimary().toColor() : (toggled ? theme.getSelectionSecondary().toColor() : theme.getBorderOuter().toColor());
|
||||
final var innerBorderColor = enabled ? theme.getBorderInner().toColor() : theme.getBorderInnerDisabled().toColor();
|
||||
this.drawDecorativeBorder(g2d, x, y, width, height, borderStrength, outerBorderColor);
|
||||
final var inset = Math.max(1, borderStrength);
|
||||
if (width > inset * 4 && height > inset * 4) {
|
||||
this.drawDecorativeBorder(g2d, x + inset, y + inset, width - inset * 2, height - inset * 2, Math.max(1, borderStrength / 2), innerBorderColor);
|
||||
}
|
||||
|
||||
if (hovered || toggled) {
|
||||
final var gemBase = theme.getSelectionPrimary().toColor();
|
||||
final var gem = new Color(gemBase.getRed(), gemBase.getGreen(), gemBase.getBlue(), pressed ? 70 : 110);
|
||||
g2d.setColor(gem);
|
||||
final int cx = x + width / 2;
|
||||
final int cy = y + Math.max(6, (int) (8 * scaleFactor));
|
||||
final int r = Math.max(3, (int) (4 * scaleFactor));
|
||||
g2d.fillPolygon(new int[] { cx, cx + r, cx, cx - r }, new int[] { cy - r, cy, cy + r, cy }, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.extio.game_engine.renderer.g2d.theme;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.GradientPaint;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
@@ -152,6 +153,10 @@ public class MetroPatternRenderer implements PatternRenderer {
|
||||
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;
|
||||
|
||||
if (backgroundColor == null) {
|
||||
@@ -188,13 +193,44 @@ public class MetroPatternRenderer implements PatternRenderer {
|
||||
}
|
||||
|
||||
b = Math.max(0.0f, Math.min(1.0f, b));
|
||||
final var bgColor = Color.getHSBColor(h, s, b);
|
||||
g2d.setColor(bgColor);
|
||||
Color bgColor = Color.getHSBColor(h, s, b);
|
||||
if (!enabled) {
|
||||
final var hsb = Color.RGBtoHSB(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), null);
|
||||
bgColor = Color.getHSBColor(hsb[0], Math.min(1.0f, hsb[1] * 0.20f), Math.min(1.0f, hsb[2] * 0.60f));
|
||||
}
|
||||
|
||||
final var bgHsb = Color.RGBtoHSB(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), null);
|
||||
final float topB = pressed ? Math.max(0.0f, bgHsb[2] - 0.10f) : Math.min(1.0f, bgHsb[2] + 0.10f);
|
||||
final float bottomB = pressed ? Math.min(1.0f, bgHsb[2] + 0.04f) : Math.max(0.0f, bgHsb[2] - 0.10f);
|
||||
final var top = Color.getHSBColor(bgHsb[0], bgHsb[1], topB);
|
||||
final var bottom = Color.getHSBColor(bgHsb[0], bgHsb[1], bottomB);
|
||||
|
||||
final var oldPaint = g2d.getPaint();
|
||||
g2d.setPaint(new GradientPaint(x, y, top, x, y + height, bottom));
|
||||
g2d.fillRect(x, y, width, height);
|
||||
g2d.setPaint(oldPaint);
|
||||
|
||||
final var borderStrength = Math.max(1, (int) (2 * scaleFactor));
|
||||
final var borderColor = (state & STATE_HOVERED) != 0 ? theme.getSelectionPrimary().toColor() :
|
||||
enabled ? theme.getBorderInner().toColor() : theme.getBorderInnerDisabled().toColor();
|
||||
this.drawDecorativeBordersMain(g2d, x, y, width, height, borderStrength, width >= 48 && height >= 48, borderColor);
|
||||
final var outerBorderColor = hovered ? theme.getSelectionPrimary().toColor() : theme.getBorderOuter().toColor();
|
||||
final var innerBorderColor = enabled ? theme.getBorderInner().toColor() : theme.getBorderInnerDisabled().toColor();
|
||||
this.drawDecorativeBordersMain(g2d, x, y, width, height, borderStrength, false, outerBorderColor);
|
||||
final var inset = Math.max(1, borderStrength);
|
||||
if (width > inset * 3 && height > inset * 3) {
|
||||
this.drawDecorativeBordersMain(g2d, x + inset, y + inset, width - inset * 2, height - inset * 2, Math.max(1, borderStrength / 2), false, innerBorderColor);
|
||||
}
|
||||
|
||||
final int routeT = Math.max(1, (int) (2 * scaleFactor));
|
||||
final int pad = Math.max(4, (int) (6 * scaleFactor));
|
||||
final int cy = y + height - pad;
|
||||
final var routeBase = pressed ? theme.getSelectionSecondary().toColor() : (hovered || toggled ? theme.getSelectionPrimary().toColor() : theme.getBorderOuter().toColor());
|
||||
final var route = new Color(routeBase.getRed(), routeBase.getGreen(), routeBase.getBlue(), enabled ? (pressed ? 150 : 200) : 80);
|
||||
g2d.setColor(route);
|
||||
g2d.fillRect(x + pad, cy - routeT / 2, Math.max(0, width - pad * 2), routeT);
|
||||
|
||||
final int station = Math.max(5, (int) (7 * scaleFactor));
|
||||
if (width >= pad * 2 + station * 2 && height >= station + 2) {
|
||||
g2d.fillOval(x + pad, cy - station / 2, station, station);
|
||||
g2d.fillOval(x + width - pad - station, cy - station / 2, station, station);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.extio.game_engine.renderer.g2d.theme;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.GradientPaint;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
@@ -143,6 +144,10 @@ public class ModernPatternRenderer implements PatternRenderer {
|
||||
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;
|
||||
|
||||
if (backgroundColor == null) {
|
||||
@@ -179,13 +184,46 @@ public class ModernPatternRenderer implements PatternRenderer {
|
||||
}
|
||||
|
||||
b = Math.max(0.0f, Math.min(1.0f, b));
|
||||
final var bgColor = Color.getHSBColor(h, s, b);
|
||||
g2d.setColor(bgColor);
|
||||
Color bgColor = Color.getHSBColor(h, s, b);
|
||||
if (!enabled) {
|
||||
final var hsb = Color.RGBtoHSB(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), null);
|
||||
bgColor = Color.getHSBColor(hsb[0], Math.min(1.0f, hsb[1] * 0.15f), Math.min(1.0f, hsb[2] * 0.55f));
|
||||
}
|
||||
|
||||
final var bgHsb = Color.RGBtoHSB(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), null);
|
||||
final float topB = pressed ? Math.max(0.0f, bgHsb[2] - 0.12f) : Math.min(1.0f, bgHsb[2] + 0.12f);
|
||||
final float bottomB = pressed ? Math.min(1.0f, bgHsb[2] + 0.05f) : Math.max(0.0f, bgHsb[2] - 0.10f);
|
||||
final var top = Color.getHSBColor(bgHsb[0], bgHsb[1], topB);
|
||||
final var bottom = Color.getHSBColor(bgHsb[0], bgHsb[1], bottomB);
|
||||
|
||||
final var oldPaint = g2d.getPaint();
|
||||
g2d.setPaint(new GradientPaint(x, y, top, x, y + height, bottom));
|
||||
g2d.fillRect(x, y, width, height);
|
||||
g2d.setPaint(oldPaint);
|
||||
|
||||
final var accentBase = hovered || toggled ? theme.getSelectionPrimary().toColor() : theme.getSelectionSecondary().toColor();
|
||||
final var accent = new Color(accentBase.getRed(), accentBase.getGreen(), accentBase.getBlue(), pressed ? 70 : 110);
|
||||
final var shine = new Color(255, 255, 255, pressed ? 18 : 40);
|
||||
final var shadow = new Color(0, 0, 0, pressed ? 40 : 60);
|
||||
|
||||
final var t = Math.max(1, (int) (1 * scaleFactor));
|
||||
g2d.setColor(shine);
|
||||
g2d.fillRect(x + t, y + t, Math.max(0, width - t * 2), Math.max(0, t));
|
||||
g2d.setColor(shadow);
|
||||
g2d.fillRect(x + t, y + height - t * 2, Math.max(0, width - t * 2), Math.max(0, t));
|
||||
|
||||
if (hovered || toggled) {
|
||||
g2d.setColor(accent);
|
||||
g2d.fillRect(x + t, y + t, Math.max(0, width - t * 2), Math.max(0, t));
|
||||
}
|
||||
|
||||
final var borderStrength = Math.max(1, (int) (2 * scaleFactor));
|
||||
final var borderColor = (state & STATE_HOVERED) != 0 ? theme.getSelectionPrimary().toColor() :
|
||||
enabled ? theme.getBorderInner().toColor() : theme.getBorderInnerDisabled().toColor();
|
||||
this.drawDecorativeBorder(g2d, x, y, width, height, borderStrength, borderColor);
|
||||
final var outerBorderColor = hovered ? theme.getSelectionPrimary().toColor() : theme.getBorderOuter().toColor();
|
||||
final var innerBorderColor = enabled ? theme.getBorderInner().toColor() : theme.getBorderInnerDisabled().toColor();
|
||||
this.drawDecorativeBorder(g2d, x, y, width, height, borderStrength, outerBorderColor);
|
||||
final var inset = Math.max(1, borderStrength);
|
||||
if (width > inset * 3 && height > inset * 3) {
|
||||
this.drawDecorativeBorder(g2d, x + inset, y + inset, width - inset * 2, height - inset * 2, Math.max(1, borderStrength / 2), innerBorderColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.extio.game_engine.renderer.g2d.theme;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.GradientPaint;
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
import org.springframework.context.annotation.Conditional;
|
||||
@@ -134,6 +135,10 @@ public class UrbanPatternRenderer implements PatternRenderer {
|
||||
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;
|
||||
|
||||
if (backgroundColor == null) {
|
||||
@@ -170,13 +175,47 @@ public class UrbanPatternRenderer implements PatternRenderer {
|
||||
}
|
||||
|
||||
b = Math.max(0.0f, Math.min(1.0f, b));
|
||||
final var bgColor = Color.getHSBColor(h, s, b);
|
||||
g2d.setColor(bgColor);
|
||||
Color bgColor = Color.getHSBColor(h, s, b);
|
||||
if (!enabled) {
|
||||
final var hsb = Color.RGBtoHSB(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), null);
|
||||
bgColor = Color.getHSBColor(hsb[0], Math.min(1.0f, hsb[1] * 0.20f), Math.min(1.0f, hsb[2] * 0.55f));
|
||||
}
|
||||
|
||||
final var bgHsb = Color.RGBtoHSB(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), null);
|
||||
final float topB = pressed ? Math.max(0.0f, bgHsb[2] - 0.10f) : Math.min(1.0f, bgHsb[2] + 0.10f);
|
||||
final float bottomB = pressed ? Math.min(1.0f, bgHsb[2] + 0.04f) : Math.max(0.0f, bgHsb[2] - 0.12f);
|
||||
final var top = Color.getHSBColor(bgHsb[0], bgHsb[1], topB);
|
||||
final var bottom = Color.getHSBColor(bgHsb[0], bgHsb[1], bottomB);
|
||||
|
||||
final var oldPaint = g2d.getPaint();
|
||||
g2d.setPaint(new GradientPaint(x, y, top, x, y + height, bottom));
|
||||
g2d.fillRect(x, y, width, height);
|
||||
g2d.setPaint(oldPaint);
|
||||
|
||||
final var t = Math.max(1, (int) (1 * scaleFactor));
|
||||
final var hatchBase = theme.getBorderOuter().toColor();
|
||||
final var hatch = new Color(hatchBase.getRed(), hatchBase.getGreen(), hatchBase.getBlue(), pressed ? 28 : 38);
|
||||
g2d.setColor(hatch);
|
||||
final int step = Math.max(10, (int) (14 * scaleFactor));
|
||||
for (int i = x - height; i < x + width + height; i += step) {
|
||||
g2d.drawLine(i, y, i + height, y + height);
|
||||
}
|
||||
|
||||
if (hovered || toggled) {
|
||||
final var accentBase = theme.getSelectionPrimary().toColor();
|
||||
final var accent = new Color(accentBase.getRed(), accentBase.getGreen(), accentBase.getBlue(), pressed ? 110 : 150);
|
||||
g2d.setColor(accent);
|
||||
final int stripe = Math.max(2, (int) (4 * scaleFactor));
|
||||
g2d.fillRect(x + t, y + t, stripe, Math.max(0, height - t * 2));
|
||||
}
|
||||
|
||||
final var borderStrength = Math.max(1, (int) (2 * scaleFactor));
|
||||
final var borderColor = (state & STATE_HOVERED) != 0 ? theme.getSelectionPrimary().toColor() :
|
||||
enabled ? theme.getBorderInner().toColor() : theme.getBorderInnerDisabled().toColor();
|
||||
this.drawDecorativeBorder(g2d, x, y, width, height, borderStrength, borderColor);
|
||||
final var outerBorderColor = hovered ? theme.getSelectionPrimary().toColor() : theme.getBorderOuter().toColor();
|
||||
final var innerBorderColor = enabled ? theme.getBorderInner().toColor() : theme.getBorderInnerDisabled().toColor();
|
||||
this.drawDecorativeBorder(g2d, x, y, width, height, borderStrength, outerBorderColor);
|
||||
final var inset = Math.max(1, borderStrength);
|
||||
if (width > inset * 3 && height > inset * 3) {
|
||||
this.drawDecorativeBorder(g2d, x + inset, y + inset, width - inset * 2, height - inset * 2, Math.max(1, borderStrength / 2), innerBorderColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.extio.game_engine.renderer.g2d.theme;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.GradientPaint;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
@@ -176,6 +177,10 @@ public class VintagePatternRenderer implements PatternRenderer {
|
||||
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;
|
||||
|
||||
if (backgroundColor == null) {
|
||||
@@ -212,15 +217,46 @@ public class VintagePatternRenderer implements PatternRenderer {
|
||||
}
|
||||
|
||||
b = Math.max(0.0f, Math.min(1.0f, b));
|
||||
final var bgColor = Color.getHSBColor(h, s, b);
|
||||
g2d.setColor(bgColor);
|
||||
g2d.fillRect(x, y + 1, width, height - 3);
|
||||
g2d.fillRect(x + 1, y + height - 2, width - 2, 1);
|
||||
Color bgColor = Color.getHSBColor(h, s, b);
|
||||
if (!enabled) {
|
||||
final var hsb = Color.RGBtoHSB(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), null);
|
||||
bgColor = Color.getHSBColor(hsb[0], Math.min(1.0f, hsb[1] * 0.15f), Math.min(1.0f, hsb[2] * 0.55f));
|
||||
}
|
||||
|
||||
final var bgHsb = Color.RGBtoHSB(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), null);
|
||||
final float topB = pressed ? Math.max(0.0f, bgHsb[2] - 0.12f) : Math.min(1.0f, bgHsb[2] + 0.12f);
|
||||
final float bottomB = pressed ? Math.min(1.0f, bgHsb[2] + 0.04f) : Math.max(0.0f, bgHsb[2] - 0.12f);
|
||||
final var top = Color.getHSBColor(bgHsb[0], bgHsb[1], topB);
|
||||
final var bottom = Color.getHSBColor(bgHsb[0], bgHsb[1], bottomB);
|
||||
|
||||
final var oldPaint = g2d.getPaint();
|
||||
g2d.setPaint(new GradientPaint(x, y, top, x, y + height, bottom));
|
||||
g2d.fillRect(x, y, width, height);
|
||||
g2d.setPaint(oldPaint);
|
||||
|
||||
final var t = Math.max(1, (int) (1 * scaleFactor));
|
||||
final var shine = new Color(255, 255, 255, pressed ? 14 : 40);
|
||||
final var baseShadow = new Color(0, 0, 0, pressed ? 50 : 70);
|
||||
g2d.setColor(shine);
|
||||
g2d.fillRect(x + t, y + t, Math.max(0, width - t * 2), Math.max(0, t));
|
||||
g2d.setColor(baseShadow);
|
||||
g2d.fillRect(x + t, y + height - t * 2, Math.max(0, width - t * 2), Math.max(0, t));
|
||||
|
||||
if (hovered || toggled) {
|
||||
final var glowBase = theme.getSelectionPrimary().toColor();
|
||||
final var glow = new Color(glowBase.getRed(), glowBase.getGreen(), glowBase.getBlue(), pressed ? 70 : 110);
|
||||
g2d.setColor(glow);
|
||||
g2d.fillRect(x + t, y + t, Math.max(0, width - t * 2), Math.max(0, t));
|
||||
}
|
||||
|
||||
final var borderStrength = Math.max(1, (int) (2 * scaleFactor));
|
||||
final var borderColor = (state & STATE_HOVERED) != 0 ? theme.getSelectionPrimary().toColor() :
|
||||
enabled ? theme.getBorderInner().toColor() : theme.getBorderInnerDisabled().toColor();
|
||||
this.drawDecorativeBorder(g2d, x, y, width, height, borderStrength, borderColor);
|
||||
final var outerBorderColor = hovered ? theme.getSelectionPrimary().toColor() : theme.getBorderOuter().toColor();
|
||||
final var innerBorderColor = enabled ? theme.getBorderInner().toColor() : theme.getBorderInnerDisabled().toColor();
|
||||
this.drawDecorativeBorder(g2d, x, y, width, height, borderStrength, outerBorderColor);
|
||||
final var inset = Math.max(1, borderStrength);
|
||||
if (width > inset * 3 && height > inset * 3) {
|
||||
this.drawDecorativeBorder(g2d, x + inset, y + inset, width - inset * 2, height - inset * 2, Math.max(1, borderStrength / 2), innerBorderColor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user