Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8602 was 8518, checked in by bensch, 19 years ago

merged the gui back to the trunk

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