[Feat] Enable color

This commit is contained in:
xiaozhou233 committed 2026-01-18 19:58:52 +08:00
1 parent 20dcc72c92
commit 5beb4a25f3
3 files changed
+45 -5

No files matched your search

@@ -7,7 +7,7 @@ public abstract class Component {
@Setter
protected double x, y;
@Getter
@Getter @Setter
protected double width, height;
protected Component parent;
@@ -28,26 +28,43 @@ public class ModuleButton extends Component {
double ax = getAbsoluteX();
double ay = getAbsoluteY();
int bgColor = 0x80000000;
if (module.isEnabled()) {
bgColor = 0xFF2E8B57;
}
if (isHovered(mouseX, mouseY)) {
bgColor = GuiRenderUtils.blendColor(bgColor, 0xFFFFFFFF, 0.15f);
}
// draw background
GuiRenderUtils.enableBlend();
GuiRenderUtils.drawRect(ax, ay, width, baseHeight, 0x80000000);
GuiRenderUtils.drawRect(ax, ay, width, baseHeight, bgColor);
// draw status bar (left)
int statusColor = module.isEnabled() ? 0xFF00FF00 : 0xFF888888;
GuiRenderUtils.drawRect(ax, ay, 2, baseHeight, statusColor);
// draw module name
GuiRenderUtils.drawString(module.getName(), ax + 4, ay + 3, 0xFFFFFFFF);
GuiRenderUtils.drawString(module.getName(), ax + 6, ay + 3, 0xFFFFFFFF);
GuiRenderUtils.disableBlend();
if (!expanded) return;
if (!expanded) {
this.height = baseHeight;
return;
}
double offsetY = baseHeight;
for (Component component : components) {
component.setY(offsetY);
component.setWidth(width); // ensure same width
component.render(mouseX, mouseY, partialTicks);
offsetY += component.getHeight();
}
this.height = offsetY;
}
@Override
public void update(int mouseX, int mouseY) {
if (!expanded) return;
@@ -32,4 +32,27 @@ public class GuiRenderUtils {
public static void disableBlend() {
GL11.glDisable(GL11.GL_BLEND);
}
public static int blendColor(int color1, int color2, float ratio) {
if (ratio <= 0f) return color1;
if (ratio >= 1f) return color2;
int a1 = (color1 >> 24) & 0xFF;
int r1 = (color1 >> 16) & 0xFF;
int g1 = (color1 >> 8) & 0xFF;
int b1 = color1 & 0xFF;
int a2 = (color2 >> 24) & 0xFF;
int r2 = (color2 >> 16) & 0xFF;
int g2 = (color2 >> 8) & 0xFF;
int b2 = color2 & 0xFF;
int a = (int) (a1 + (a2 - a1) * ratio);
int r = (int) (r1 + (r2 - r1) * ratio);
int g = (int) (g1 + (g2 - g1) * ratio);
int b = (int) (b1 + (b2 - b1) * ratio);
return (a << 24) | (r << 16) | (g << 8) | b;
}
}