1 | /*! |
---|
2 | * @file glgui_widget.h |
---|
3 | * The gl_widget of the openglGUI |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _GLGUI_WIDGET_H |
---|
7 | #define _GLGUI_WIDGET_H |
---|
8 | |
---|
9 | #include "element_2d.h" |
---|
10 | #include "rect2D.h" |
---|
11 | |
---|
12 | #include "material.h" |
---|
13 | |
---|
14 | #include "event.h" |
---|
15 | #include "signal_connector.h" |
---|
16 | |
---|
17 | #include "glincl.h" |
---|
18 | |
---|
19 | #include <vector> |
---|
20 | |
---|
21 | // FORWARD DECLARATION |
---|
22 | class Material; |
---|
23 | |
---|
24 | namespace OrxGui |
---|
25 | { |
---|
26 | typedef enum |
---|
27 | { |
---|
28 | Signal_click = 0, |
---|
29 | Signal_release, |
---|
30 | Signal_rollOn, |
---|
31 | Signal_rollOff, |
---|
32 | Signal_open, |
---|
33 | Signal_close, |
---|
34 | Signal_destroy, |
---|
35 | |
---|
36 | SignalCount, |
---|
37 | } SignalType; |
---|
38 | |
---|
39 | |
---|
40 | class GLGuiCursor; |
---|
41 | |
---|
42 | //! if the Element should be visible by default. |
---|
43 | #define GLGUI_WIDGET_DEFAULT_VISIBLE false |
---|
44 | |
---|
45 | //! This is widget part of the openglGUI class |
---|
46 | /** |
---|
47 | * A widget is the main class of all the elements of th GUI. |
---|
48 | */ |
---|
49 | class GLGuiWidget : public Element2D |
---|
50 | { |
---|
51 | |
---|
52 | private: |
---|
53 | |
---|
54 | public: |
---|
55 | GLGuiWidget(); |
---|
56 | virtual ~GLGuiWidget(); |
---|
57 | |
---|
58 | void show(); |
---|
59 | void hide(); |
---|
60 | |
---|
61 | /// INTERCONNECTIVITY |
---|
62 | void connectSignal(SignalType signalType, BaseObject* obj, const Executor* signal); |
---|
63 | void disconnectSignal(SignalType signalType); |
---|
64 | |
---|
65 | |
---|
66 | /// FOCUS |
---|
67 | /** @brief gives focus to this widget */ |
---|
68 | void giveFocus(); |
---|
69 | void breakFocus(); |
---|
70 | /** @returns true if the widget is focusable */ |
---|
71 | bool focusable() const { return this->_focusable; }; |
---|
72 | /** @param focusable sets if the Widget should be focusable */ |
---|
73 | void setFocusable(bool focusable = true) { this->_focusable = focusable; }; |
---|
74 | /** @returns true if the position is inside of the Widget. @param position the position to check */ |
---|
75 | bool focusOverWidget(const Vector2D& position) const; |
---|
76 | /** @brief overloaded function, that returns true if the cursor is on top of the Widget */ |
---|
77 | bool focusOverWidget(const OrxGui::GLGuiCursor* const cursor) const; |
---|
78 | |
---|
79 | /** @returns the currently focused Widget (NULL if none is selected) */ |
---|
80 | static GLGuiWidget* focused() { return GLGuiWidget::_focused; }; |
---|
81 | |
---|
82 | |
---|
83 | /// CLICK |
---|
84 | void click(); |
---|
85 | void release(); |
---|
86 | bool clickable() const { return this->_clickable; }; |
---|
87 | void setClickable(bool clickable = true) { this->_clickable = clickable; }; |
---|
88 | |
---|
89 | virtual void update() {}; |
---|
90 | virtual void draw() const; |
---|
91 | |
---|
92 | |
---|
93 | /// MATERIAL (looks) |
---|
94 | Material& backMaterial() { return this->backMat; }; |
---|
95 | const Material& backMaterial() const { return this->backMat; }; |
---|
96 | |
---|
97 | Material& frontMaterial() { return this->frontMat; }; |
---|
98 | const Material& frontMaterial() const { return this->frontMat; }; |
---|
99 | |
---|
100 | /** @param the Event to process. @returns true if the Event has been consumed*/ |
---|
101 | virtual bool processEvent(const Event& event) { }; |
---|
102 | |
---|
103 | |
---|
104 | DeclareSignal(testSignal, ()); |
---|
105 | |
---|
106 | protected: |
---|
107 | // if something was clickt on the GUI-widget. |
---|
108 | virtual void clicked(); |
---|
109 | virtual void released(); |
---|
110 | virtual void receivedFocus(); |
---|
111 | virtual void removedFocus(); |
---|
112 | |
---|
113 | virtual void destroyed(); |
---|
114 | |
---|
115 | |
---|
116 | inline void startDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); }; |
---|
117 | inline void endDraw() const { glPopMatrix(); }; |
---|
118 | |
---|
119 | private: |
---|
120 | void init(); |
---|
121 | |
---|
122 | |
---|
123 | private: |
---|
124 | /// LOOKS |
---|
125 | Material backMat; |
---|
126 | Rect2D backRect; |
---|
127 | |
---|
128 | Material frontMat; |
---|
129 | Rect2D frontRect; |
---|
130 | |
---|
131 | |
---|
132 | /// SIGNALS |
---|
133 | std::vector<SignalConnector> widgetSignals; |
---|
134 | |
---|
135 | /// EVENTS |
---|
136 | bool _focusable; //!< If this widget can receive focus. |
---|
137 | bool _clickable; //!< if this widget can be clicked upon. |
---|
138 | |
---|
139 | bool _pushed; |
---|
140 | |
---|
141 | static GLGuiWidget* _focused; |
---|
142 | static GLGuiWidget* _inputGrabber; |
---|
143 | }; |
---|
144 | } |
---|
145 | #endif /* _GLGUI_WIDGET_H */ |
---|