Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gl/glgui_widget.h @ 8312

Last change on this file since 8312 was 8312, checked in by bensch, 18 years ago

trunk: merged the water-branche back here
removed the HACK in GameWorld in the Process (hope it is not needed anymore…

merged with command:
svn merge https://svn.orxonox.net/orxonoanches/water/src/lib/gui/gl_gui src/lib/gui/gl/ -r8063:HEAD

File size: 5.8 KB
Line 
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
22class Material;
23
24namespace OrxGui
25{
26
27  class GLGuiCursor;
28
29  //! if the Element should be visible by default.
30#define GLGUI_WIDGET_DEFAULT_VISIBLE       false
31
32  //! This is widget part of the openglGUI class
33  /**
34   * A widget is the main class of all the elements of th GUI.
35   */
36  class GLGuiWidget : public Element2D
37{
38  public:
39  //! An enumerator that defines the different states Widgets may be in.
40  typedef enum {
41    Normal,           //!< Normal state of the GUI's Widgets.
42    Active,           //!< If the widget is Active.
43    Selected,         //!< If the Widget is Selected.
44    Insensitive       //!< If the Widget is insensitive.
45  } State;
46
47
48
49  public:
50    GLGuiWidget(GLGuiWidget* parent = NULL);
51    virtual ~GLGuiWidget();
52
53    void show();
54    void hide();
55
56    void setParentWidget(GLGuiWidget* parent);
57    GLGuiWidget* parent() const { return this->_parent; }
58
59    /// FOCUS
60    /** @brief gives focus to this widget */
61    void giveFocus();
62    void breakFocus();
63    /** @returns true if the widget is focusable */
64    bool focusable() const { return this->_focusable; };
65    /** @param focusable sets if the Widget should be focusable */
66    void setFocusable(bool focusable = true) { this->_focusable = focusable; };
67    /** @returns true if the position is inside of the Widget. @param position the position to check */
68    bool focusOverWidget(const Vector2D& position) const;
69    /** @brief overloaded function, that returns true if the cursor is on top of the Widget */
70    bool focusOverWidget(const OrxGui::GLGuiCursor* const cursor) const;
71
72    /** @returns the currently focused Widget (NULL if none is selected) */
73    static GLGuiWidget* focused() { return GLGuiWidget::_focused; };
74
75
76    /// CLICK
77    void click(const Vector2D& pos);
78    void release(const Vector2D& pos);
79    bool clickable() const { return this->_clickable; };
80    void setClickable(bool clickable = true) { this->_clickable = clickable; };
81
82    static void connect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver, Slot executor);
83    void connect(Signal& signal, BaseObject* receiver, Slot executor);
84
85    void disconnect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver);
86
87
88    /// MATERIAL (looks)
89    Material& backMaterial() { return this->_backMat; };
90    const Material& backMaterial() const { return this->_backMat; };
91    Rect2D& backRect() { return this->_backRect; };
92    const Rect2D& backRect() const { return this->_backRect; };
93
94    Material& frontMaterial() { return this->_frontMat; };
95    const Material& frontMaterial() const { return this->_frontMat; };
96    Rect2D& frontRect() { return this->_frontRect; };
97    const Rect2D& frontRect() const { return this->_frontRect; };
98
99    /** @brief sets all borders to the same value. */
100    void setBorderSize(float borderSize);
101    void setBorderLeft(float borderLeft);
102    void setBorderRight(float borderRight);
103    void setBorderTop(float borderTop);
104    void setBorderBottom(float borderBottom);
105
106    float borderLeft() const { return this->_borderLeft; };
107    float borderRight() const { return this->_borderRight; };
108    float borderTop() const { return this->_borderTop; };
109    float borderBottom() const { return this->_borderBottom; };
110
111
112    void setWidgetSize(const Vector2D& size);
113    void setWidgetSize(float x, float y);
114
115
116    void setBackgroundColor(float x, float y, float z) { this->backMaterial().setDiffuse(x,y,z); };
117
118    inline void drawRect(const Rect2D& rect) const {
119      glBegin(GL_QUADS);
120      glTexCoord2i(0,0); glVertex2d(rect.left(), rect.top());
121      glTexCoord2i(0,1); glVertex2d(rect.left(), rect.bottom());
122      glTexCoord2i(1,1); glVertex2d(rect.right(), rect.bottom());
123      glTexCoord2i(1,0); glVertex2d(rect.right(), rect.top());
124      glEnd();
125    }
126
127
128    virtual void update() {};
129    virtual void draw() const;
130
131    /** @param the Event to process. @returns true if the Event has been consumed*/
132    virtual bool processEvent(const Event& event) { return false; };
133
134  protected:
135
136    /// LOOKS
137    virtual void resize();
138
139    virtual void hiding() {};
140    virtual void showing() {};
141    // if something was clickt on the GUI-widget.
142    virtual void clicking(const Vector2D& pos);
143    virtual void releasing(const Vector2D& pos);
144    virtual void receivedFocus();
145    virtual void removedFocus();
146
147    virtual void destroyed();
148
149
150    inline void beginDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); };
151    inline void endDraw() const { glPopMatrix(); };
152
153  private:
154    void init();
155
156
157  private:
158    GLGuiWidget*                   _parent;           //!< The parent of this Widget.
159
160    /// LOOKS
161    Material                       _backMat;
162    Rect2D                         _backRect;
163
164    Material                       _frontMat;
165    Rect2D                         _frontRect;
166
167    float                          _borderLeft;
168    float                          _borderRight;
169    float                          _borderTop;
170    float                          _borderBottom;
171
172    Vector2D                       _minSize;
173
174    /// EVENTS
175    bool                           _focusable;        //!< If this widget can receive focus.
176    bool                           _clickable;        //!< if this widget can be clicked upon.
177
178    bool                           _pushed;
179
180
181    static GLGuiWidget*            _selected;         //!< The currently selected Widget.
182    static GLGuiWidget*            _focused;          //!< The currently Focused Widget.
183
184    static GLGuiWidget*            _inputGrabber;     //!< The Widget that grabs input.
185  };
186}
187#endif /* _GLGUI_WIDGET_H */
Note: See TracBrowser for help on using the repository browser.