1 module pixelperfectengine.concrete.elements.button;
2 
3 public import pixelperfectengine.concrete.elements.base;
4 /**
5  * Implements a simple clickable window element for user input.
6  */
7 public class Button : WindowElement {
8 	//private bool isPressed;
9 	//public bool enableRightButtonClick;
10 	//public bool enableMiddleButtonClick;
11 	/**
12 	 * Creates a Button with the default text formatting style.
13 	 * Params:
14 	 *   text = The text to be displayed on the button.
15 	 *   source = The source of the events emitted by this window element.
16 	 *   position = Defines where the button should be drawn.
17 	 */
18 	public this(dstring text, string source, Box position) {
19 		this(new Text(text,getStyleSheet.getChrFormatting("button")), source, position);
20 	}
21 	/**
22 	 * Creates a Button with the supplied Text object.
23 	 * Params:
24 	 *   text = The text to be displayed on the button. Can contain one or more icons.
25 	 *   source = The source of the events emitted by this window element.
26 	 *   position = Defines where the button should be drawn.
27 	 */
28 	public this(Text text, string source, Box position) {
29 		this.position = position;
30 		this.text = text;
31 		this.source = source;
32 		//output = new BitmapDrawer(coordinates.width, coordinates.height);
33 	}
34 	public override void draw() {
35 		if (parent is null) return;
36 		StyleSheet ss = getStyleSheet();
37 		parent.clearArea(position);
38 		if (isPressed) {
39 			
40 			with (parent) {
41 				drawFilledBox(position, ss.getColor("windowinactive"));
42 				drawLine(position.cornerUL, position.cornerUR, ss.getColor("windowdescent"));
43 				drawLine(position.cornerUL, position.cornerLL, ss.getColor("windowdescent"));
44 				drawLine(position.cornerLL, position.cornerLR, ss.getColor("windowascent"));
45 				drawLine(position.cornerUR, position.cornerLR, ss.getColor("windowascent"));
46 			}
47 		} else {
48 			
49 			with (parent) {
50 				drawFilledBox(position, ss.getColor("buttonTop"));
51 				drawLine(position.cornerUL, position.cornerUR, ss.getColor("windowascent"));
52 				drawLine(position.cornerUL, position.cornerLL, ss.getColor("windowascent"));
53 				drawLine(position.cornerLL, position.cornerLR, ss.getColor("windowdescent"));
54 				drawLine(position.cornerUR, position.cornerLR, ss.getColor("windowdescent"));
55 			}
56 		}
57 		if (isFocused) {
58 			const int textPadding = ss.drawParameters["horizTextPadding"];
59 			parent.drawBoxPattern(position - textPadding, ss.pattern["blackDottedLine"]);
60 		}
61 		parent.drawTextSL(position, text, Point(0, 0));
62 		if (state == ElementState.Disabled) {
63 			parent.bitBLTPattern(position, ss.getImage("ElementDisabledPtrn"));
64 		}
65 		if (onDraw !is null) {
66 			onDraw();
67 		}
68 	}
69 	
70 }