Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Better coloring sceme

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    void setFrontColor(const Color& frontColor) { this->_frontColor = frontColor; this->updateFrontColor(); };
95    const Color& frontColor() const { return this->_frontColor; };
96
97    /** @brief sets all borders to the same value. */
98    void setBorderSize(float borderSize);
99    void setBorderLeft(float borderLeft);
100    void setBorderRight(float borderRight);
101    void setBorderTop(float borderTop);
102    void setBorderBottom(float borderBottom);
103
104    float borderLeft() const { return this->_borderLeft; };
105    float borderRight() const { return this->_borderRight; };
106    float borderTop() const { return this->_borderTop; };
107    float borderBottom() const { return this->_borderBottom; };
108
109
110    void setWidgetSize(const Vector2D& size);
111    void setWidgetSize(float x, float y);
112
113
114    void setBackgroundColor(float x, float y, float z) { this->backMaterial().setDiffuse(x,y,z); };
115
116    inline void drawRect(const Rect2D& rect) const
117    {
118      glBegin(GL_QUADS);
119      glTexCoord2i(0,0); glVertex2d(rect.left(), rect.top());
120      glTexCoord2i(0,1); glVertex2d(rect.left(), rect.bottom());
121      glTexCoord2i(1,1); glVertex2d(rect.right(), rect.bottom());
122      glTexCoord2i(1,0); glVertex2d(rect.right(), rect.top());
123      glEnd();
124    }
125
126
127    virtual void update() {};
128    virtual void draw() const;
129
130    /** @param the Event to process. @returns true if the Event has been consumed*/
131    virtual bool processEvent(const Event& event) { return false; };
132
133
134  protected:
135    /// LOOKS
136    virtual void resize();
137
138    virtual void hiding() {};
139    virtual void showing() {};
140    virtual void updateFrontColor() {};
141
142    inline void beginDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); };
143    inline void endDraw() const { glPopMatrix(); };
144
145    /// EVENTS
146    // if something was clickt on the GUI-widget.
147    virtual void clicking(const Vector2D& pos);
148    virtual void releasing(const Vector2D& pos);
149    virtual void receivedFocus();
150    virtual void removedFocus();
151
152    virtual void destroyed();
153
154  private:
155    void init();
156
157  private:
158    GLGuiWidget*                   _parent;           //!< The parent of this Widget.
159
160    /// LOOKS
161    Material                       _backMat;
162    Rect2D                         _backRect;
163
164    Color                          _frontColor;
165
166    float                          _borderLeft;
167    float                          _borderRight;
168    float                          _borderTop;
169    float                          _borderBottom;
170
171    Vector2D                       _minSize;
172
173    /// EVENTS
174    bool                           _focusable;        //!< If this widget can receive focus.
175    bool                           _clickable;        //!< if this widget can be clicked upon.
176
177    bool                           _pushed;
178
179
180    static GLGuiWidget*            _selected;         //!< The currently selected Widget.
181    static GLGuiWidget*            _focused;          //!< The currently Focused Widget.
182
183    static GLGuiWidget*            _inputGrabber;     //!< The Widget that grabs input.
184  };
185}
186#endif /* _GLGUI_WIDGET_H */
Note: See TracBrowser for help on using the repository browser.