99import java .awt .event .MouseMotionListener ;
1010import java .awt .event .MouseWheelListener ;
1111import java .util .ArrayList ;
12+ import java .util .Arrays ;
1213import java .util .concurrent .CopyOnWriteArrayList ;
1314
1415public class PUIElement extends PUICanvas { // PaulsenUserInterfaceIntegratedElement
1516
1617 // Static
1718 public static volatile boolean useGBC = false ; // signals PUICore to use System.gbc()
1819 public static volatile CopyOnWriteArrayList <PUIElement > registeredElements = new CopyOnWriteArrayList <PUIElement >();
19- public static boolean darkUIMode = false ;
20- public static Color darkBG_1 = new Color (47 , 47 , 47 ), darkBG_2 = new Color (57 , 57 , 57 ),
21- darkOutline = new Color (81 , 81 , 81 ), darkText = new Color (235 , 235 , 235 ),
22- darkSelected = new Color (196 , 196 , 196 );
20+ public static volatile Color [] default_colors = new Color []{
21+ new Color (47 , 47 , 47 ), // BG
22+ new Color (196 , 196 , 196 ), // Text
23+ new Color (57 , 57 , 57 ), // BG_accent
24+ new Color (81 , 81 , 81 ) // Text_accent
25+ };
2326
2427 public enum ElementAlignment {
2528 HORIZONTAL , VERTICAL
2629 }
2730
28- protected int x = 0 , y = 0 , w = 0 , h = 0 ;
29- protected Color backgroundColor = Color . LIGHT_GRAY ;
31+ protected int x = 0 , y = 0 , w = 0 , h = 0 , arcWidth = 15 , arcHeight = 15 ;
32+ protected volatile Color colors [] = new Color [ 0 ] ;
3033 protected PUIPaintable hoverOverlay , pressOverlay ;
3134 protected PUIFrame frame ;
3235 protected PUICore core ;
@@ -63,15 +66,13 @@ private void init() {
6366 mouseMotionListeners .add (new MouseMotionListener () {
6467 @ Override
6568 public void mouseMoved (MouseEvent e ) {
66- if (!enabled )
67- return ;
69+ if (!enabled ) return ;
6870 hovered = contains (e .getPoint ());
6971 }
7072
7173 @ Override
7274 public void mouseDragged (MouseEvent e ) {
73- if (!enabled )
74- return ;
75+ if (!enabled ) return ;
7576 Point p = e .getPoint ();
7677 hovered = contains (e .getPoint ());
7778
@@ -80,16 +81,14 @@ public void mouseDragged(MouseEvent e) {
8081 mouseListeners .add (new MouseListener () {
8182 @ Override
8283 public void mouseReleased (MouseEvent e ) {
83- if (enabled )
84- hovered = contains (e .getPoint ());
84+ if (enabled ) hovered = contains (e .getPoint ());
8585 pressed = false ;
8686 isCurrentlyPressing = false ;
8787 }
8888
8989 @ Override
9090 public void mousePressed (MouseEvent e ) {
91- if (!enabled )
92- return ;
91+ if (!enabled ) return ;
9392 if (!pressed && hovered ) {
9493 Point p = e .getPoint ();
9594 if (p != null && getBounds ().contains (p )) {
@@ -116,31 +115,25 @@ public void mouseClicked(MouseEvent e) {
116115 paint = new PUIPaintable () {
117116 @ Override
118117 public void paint (Graphics2D g , int x , int y , int w , int h ) {
119- if (darkUIMode && backgroundColor == Color .LIGHT_GRAY ) {
120- g .setColor (darkBG_1 );
121- g .fillRect (x , y , w , h );
122- g .setColor (darkOutline );
123- g .drawRect (x , y , w , h );
124- } else {
125- g .setColor (backgroundColor );
126- g .fillRect (x , y , w , h );
127- g .setColor (new Color (50 , 50 , 50 ));
128- g .drawRect (x , y , w , h );
129- }
118+ g .setColor (getBackgroundColor ());
119+ g .fillRoundRect (x , y , w , h , arcWidth , arcHeight );
120+
121+ g .setColor (color (2 ));
122+ g .drawRoundRect (x , y , w , h , arcWidth , arcHeight );
130123 }
131124 };
132125 hoverOverlay = new PUIPaintable () {
133126 @ Override
134127 public void paint (Graphics2D g , int x , int y , int w , int h ) {
135128 g .setColor (new Color (100 , 100 , 100 , 100 ));
136- g .fillRect (x , y , w , h );
129+ g .fillRoundRect (x , y , w , h , arcWidth , arcHeight );
137130 }
138131 };
139132 pressOverlay = new PUIPaintable () {
140133 @ Override
141134 public void paint (Graphics2D g , int x , int y , int w , int h ) {
142135 g .setColor (new Color (100 , 100 , 100 , 200 ));
143- g .fillRect (x , y , w , h );
136+ g .fillRoundRect (x , y , w , h , arcWidth , arcHeight );
144137 }
145138 };
146139 }
@@ -169,19 +162,16 @@ private void initCore() {
169162
170163 @ Override
171164 public synchronized void draw (Graphics2D g ) {
172- if (g == null || !isEnabled ())
173- return ;
165+ if (g == null || !isEnabled ()) return ;
174166
175167 if (paint != null ) {
176168 paint .paint (g , x , y , w , h );
177169 }
178170 if (hovered ) {
179171 if (hovered && !pressed && paintOverOnHover ) {
180- if (hoverOverlay != null )
181- hoverOverlay .paint (g , x , y , w , h );
172+ if (hoverOverlay != null ) hoverOverlay .paint (g , x , y , w , h );
182173 } else if (pressed && paintOverOnPress ) {
183- if (pressOverlay != null )
184- pressOverlay .paint (g , x , y , w , h );
174+ if (pressOverlay != null ) pressOverlay .paint (g , x , y , w , h );
185175 }
186176 }
187177 }
@@ -205,10 +195,8 @@ public ArrayList<PUIAction> getActionListeners() {
205195
206196 public void runAllActions () {
207197
208- if (actions != null )
209- for (PUIAction r : actions )
210- if (r != null )
211- r .run (this );
198+ if (actions != null ) for (PUIAction r : actions )
199+ if (r != null ) r .run (this );
212200
213201 if (repaintFrameOnEvent && frame != null ) {
214202 frame .repaint ();
@@ -359,10 +347,8 @@ public void setInteractionLayer(int interactionLayer) {
359347 public void setLayer (int l ) {
360348 drawLayer = l ;
361349 interactionLayer = l ;
362- if (core != null )
363- core .rearrangeElements ();
364- if (frame != null )
365- frame .rearrangeElements ();
350+ if (core != null ) core .rearrangeElements ();
351+ if (frame != null ) frame .rearrangeElements ();
366352 }
367353
368354 public ArrayList <MouseMotionListener > getMouseMotionListeners () {
@@ -378,11 +364,56 @@ public ArrayList<MouseListener> getMouseListeners() {
378364 }
379365
380366 public Color getBackgroundColor () {
381- return backgroundColor ;
367+ return color (0 );
368+ }
369+
370+ public Color getTextColor () {
371+ return color (1 );
382372 }
383373
384374 public void setBackgroundColor (Color backgroundColor ) {
385- this .backgroundColor = backgroundColor ;
375+ setColor (0 , backgroundColor );
376+ }
377+
378+ public Color color (int index ) {
379+ if (colors .length > index ) {
380+ return colors [index ];
381+ }
382+ if (default_colors .length > index ) {
383+ return default_colors [index ];
384+ }
385+ return null ;
386+ }
387+
388+ public void setColor (int index , Color color ) {
389+ if (colors .length > index ) {
390+ colors [index ] = color ;
391+ } else {
392+ colors = Arrays .copyOf (colors , index + 1 );
393+ colors [index ] = color ;
394+ }
395+ }
396+
397+ /**
398+ * @return Default-Color of the library - Null if the Could does not exist
399+ */
400+ public static Color getDefaultColor (int index ) {
401+ if (default_colors .length > index ) {
402+ return default_colors [index ];
403+ }
404+ return null ;
405+ }
406+
407+ /*
408+ Sets Default-Color of the library
409+ */
410+ public static void setDefaultColor (int index , Color color ) {
411+ if (default_colors .length > index ) {
412+ default_colors [index ] = color ;
413+ } else {
414+ default_colors = Arrays .copyOf (default_colors , index + 1 );
415+ default_colors [index ] = color ;
416+ }
386417 }
387418
388419 public Object getMetadata () {
0 commit comments