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/widget.d)
6  * Documentation:
7  * Coverage:
8 **/
9 module liberty.framework.gui.widget;
10 
11 import liberty.input.impl;
12 import liberty.material.impl;
13 import liberty.math.transform;
14 import liberty.math.vector;
15 import liberty.model.impl;
16 import liberty.scene.constants;
17 import liberty.scene.services;
18 import liberty.framework.gui.impl;
19 
20 import liberty.scene.entity;
21 
22 /**
23  *
24 **/
25 class Widget : Entity {
26   private {
27     Gui gui;
28     Vector2I index;
29     int zIndex = 0;
30   }
31 
32   /**
33    *
34   **/
35   this(string id, Gui gui) {
36     super(id);
37     this.gui = gui;
38 
39     if (gui.getRootCanvas !is null)
40       gui.getRootCanvas.addWidget(this);
41   }
42 
43   /**
44    *
45   **/
46   final Gui getGui()   {
47     return gui;
48   }
49 
50   /**
51    *
52    * Returns reference to this so it can be used in a stream.
53   **/
54   typeof(this) setIndex(int x, int y)   {
55     return setIndex(Vector2I(x, y));
56   }
57 
58   /**
59    *
60    * Returns reference to this so it can be used in a stream.
61   **/
62   typeof(this) setIndex(Vector2I value)   {
63     index = value;
64     return this;
65   }
66 
67   /**
68    *
69   **/
70   final Vector2I getIndex()   {
71     return index;
72   }
73 
74   /**
75    *
76   **/
77   final bool isMouseColliding() {
78     Vector2F mousePos = Input.getMouse.getPostion;
79     return mousePos.x >= transform.getLocation.x - transform.getScale.x / 2 && 
80       mousePos.x <= transform.getLocation.x + transform.getScale.x / 2 && 
81       mousePos.y >= transform.getLocation.y - transform.getScale.y / 2 && 
82       mousePos.y <= transform.getLocation.y + transform.getScale.y / 2;
83   }
84 
85   /**
86    *
87    * Returns reference to this so it can be used in a stream.
88   **/
89   final typeof(this) setZIndex(int value)   {
90     zIndex = value;
91     return this;
92   }
93 
94   /**
95    *
96   **/
97   final int getZIndex()   const {
98     return zIndex;
99   }
100 
101   override void update() {}
102 }