[4838] | 1 | /*! |
---|
[5391] | 2 | * @file glgui_widget.h |
---|
| 3 | * The gl_widget of the openglGUI |
---|
| 4 | */ |
---|
[1853] | 5 | |
---|
[5362] | 6 | #ifndef _GLGUI_WIDGET_H |
---|
| 7 | #define _GLGUI_WIDGET_H |
---|
[1853] | 8 | |
---|
[5362] | 9 | #include "element_2d.h" |
---|
[7919] | 10 | #include "rect2D.h" |
---|
| 11 | |
---|
[6295] | 12 | #include "material.h" |
---|
| 13 | |
---|
[7919] | 14 | #include "event.h" |
---|
[7779] | 15 | #include "signal_connector.h" |
---|
[5690] | 16 | |
---|
[7919] | 17 | #include "glincl.h" |
---|
| 18 | |
---|
| 19 | #include <vector> |
---|
| 20 | |
---|
[4838] | 21 | // FORWARD DECLARATION |
---|
[5365] | 22 | class Material; |
---|
[3543] | 23 | |
---|
[7779] | 24 | namespace OrxGui |
---|
[5391] | 25 | { |
---|
[7779] | 26 | typedef enum |
---|
| 27 | { |
---|
[7855] | 28 | Signal_click = 0, |
---|
| 29 | Signal_release, |
---|
| 30 | Signal_rollOn, |
---|
| 31 | Signal_rollOff, |
---|
| 32 | Signal_open, |
---|
| 33 | Signal_close, |
---|
| 34 | Signal_destroy, |
---|
[5391] | 35 | |
---|
[7855] | 36 | SignalCount, |
---|
| 37 | } SignalType; |
---|
[7779] | 38 | |
---|
[7855] | 39 | |
---|
[7919] | 40 | class GLGuiCursor; |
---|
| 41 | |
---|
[7779] | 42 | //! if the Element should be visible by default. |
---|
[5387] | 43 | #define GLGUI_WIDGET_DEFAULT_VISIBLE false |
---|
| 44 | |
---|
[7779] | 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 | { |
---|
[7919] | 51 | |
---|
[7779] | 52 | private: |
---|
| 53 | |
---|
[5366] | 54 | public: |
---|
| 55 | GLGuiWidget(); |
---|
| 56 | virtual ~GLGuiWidget(); |
---|
[2036] | 57 | |
---|
[5366] | 58 | void show(); |
---|
[6431] | 59 | void hide(); |
---|
[5364] | 60 | |
---|
[7919] | 61 | /// INTERCONNECTIVITY |
---|
[7855] | 62 | void connectSignal(SignalType signalType, BaseObject* obj, const Executor* signal); |
---|
| 63 | void disconnectSignal(SignalType signalType); |
---|
[5364] | 64 | |
---|
[7868] | 65 | |
---|
[7919] | 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 | |
---|
[7868] | 89 | virtual void update() {}; |
---|
| 90 | virtual void draw() const; |
---|
| 91 | |
---|
[7919] | 92 | |
---|
| 93 | /// MATERIAL (looks) |
---|
[7868] | 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 | |
---|
[7919] | 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 | |
---|
[7868] | 106 | protected: |
---|
| 107 | // if something was clickt on the GUI-widget. |
---|
[7919] | 108 | virtual void clicked(); |
---|
| 109 | virtual void released(); |
---|
| 110 | virtual void receivedFocus(); |
---|
| 111 | virtual void removedFocus(); |
---|
[5391] | 112 | |
---|
[7919] | 113 | virtual void destroyed(); |
---|
[5391] | 114 | |
---|
[7855] | 115 | |
---|
[6287] | 116 | inline void startDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); }; |
---|
| 117 | inline void endDraw() const { glPopMatrix(); }; |
---|
| 118 | |
---|
[7779] | 119 | private: |
---|
| 120 | void init(); |
---|
| 121 | |
---|
[7855] | 122 | |
---|
[7919] | 123 | private: |
---|
| 124 | /// LOOKS |
---|
| 125 | Material backMat; |
---|
| 126 | Rect2D backRect; |
---|
[7855] | 127 | |
---|
[7919] | 128 | Material frontMat; |
---|
| 129 | Rect2D frontRect; |
---|
[7855] | 130 | |
---|
[3245] | 131 | |
---|
[7919] | 132 | /// SIGNALS |
---|
| 133 | std::vector<SignalConnector> widgetSignals; |
---|
[5387] | 134 | |
---|
[7919] | 135 | /// EVENTS |
---|
| 136 | bool _focusable; //!< If this widget can receive focus. |
---|
| 137 | bool _clickable; //!< if this widget can be clicked upon. |
---|
[5391] | 138 | |
---|
[7919] | 139 | bool _pushed; |
---|
| 140 | |
---|
| 141 | static GLGuiWidget* _focused; |
---|
| 142 | static GLGuiWidget* _inputGrabber; |
---|
[7779] | 143 | }; |
---|
| 144 | } |
---|
[5362] | 145 | #endif /* _GLGUI_WIDGET_H */ |
---|