From a8e96b5355e074adc066db28fc64062893da2608 Mon Sep 17 00:00:00 2001 From: lukflug Date: Wed, 14 Apr 2021 13:45:50 +0200 Subject: [PATCH] Added doctor swag theme --- README.md | 4 +- build.gradle | 2 +- .../theme/DoctorSwagRainbowTheme.java | 151 ++++++++++++++++++ 3 files changed, 154 insertions(+), 3 deletions(-) create mode 100644 panelstudio/src/main/java/com/lukflug/panelstudio/theme/DoctorSwagRainbowTheme.java diff --git a/README.md b/README.md index 8ffc47d..f9c0129 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ repositories { } dependencies { - compile('com.lukflug:panelstudio:0.1.8') + compile('com.lukflug:panelstudio:0.1.11') } shadowJar { @@ -204,7 +204,7 @@ Toggleable hudToggle=new Toggleable() { ``` ## Reference -For a list of classes and methods, consult the [javadoc](https://lukflug.github.io/javadoc/panelstudio/0.1.10/overview-summary.html). For an example implementation, consult the GameSense source code. +For a list of classes and methods, consult the [javadoc](https://lukflug.github.io/javadoc/panelstudio/0.1.11/overview-summary.html). For an example implementation, consult the GameSense source code. ## Creating custom themes The components provided by PanelStudio use the methods in the `Renderer` interface to render. A `Theme` consist of three renderers: one for the single components (settings), one for the containers (modules) and one for the panels (categories). To see how themes are implemented, consult the package `com.lukflug.panelstudio.theme`. diff --git a/build.gradle b/build.gradle index 644e67a..8d4e8e9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ allprojects { group = "com.lukflug" - version = "0.1.10" + version = "0.1.11" } subprojects { diff --git a/panelstudio/src/main/java/com/lukflug/panelstudio/theme/DoctorSwagRainbowTheme.java b/panelstudio/src/main/java/com/lukflug/panelstudio/theme/DoctorSwagRainbowTheme.java new file mode 100644 index 0000000..83785d4 --- /dev/null +++ b/panelstudio/src/main/java/com/lukflug/panelstudio/theme/DoctorSwagRainbowTheme.java @@ -0,0 +1,151 @@ +package com.lukflug.panelstudio.theme; + +import java.awt.Color; +import java.awt.Point; +import java.awt.Rectangle; +import java.util.function.Supplier; + +import com.lukflug.panelstudio.Context; + +/** + * Theme made on commission for doctor swag#2624. + * @author lukflug + */ +public class DoctorSwagRainbowTheme implements Theme { + protected ColorScheme scheme; + protected Renderer componentRenderer,containerRenderer,panelRenderer; + protected Supplier ignoreDisabled,buttonRainbow; + + public DoctorSwagRainbowTheme (ColorScheme scheme, int height, Supplier ignoreDisabled, Supplier buttonRainbow) { + this.scheme=scheme; + panelRenderer=new ComponentRenderer(0,height,0); + containerRenderer=new ComponentRenderer(1,height,0); + componentRenderer=new ComponentRenderer(2,height,0); + this.ignoreDisabled=ignoreDisabled; + this.buttonRainbow=buttonRainbow; + } + + @Override + public Renderer getPanelRenderer() { + return panelRenderer; + } + + @Override + public Renderer getContainerRenderer() { + return containerRenderer; + } + + @Override + public Renderer getComponentRenderer() { + return componentRenderer; + } + + + protected class ComponentRenderer extends RendererBase { + protected final int level; + + public ComponentRenderer (int level, int height, int border) { + super(height+2*border,border,0,0,0); + this.level=level; + } + + @Override + public void renderTitle(Context context, String text, boolean focus, boolean active, boolean open) { + super.renderTitle(context,text,focus,active,open); + if (level!=0) { + Color color=getFontColor(active); + Point p1,p2,p3; + if (open) { + p3=new Point(context.getPos().x+context.getSize().width-3, context.getPos().y+context.getSize().height/4); + p2=new Point(context.getPos().x+context.getSize().width-context.getSize().height/2, context.getPos().y+context.getSize().height*3/4); + p1=new Point(context.getPos().x+context.getSize().width-context.getSize().height+3, context.getPos().y+context.getSize().height/4); + } else { + p3=new Point(context.getPos().x+context.getSize().width-context.getSize().height*3/4,context.getPos().y+3); + p2=new Point(context.getPos().x+context.getSize().width-context.getSize().height/4, context.getPos().y+context.getSize().height/2); + p1=new Point(context.getPos().x+context.getSize().width-context.getSize().height*3/4,context.getPos().y+context.getSize().height-3); + } + context.getInterface().drawLine(p1,p2,color,color); + context.getInterface().drawLine(p2,p3,color,color); + } + if (level==0 && open) { + Color color=getFontColor(focus); + context.getInterface().fillRect(new Rectangle(context.getRect().x,context.getRect().y+context.getRect().height-1,context.getRect().width,1),color,color,color,color); + } + } + + @Override + public void renderRect (Context context, String text, boolean focus, boolean active, Rectangle rectangle, boolean overlay) { + if ((level==0 || !active) && (level!=1 || !ignoreDisabled.get())) { + Color color=getBackgroundColor(focus); + context.getInterface().fillRect(new Rectangle(rectangle.x,rectangle.y,context.getRect().x+context.getRect().width-rectangle.x,rectangle.height),color,color,color,color); + } + if (level!=0 && overlay) { + Color overlayColor; + if (context.isHovered()) { + overlayColor=new Color(0,0,0,64); + } else { + overlayColor=new Color(0,0,0,0); + } + context.getInterface().fillRect(context.getRect(),overlayColor,overlayColor,overlayColor,overlayColor); + } + Point stringPos=new Point(rectangle.getLocation()); + stringPos.translate(0,getOffset()); + if (level==0) stringPos=new Point(rectangle.x+rectangle.width/2-context.getInterface().getFontWidth(text)/2,rectangle.y+getOffset()); + if (level==2 && overlay) context.getInterface().drawString(stringPos,"> "+text,getFontColor(focus)); + else context.getInterface().drawString(stringPos,text,getFontColor(focus)); + } + + @Override + public void renderBackground (Context context, boolean focus) { + if (level==0) { + if (buttonRainbow.get()) { + Rectangle rect=context.getRect(); + for (int current=rect.y;currenttargetHue) nextHue=targetHue; + Color colorA=Color.getHSBColor(currentHue,hsb[1],hsb[2]); + Color colorB=Color.getHSBColor(nextHue,hsb[1],hsb[2]); + int top=(int)Math.round((currentHue-hsb[0])*getColorScheme().getOpacity()); + int bottom=(int)Math.round((nextHue-hsb[0])*getColorScheme().getOpacity()); + context.getInterface().fillRect(new Rectangle(rect.x,rect.y+top,rect.width,bottom-top),colorA,colorA,colorB,colorB); + currentHue=nextHue; + } + } + } +}