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