1 module pixelperfectengine.concrete.elements.smallbutton;
2 
3 public import pixelperfectengine.concrete.elements.base;
4 
5 /**
6  * SmallButton is used to implement small buttons for toolbars, on window headers, etc.
7  * Icons contain the frame of the buttons, etc., and are recalled from the closest 
8  * available stylesheet.
9  */
10 public class SmallButton : WindowElement, ISmallButton {
11 	///Defines what icons will the button use for its states.
12 	public string			iconPressed, iconUnpressed;
13 	
14 	/**
15 	 * Creates an instance of SmallButton.
16 	 * Params:
17 	 *   iconPressed = the string ID of the icon to be shown when the button is pressed.
18 	 *   iconUnpressed = the string ID of the icon to be shown when the button is not 
19 	 * pressed.
20 	 *   source = the source identifier passed in the event class.
21 	 *   position = the position where the button will be drawn. If the button will be 
22 	 * used as a window header button, you only need to set the size, since the final 
23 	 * position will be set by the window itself.
24 	 */
25 	public this(string iconPressed, string iconUnpressed, string source, Box position){
26 		this.position = position;
27 
28 		//this.text = text;
29 		this.source = source;
30 		this.iconPressed = iconPressed;
31 		this.iconUnpressed = iconUnpressed;
32 		
33 		
34 	}
35 	public override void draw() {
36 		if (parent is null) return;
37 		StyleSheet ss = getStyleSheet();
38 		Bitmap8Bit icon = isPressed ? ss.getImage(iconPressed) : ss.getImage(iconUnpressed);
39 		parent.bitBLT(position.cornerUL, icon);
40 		Box pos = position;
41 		pos.bottom--;
42 		pos.right--;
43 		if (isFocused) {
44 			const int textPadding = ss.drawParameters["horizTextPadding"];
45 			parent.drawBoxPattern(pos - textPadding, ss.pattern["blackDottedLine"]);
46 		}
47 
48 		if (state == ElementState.Disabled) {
49 			parent.bitBLTPattern(pos, ss.getImage("ElementDisabledPtrn"));
50 		}
51 		if (onDraw !is null) {
52 			onDraw();
53 		}
54 	}
55 	/**
56 	 * Returns true if the SmallButton is of size `height`, false otherwise.
57 	 */
58 	public bool isSmallButtonHeight(int height) {
59 		if (position.width == height && position.height == height) return true;
60 		else return false;
61 	}
62 	///Returns true if left side justified, false otherwise.
63 	public bool isLeftSide() @nogc @safe pure nothrow const {
64 		return flags & IS_LHS ? true : false;
65 	}
66 	///Sets the small button to the left side if true.
67 	public bool isLeftSide(bool val) @nogc @safe pure nothrow {
68 		if (val) flags |= IS_LHS;
69 		else flags &= ~IS_LHS;
70 		return flags & IS_LHS ? true : false;
71 	}
72 }