GUI.h
1 /*
2 
3 Copyright (c) 2018, Johnathan Corkery. (jcorkery@umich.edu)
4 All rights reserved.
5 
6 This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
7 Dynacoe was released under the MIT License, as detailed below.
8 
9 
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is furnished
16 to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall
19 be included in all copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 
29 
30 
31 */
32 
33 #ifndef H_DC_GUI_COMPONENT_INCLUDED
34 #define H_DC_GUI_COMPONENT_INCLUDED
35 
36 #include <Dynacoe/Spatial.h>
37 #include <Dynacoe/Component.h>
38 
39 namespace Dynacoe {
40 
41 
52 class GUI : public Component, public Spatial {
53  public:
54  GUI();
55  ~GUI();
56 
57 
58 
59 
64  void DefineRegion(int w, int h);
65 
66 
67 
70  bool IsFocused();
71 
74  bool IsHovered();
75 
78  bool IsClicked();
79 
82  bool IsBeingDragged();
83 
84 
85 
90  void GrabInput();
91 
95  static void UngrabInput();
96 
101  void SetFocus();
102 
106  static void Unfocus();
107 
110  static bool IsFocusedClicked();
111 
112 
115  static bool IsFocusedHovered();
116 
117 
120  int GetRegionW();
121 
124  int GetRegionH();
125 
128  void SetTooltipText(const std::string & tooltip);
129 
132  const std::string & GetTooltipText() const;
133 
134 
135 
136  void OnStep();
137  std::string GetInfo();
138 
139  private:
140  void Initialize();
141  static GUI * focused;
142  static GUI * grabbed;
143  std::string tooltipText;
144  bool hovered;
145  int w, h;
146 };
147 
148 
149 
150 }
151 #endif
static bool IsFocusedClicked()
Convenience function to get whether the focused widget is clicked.
void DefineRegion(int w, int h)
Defines the input pointer region.
void SetFocus()
Sets this GUI to be the focused widget.
bool IsFocused()
Returns whether the GUI is focused view the SetFocus() function.
bool IsBeingDragged()
Returns whether the user's pointer is attempting to drag the region.
void GrabInput()
Attempts to grab the input focus for this GUI.
void OnStep()
Function that is called upon each Run iteration. Component Run()s are run before the entity's run fun...
const std::string & GetTooltipText() const
Returns the currently set tooltip text. The default is the empty string.
Definition: AssetID.h:37
std::string GetInfo()
Returns a string containing human-readable information on the state of the component.
int GetRegionH()
Returns the height of the defined region.
bool IsClicked()
Returns whether the user's pointer clicked within this GUI's region this frame.
A component that provides managed input interaction suitable for making things like buttons...
Definition: GUI.h:52
static void UngrabInput()
Ungrabs the GUI that has grabbed input.
static bool IsFocusedHovered()
Convenience function to get whether the focused widget is hovered.
static void Unfocus()
Unsets the current;y focused widget.
void SetTooltipText(const std::string &tooltip)
Sets text to appear if the pointer is above it.
Class that extends the functionality of an Entity, but as a removable and addable object...
Definition: Component.h:66
bool IsHovered()
Returns whether user's pointer is over this GUI's region this frame.
int GetRegionW()
Returns the width of the defined region.