1 module ws.gui.buttonSimple;
2 
3 import
4 	ws.event,
5 	ws.gl.draw,
6 	ws.gui.base,
7 	ws.gui.style,
8 	ws.gui.text,
9 	ws.gui.point;
10 
11 
12 class Button: Base {
13 	
14 	Event!() leftClick;
15 	Event!() rightClick;
16 
17 	string text;
18 	bool pressed;
19 	bool mouseFocus;
20 	string font = "sans";
21 	int fontSize = 12;
22 
23 	this(string text){
24 		leftClick = new Event!();
25 		rightClick = new Event!();
26 		Style style;
27 		style.bg = Color(
28 				[0.1, 0.1, 0.1, 0.5],
29 				[0.2, 0.2, 0.2, 0.7],
30 				[0.2, 0.2, 0.2, 1],
31 		);
32 		style.fg = Color(
33 				[1, 1, 1, 0.9],
34 				[1, 1, 1, 1],
35 				[1, 1, 1, 1]
36 		);
37 		this.text = text;
38 		setStyle(style);
39 	}
40 
41 
42 	override void setStyle(Style style){
43 		super.setStyle(style);
44 	}
45 
46 
47 	override void onDraw(){
48 		draw.setColor(pressed ? style.bg.active :
49 				(mouseFocus ? style.bg.hover
50 						: style.bg.normal));
51 		draw.rect(pos, size);
52 		/+
53 		draw.setColor(pressed ? style.fg.active :
54 				(mouseFocus ? style.fg.hover
55 						: style.fg.normal));
56 		+/
57 		draw.setColor(style.fg);
58 		draw.setFont(font, fontSize);
59 		draw.text(pos, size.h, text);
60 		super.onDraw();
61 	}
62 
63 
64 	override void onMouseButton(Mouse.button button, bool p, int x, int y){
65 		super.onMouseButton(button, p, x, y);
66 		if(!p && pressed){
67 			if(button == Mouse.buttonLeft)
68 				leftClick();
69 			else if(button == Mouse.buttonRight)
70 				rightClick();
71 			pressed = false;
72 		}
73 		pressed = p;
74 	}
75 	
76 	
77 	override void onMouseFocus(bool focus){
78 		mouseFocus = focus;
79 		if(!focus)
80 			pressed = false;
81 		super.onMouseFocus(focus);
82 	}
83 
84 
85 }
86