22
33import studios .vanish .utility .EventHandler ;
44
5+
56import java .awt .Font ;
67import java .awt .event .MouseEvent ;
78public class Button
89{
10+ public enum ButtonType
11+ {
12+ Rectangle , Circle
13+ }
914 public Point Location = new Point (0 , 0 );
1015 public Size Size = new Size (130 , 25 );
1116 public String Text = "button" ;
1217 public Font TextFont = new Font ("Segoe UI" , Font .PLAIN , 11 );
1318 public Color [] BackColor = {Color .Black , Color .Red , Color .Green };
1419 public Color [] ForeColor = {Color .White , Color .Green , Color .Red };
1520 public EventHandler OnClick = new EventHandler ();
21+ public ButtonType Type = ButtonType .Rectangle ;
1622 public boolean Enabled = true ;
1723 private int state = 0 ;
18- private Rectangle rect ;
24+ private Shape bounds ;
1925 private boolean down = false ;
2026 Window wnd ;
2127 public Button (Window wnd , String text )
@@ -48,14 +54,26 @@ public void SetForeColor(Color normal, Color hover, Color press)
4854 }
4955 public void Initialize ()
5056 {
51- rect = new Rectangle (BackColor [state ], Location , Size );
57+ int rad = Size .Width ;
58+ if (Size .Height > Size .Width )
59+ {
60+ rad = Size .Height ;
61+ }
62+ if (Type == ButtonType .Rectangle )
63+ {
64+ bounds = new Rectangle (BackColor [state ], Location , Size );
65+ }
66+ else if (Type == ButtonType .Circle )
67+ {
68+ bounds = new Circle (BackColor [state ], Location , rad );
69+ }
5270 }
5371 public void Check (Point MouseLocation , int Button )
5472 {
5573 if (Enabled == true )
5674 {
57- rect = new Rectangle ( BackColor [ state ], Location , Size );
58- if (rect .Intersects (MouseLocation ))
75+ Initialize ( );
76+ if (bounds .Intersects (MouseLocation ))
5977 {
6078 if (wnd .Mouse [MouseEvent .BUTTON1 ])
6179 {
@@ -82,8 +100,9 @@ public void Check(Point MouseLocation, int Button)
82100 public void Render (GraphicsUnit Graphics )
83101 {
84102 Size center = Graphics .GetTextSize (Text , TextFont );
85- Point text = new Point ((Location .X + (Size .Width ) / 2 ) - (center .Width / 2 ), (Location .Y + (Size .Height ) / 2 ) - (center .Height / 2 ));
86- Graphics .FillRectangle (BackColor [state ], Location , Size );
103+ Initialize ();
104+ Point text = new Point (bounds .GetShapeCenter ().X - (center .Width / 2 ), bounds .GetShapeCenter ().Y - (center .Height / 2 ));
105+ bounds .Render (Graphics );
87106 Graphics .DrawString (Text , ForeColor [state ], text , TextFont );
88107 }
89108}
0 commit comments