1 module evael.graphics.gui.controls.CheckBox; 2 3 import evael.graphics.gui.controls.Control; 4 5 import evael.utils.Math; 6 7 import evael.utils.Size; 8 import evael.utils.Color; 9 10 class CheckBox : Control 11 { 12 private bool m_checked; 13 14 /// Check rect color 15 private Color m_color; 16 17 private wstring m_text; 18 19 private vec2 m_textPosition; 20 21 public this(in wstring text, in float x, in float y, in int width = 13, in int height = 13) 22 { 23 this(text, vec2(x, y), Size!int(width, height)); 24 } 25 26 public this(in wstring text, in vec2 position, in Size!int size) 27 { 28 super(position, size); 29 30 this.m_name = "checkBox"; 31 this.m_checked = false; 32 this.m_color = Color.Black; 33 this.m_text = text; 34 } 35 36 public override void draw(in float deltaTime) 37 { 38 if(!this.m_isVisible) 39 return; 40 } 41 42 /** 43 * Event called on mouse button release 44 * Params: 45 * mouseButton : mouse button 46 */ 47 public override void onMouseUp(in MouseButton mouseButton) 48 { 49 super.onMouseUp(mouseButton); 50 this.switchState!(State.Hovered); 51 52 this.m_checked = !this.m_checked; 53 } 54 55 /** 56 * Event called when mouse enters in control's rect 57 * Params: 58 * mousePosition : mouse position 59 */ 60 public override void onMouseMove(in ref vec2 mousePosition) 61 { 62 super.onMouseMove(mousePosition); 63 64 if(this.isClicked) 65 { 66 this.switchState!(State.Clicked); 67 } 68 else 69 { 70 this.switchState!(State.Hovered); 71 } 72 } 73 74 /** 75 * Event called when mouse leaves control's rect 76 */ 77 public override void onMouseLeave() 78 { 79 super.onMouseLeave(); 80 this.switchState!(State.Normal); 81 } 82 83 @property 84 public bool checked() const nothrow 85 { 86 return this.m_checked; 87 } 88 89 90 @property 91 public void color()(in auto ref Color value) 92 { 93 this.m_color = value; 94 } 95 }