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 StyleSheet ss = getStyleSheet(); 36 parent.clearArea(position); 37 if (isPressed) { 38 39 with (parent) { 40 drawFilledBox(position, ss.getColor("windowinactive")); 41 drawLine(position.cornerUL, position.cornerUR, ss.getColor("windowdescent")); 42 drawLine(position.cornerUL, position.cornerLL, ss.getColor("windowdescent")); 43 drawLine(position.cornerLL, position.cornerLR, ss.getColor("windowascent")); 44 drawLine(position.cornerUR, position.cornerLR, ss.getColor("windowascent")); 45 } 46 } else { 47 48 with (parent) { 49 drawFilledBox(position, ss.getColor("buttonTop")); 50 drawLine(position.cornerUL, position.cornerUR, ss.getColor("windowascent")); 51 drawLine(position.cornerUL, position.cornerLL, ss.getColor("windowascent")); 52 drawLine(position.cornerLL, position.cornerLR, ss.getColor("windowdescent")); 53 drawLine(position.cornerUR, position.cornerLR, ss.getColor("windowdescent")); 54 } 55 } 56 if (isFocused) { 57 const int textPadding = ss.drawParameters["horizTextPadding"]; 58 parent.drawBoxPattern(position - textPadding, ss.pattern["blackDottedLine"]); 59 } 60 parent.drawTextSL(position, text, Point(0, 0)); 61 if (state == ElementState.Disabled) { 62 parent.bitBLTPattern(position, ss.getImage("ElementDisabledPtrn")); 63 } 64 if (onDraw !is null) { 65 onDraw(); 66 } 67 } 68 69 }