|
| 1 | +package com.lukflug.panelstudio.theme; |
| 2 | + |
| 3 | +import java.awt.Color; |
| 4 | +import java.awt.Point; |
| 5 | +import java.awt.Rectangle; |
| 6 | +import java.util.function.Supplier; |
| 7 | + |
| 8 | +import com.lukflug.panelstudio.Context; |
| 9 | + |
| 10 | +/** |
| 11 | + * Theme made on commission for doctor swag#2624. |
| 12 | + * @author lukflug |
| 13 | + */ |
| 14 | +public class DoctorSwagRainbowTheme implements Theme { |
| 15 | + protected ColorScheme scheme; |
| 16 | + protected Renderer componentRenderer,containerRenderer,panelRenderer; |
| 17 | + protected Supplier<Boolean> ignoreDisabled,buttonRainbow; |
| 18 | + |
| 19 | + public DoctorSwagRainbowTheme (ColorScheme scheme, int height, Supplier<Boolean> ignoreDisabled, Supplier<Boolean> buttonRainbow) { |
| 20 | + this.scheme=scheme; |
| 21 | + panelRenderer=new ComponentRenderer(0,height,0); |
| 22 | + containerRenderer=new ComponentRenderer(1,height,0); |
| 23 | + componentRenderer=new ComponentRenderer(2,height,0); |
| 24 | + this.ignoreDisabled=ignoreDisabled; |
| 25 | + this.buttonRainbow=buttonRainbow; |
| 26 | + } |
| 27 | + |
| 28 | + @Override |
| 29 | + public Renderer getPanelRenderer() { |
| 30 | + return panelRenderer; |
| 31 | + } |
| 32 | + |
| 33 | + @Override |
| 34 | + public Renderer getContainerRenderer() { |
| 35 | + return containerRenderer; |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + public Renderer getComponentRenderer() { |
| 40 | + return componentRenderer; |
| 41 | + } |
| 42 | + |
| 43 | + |
| 44 | + protected class ComponentRenderer extends RendererBase { |
| 45 | + protected final int level; |
| 46 | + |
| 47 | + public ComponentRenderer (int level, int height, int border) { |
| 48 | + super(height+2*border,border,0,0,0); |
| 49 | + this.level=level; |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public void renderTitle(Context context, String text, boolean focus, boolean active, boolean open) { |
| 54 | + super.renderTitle(context,text,focus,active,open); |
| 55 | + if (level!=0) { |
| 56 | + Color color=getFontColor(active); |
| 57 | + Point p1,p2,p3; |
| 58 | + if (open) { |
| 59 | + p3=new Point(context.getPos().x+context.getSize().width-3, context.getPos().y+context.getSize().height/4); |
| 60 | + p2=new Point(context.getPos().x+context.getSize().width-context.getSize().height/2, context.getPos().y+context.getSize().height*3/4); |
| 61 | + p1=new Point(context.getPos().x+context.getSize().width-context.getSize().height+3, context.getPos().y+context.getSize().height/4); |
| 62 | + } else { |
| 63 | + p3=new Point(context.getPos().x+context.getSize().width-context.getSize().height*3/4,context.getPos().y+3); |
| 64 | + p2=new Point(context.getPos().x+context.getSize().width-context.getSize().height/4, context.getPos().y+context.getSize().height/2); |
| 65 | + p1=new Point(context.getPos().x+context.getSize().width-context.getSize().height*3/4,context.getPos().y+context.getSize().height-3); |
| 66 | + } |
| 67 | + context.getInterface().drawLine(p1,p2,color,color); |
| 68 | + context.getInterface().drawLine(p2,p3,color,color); |
| 69 | + } |
| 70 | + if (level==0 && open) { |
| 71 | + Color color=getFontColor(focus); |
| 72 | + context.getInterface().fillRect(new Rectangle(context.getRect().x,context.getRect().y+context.getRect().height-1,context.getRect().width,1),color,color,color,color); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + public void renderRect (Context context, String text, boolean focus, boolean active, Rectangle rectangle, boolean overlay) { |
| 78 | + if ((level==0 || !active) && (level!=1 || !ignoreDisabled.get())) { |
| 79 | + Color color=getBackgroundColor(focus); |
| 80 | + context.getInterface().fillRect(new Rectangle(rectangle.x,rectangle.y,context.getRect().x+context.getRect().width-rectangle.x,rectangle.height),color,color,color,color); |
| 81 | + } |
| 82 | + if (level!=0 && overlay) { |
| 83 | + Color overlayColor; |
| 84 | + if (context.isHovered()) { |
| 85 | + overlayColor=new Color(0,0,0,64); |
| 86 | + } else { |
| 87 | + overlayColor=new Color(0,0,0,0); |
| 88 | + } |
| 89 | + context.getInterface().fillRect(context.getRect(),overlayColor,overlayColor,overlayColor,overlayColor); |
| 90 | + } |
| 91 | + Point stringPos=new Point(rectangle.getLocation()); |
| 92 | + stringPos.translate(0,getOffset()); |
| 93 | + if (level==0) stringPos=new Point(rectangle.x+rectangle.width/2-context.getInterface().getFontWidth(text)/2,rectangle.y+getOffset()); |
| 94 | + if (level==2 && overlay) context.getInterface().drawString(stringPos,"> "+text,getFontColor(focus)); |
| 95 | + else context.getInterface().drawString(stringPos,text,getFontColor(focus)); |
| 96 | + } |
| 97 | + |
| 98 | + @Override |
| 99 | + public void renderBackground (Context context, boolean focus) { |
| 100 | + if (level==0) { |
| 101 | + if (buttonRainbow.get()) { |
| 102 | + Rectangle rect=context.getRect(); |
| 103 | + for (int current=rect.y;current<rect.y+rect.height;current+=height) { |
| 104 | + int height=Math.min(this.height,rect.height+rect.y-current); |
| 105 | + renderRainbowRect(new Rectangle(rect.x,current,rect.width,height),context,focus); |
| 106 | + } |
| 107 | + } else renderRainbowRect(context.getRect(),context,focus); |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + @Override |
| 112 | + public void renderBorder (Context context, boolean focus, boolean active, boolean open) { |
| 113 | + } |
| 114 | + |
| 115 | + @Override |
| 116 | + public Color getMainColor (boolean focus, boolean active) { |
| 117 | + if (active) return getColorScheme().getActiveColor(); |
| 118 | + return new Color(0,0,0,0); |
| 119 | + } |
| 120 | + |
| 121 | + @Override |
| 122 | + public Color getBackgroundColor (boolean focus) { |
| 123 | + Color color=getColorScheme().getBackgroundColor(); |
| 124 | + return new Color(color.getRed(),color.getGreen(),color.getBlue()); |
| 125 | + } |
| 126 | + |
| 127 | + @Override |
| 128 | + public ColorScheme getDefaultColorScheme() { |
| 129 | + return DoctorSwagRainbowTheme.this.scheme; |
| 130 | + } |
| 131 | + |
| 132 | + protected void renderRainbowRect (Rectangle rect, Context context, boolean focus) { |
| 133 | + Color source=getMainColor(focus,true); |
| 134 | + float[] hsb=Color.RGBtoHSB(source.getRed(),source.getGreen(),source.getBlue(),null); |
| 135 | + float currentHue=hsb[0]; |
| 136 | + float targetHue=hsb[0]; |
| 137 | + if (getColorScheme().getOpacity()!=0) targetHue+=rect.height/(float)getColorScheme().getOpacity(); |
| 138 | + else context.getInterface().fillRect(rect,source,source,source,source); |
| 139 | + while (currentHue<targetHue) { |
| 140 | + float nextHue=(float)(Math.floor(currentHue*6)+1)/6; |
| 141 | + if (nextHue>targetHue) nextHue=targetHue; |
| 142 | + Color colorA=Color.getHSBColor(currentHue,hsb[1],hsb[2]); |
| 143 | + Color colorB=Color.getHSBColor(nextHue,hsb[1],hsb[2]); |
| 144 | + int top=(int)Math.round((currentHue-hsb[0])*getColorScheme().getOpacity()); |
| 145 | + int bottom=(int)Math.round((nextHue-hsb[0])*getColorScheme().getOpacity()); |
| 146 | + context.getInterface().fillRect(new Rectangle(rect.x,rect.y+top,rect.width,bottom-top),colorA,colorA,colorB,colorB); |
| 147 | + currentHue=nextHue; |
| 148 | + } |
| 149 | + } |
| 150 | + } |
| 151 | +} |
0 commit comments