1 module evael.graphics.gui.controls.MessageBox;
2 
3 import evael.graphics.gui.controls.Container;
4 import evael.graphics.gui.controls.Button;
5 import evael.graphics.gui.controls.TextBlock;
6 
7 import evael.utils.Math;
8 
9 import evael.utils.Size;
10 import evael.utils.Color;
11 
12 class MessageBox : Container
13 {
14 	enum ButtonType : ubyte
15 	{
16 		Ok,
17 		No,
18 	}
19 
20 	protected alias void delegate(ButtonType buttonType) OnAnswerEvent;
21 	protected OnAnswerEvent m_onAnswerEvent;
22 
23 	/// MessageBox content
24 	private wstring m_message;
25 
26 	public this(in wstring message, in float x, in float y, in int width = 0, in int height = 0)
27 	{
28 		this(message, vec2(x, y), Size!int(width, height));
29 	}
30 
31 	public this(in wstring message, in vec2 position, in Size!int size)
32 	{
33 		super(position, size);
34 
35 		this.m_movable = false;
36 		this.m_message = message;
37 		
38 		this.hide();
39 	}
40 
41 	public override void draw(in float deltaTime)
42 	{
43 		super.draw(deltaTime);
44 	}
45 
46 	public override void initialize()
47 	{
48 		this.m_size.width = cast(int)this.m_theme.font.getTextWidth(this.m_message) + 120;
49 		this.m_size.height = this.m_theme.font.getTextHeight(this.m_message) + 60;
50 
51 		auto noButton = new Button("Non", this.m_theme.font.getTextWidth(this.m_message) - 40, 5);
52 		auto okButton = new Button("Oui", noButton.position.x - noButton.size.width - 50, 5);
53 
54 		okButton.onClickEvent = (sender) => this.m_onAnswerEvent(ButtonType.Ok);
55 		noButton.onClickEvent = (sender) => this.m_onAnswerEvent(ButtonType.No);
56 
57 		auto text = new TextBlock();
58 		text.text = this.m_message;
59 		text.dock = Control.Dock.Fill;
60 
61 		this.addChild(text);
62 		this.addChild(okButton);
63 		this.addChild(noButton);
64 
65 		super.initialize();
66 	}
67 
68 	@property
69 	public void onAnswerEvent(OnAnswerEvent value) nothrow
70 	{
71 		this.m_onAnswerEvent = value;
72 	}
73 
74 }