Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/lib/gui/gl/glgui_widget.h @ 8301

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

trunk: output of EventListener Nicer

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