1 module evael.graphics.gui.controls.Window; 2 3 import evael.graphics.gui.controls.Container; 4 5 import evael.utils.Math; 6 import evael.utils.Size; 7 8 /** 9 * 10 */ 11 class Window : Container 12 { 13 /// Display title bar ? 14 protected bool m_titleBar; 15 16 /// Display close button ? 17 protected bool m_closeButton; 18 19 public this(in float x, in float y, in int width, in int height) 20 { 21 this(vec2(x, y,), Size!int(width, height)); 22 } 23 24 public this()(in auto ref vec2 position, in auto ref Size!int size) 25 { 26 super(position, size); 27 28 this.m_closeButton = true; 29 this.m_titleBar = false; 30 } 31 32 /** 33 * Event called when mouse enters the control. 34 * Params: 35 * position : mouse position 36 */ 37 public override void onMouseMove(in ref vec2 position) 38 { 39 super.onMouseMove(position); 40 41 // We draw the control that is under the mouse at the end 42 if (this.m_controlUnderMouse !is null) 43 { 44 import std.algorithm : sort; 45 46 this.m_controls.sort!((a, b) => a.zIndex < b.zIndex); 47 48 //this.m_controls.sort!((a, b) => b == this.m_controlUnderMouse); 49 } 50 } 51 52 public override void initialize() 53 { 54 if (this.m_titleBar) 55 { 56 import evael.graphics.gui.controls.Panel; 57 import evael.graphics.gui.controls.Button; 58 59 // Title panel 60 auto panel = new Panel(0, 0, this.m_size.width - 4, 25); 61 panel.dock = Control.Dock.Top; 62 63 if(this.m_closeButton) 64 { 65 auto closeButton = new Button(-5, 2 , 20, 20); 66 closeButton.type = Button.Type.Icon; 67 closeButton.dock = Control.Dock.Right; 68 closeButton.icon = Icon.Cross; 69 closeButton.onClickEvent = (sender) { this.hide(); }; 70 71 panel.addChild(closeButton); 72 } 73 74 this.addChild(panel); 75 } 76 77 super.initialize(); 78 } 79 80 @nogc 81 @property nothrow 82 { 83 public void titleBar(in bool value) 84 { 85 this.m_titleBar = value; 86 } 87 88 public void closeButton(in bool value) 89 { 90 this.m_closeButton = value; 91 } 92 } 93 }