1 module pixelperfectengine.concrete.dialogs.defaultdialog;
2 
3 public import pixelperfectengine.concrete.window;
4 import pixelperfectengine.concrete.elements;
5 
6 /**
7  * Default dialog for simple messageboxes.
8  */
9 public class DefaultDialog : Window{
10 	private string source;
11 	public void delegate(Event ev) output;
12 
13 	public this(Box size, string source, Text title, Text[] message, Text[] options = [],
14 			string[] values = ["close"], StyleSheet customStyle = null) {
15 		super(size, title, null, customStyle);
16 		//generate text
17 		if(options.length == 0)
18 			options ~= new Text("Ok", getStyleSheet().getChrFormatting("button"));
19 		
20 		this.source = source;
21 		int x1, x2, y1 = 20, y2 = getStyleSheet.drawParameters["TextSpacingTop"] + getStyleSheet.drawParameters["TextSpacingBottom"]
22 								+ options[0].font.size;
23 		//Label msg = new Label(message[0], "null", Coordinate(5, 20, size.width()-5, 40));
24 		//addElement(msg, EventProperties.MOUSE);
25 
26 		//generate buttons
27 
28 		x1 = size.width() - 10;
29 		Button[] buttons;
30 		int button1 = size.height - getStyleSheet.drawParameters["WindowBottomPadding"];
31 		int button2 = button1 - getStyleSheet.drawParameters["ComponentHeight"];
32 		
33 		
34 		for(int i; i < options.length; i++) {
35 			x2 = x1 - (options[i].getWidth + getStyleSheet.drawParameters["ButtonPaddingHoriz"]);
36 			buttons ~= new Button(options[i], values[i], Box(x2, button2, x1, button1));
37 			buttons[i].onMouseLClick = &actionEvent;
38 			addElement(buttons[i]);
39 			x1 = x2 - 1;
40 		}
41 		//add labels
42 		for(int i; i < message.length; i++) {
43 			Label msg = new Label(message[i], "null", Box(getStyleSheet.drawParameters["WindowLeftPadding"],
44 								y1, size.width()-getStyleSheet.drawParameters["WindowRightPadding"], y1 + y2));
45 			addElement(msg);
46 			y1 += y2;
47 		}
48 	}
49 	///Ditto
50 	public this(Box size, string source, dstring title, dstring[] message, dstring[] options = ["Close"],
51 			string[] values = ["close"], StyleSheet customStyle = null) {
52 		this.customStyle = customStyle;
53 		Text[] opt_2;
54 		opt_2.reserve(options.length);
55 		foreach (dstring key; options) 
56 			opt_2 ~= new Text(key, getStyleSheet().getChrFormatting("button"));
57 		
58 		Text[] msg_2;
59 		msg_2.reserve(message.length);
60 		foreach (dstring key; message)
61 			msg_2 ~= new Text(key, getStyleSheet().getChrFormatting("label"));
62 		this(size, source, new Text(title, getStyleSheet().getChrFormatting("windowHeader")),msg_2,opt_2,values,customStyle);
63 	}
64 	public void actionEvent(Event ev){
65 		WindowElement we = cast(WindowElement)ev.sender;
66 		if(we.getSource == "close") {
67 			close();
68 		} else {
69 			ev.aux = this;
70 			output(ev);
71 		}
72 	}
73 }