1 /** 2 * Copyright: Copyright (C) 2018 Gabriel Gheorghe, All Rights Reserved 3 * Authors: $(Gabriel Gheorghe) 4 * License: $(LINK2 https://www.gnu.org/licenses/gpl-3.0.txt, GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007) 5 * Source: $(LINK2 https://github.com/GabyForceQ/LibertyEngine/blob/master/source/liberty/framework/gui/controls.d) 6 * Documentation: 7 * Coverage: 8 **/ 9 module liberty.framework.gui.controls; 10 11 import liberty.material.impl; 12 import liberty.math.vector; 13 import liberty.model.impl; 14 import liberty.model.io; 15 import liberty.framework.gui.event; 16 import liberty.framework.gui.meta; 17 import liberty.framework.gui.vertex; 18 import liberty.framework.gui.widget; 19 20 /** 21 * 22 **/ 23 final class Canvas : Widget { 24 private { 25 Widget[string] widgets; 26 } 27 28 mixin WidgetConstructor; 29 30 /** 31 * Call update for all widgets. 32 **/ 33 override void update() { 34 foreach (widget; widgets) 35 widget.update; 36 } 37 38 /** 39 * Returns the widgets map. 40 **/ 41 Widget[string] getWidgets() { 42 return widgets; 43 } 44 45 /** 46 * Returns a widget by given id 47 **/ 48 Widget getWidget(string id) { 49 return widgets[id]; 50 } 51 52 package typeof(this) addWidget(Widget widget) { 53 // Add a new widget to the canvas 54 widgets[widget.id] = widget; 55 56 // Returns reference to this and can be used in a stream 57 return this; 58 } 59 } 60 61 /** 62 * 63 **/ 64 final class CustomControl(alias E) : Widget { 65 mixin WidgetEventProps!(E); 66 67 mixin WidgetConstructor!(q{ 68 model = new Model(ModelIO.loadRawModel(uiSquareVertices, uiSquareIndices), [Material.getDefault()]); 69 }); 70 71 mixin WidgetUpdate; 72 } 73 74 /** 75 * 76 **/ 77 final class Button : Widget { 78 mixin WidgetEventProps!([ 79 Event.MouseLeftClick, 80 Event.MouseMiddleClick, 81 Event.MouseRightClick, 82 Event.MouseOver, 83 Event.MouseMove, 84 Event.MouseEnter, 85 Event.MouseLeave, 86 Event.Update 87 ]); 88 89 mixin WidgetConstructor!(q{ 90 model = new Model(ModelIO.loadRawModel(uiSquareVertices, uiSquareIndices), [Material.getDefault()]); 91 }); 92 93 mixin WidgetUpdate; 94 } 95 96 /** 97 * 98 **/ 99 final class CustomButton(alias E) : Widget { 100 mixin WidgetEventProps!([ 101 Event.MouseLeftClick 102 ] ~ E); 103 104 mixin WidgetConstructor!(q{ 105 model = new Model(ModelIO.loadRawModel(uiSquareVertices, uiSquareIndices), [Material.getDefault()]); 106 }); 107 108 mixin WidgetUpdate; 109 } 110 111 /** 112 * 113 **/ 114 final class CheckBox : Widget { 115 mixin WidgetEventProps!([ 116 Event.MouseLeftClick, 117 Event.MouseMiddleClick, 118 Event.MouseRightClick, 119 Event.MouseOver, 120 Event.MouseMove, 121 Event.MouseEnter, 122 Event.MouseLeave, 123 Event.Check, 124 Event.Checked, 125 Event.Uncheck, 126 Event.Unchecked, 127 Event.StateChange, 128 Event.Update 129 ]); 130 131 mixin WidgetConstructor!(q{ 132 model = new Model(ModelIO.loadRawModel(uiSquareVertices, uiSquareIndices), [Material.getDefault()]); 133 }); 134 135 mixin WidgetUpdate; 136 } 137 138 /** 139 * 140 **/ 141 final class CustomCheckBox(alias E) : Widget { 142 mixin WidgetEventProps!([ 143 Event.Check, 144 Event.Checked, 145 Event.Uncheck, 146 Event.Unchecked, 147 ] ~ E); 148 149 mixin WidgetConstructor!(q{ 150 model = new Model(ModelIO.loadRawModel(uiSquareVertices, uiSquareIndices), [Material.getDefault()]); 151 }); 152 153 mixin WidgetUpdate; 154 } 155 156 /** 157 * 158 **/ 159 final class TextBlock : Widget { 160 mixin WidgetConstructor; 161 } 162 163 /*private*/ uint[6] uiSquareIndices = [ 164 0, 1, 2, 165 0, 2, 3 166 ]; 167 168 /*private*/ GuiVertex[] uiSquareVertices = [ 169 GuiVertex(Vector3F(-1.0f, 1.0f, 0.0f), Vector2F(0.0f, 1.0f)), 170 GuiVertex(Vector3F(-1.0f, -1.0f, 0.0f), Vector2F(0.0f, 0.0f)), 171 GuiVertex(Vector3F( 1.0f, -1.0f, 0.0f), Vector2F(1.0f, 0.0f)), 172 GuiVertex(Vector3F( 1.0f, 1.0f, 0.0f), Vector2F(1.0f, 1.0f)) 173 ];