Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/lib/gui/gl_gui/glgui_widget.h @ 8002

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

gui: multiple Connections also work

File size: 4.6 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    GLGuiWidget(GLGuiWidget* parent = NULL);
40    virtual ~GLGuiWidget();
41
42    void show();
43    void hide();
44
45
46    /// FOCUS
47    /** @brief gives focus to this widget */
48    void giveFocus();
49    void breakFocus();
50    /** @returns true if the widget is focusable */
51    bool focusable() const { return this->_focusable; };
52    /** @param focusable sets if the Widget should be focusable */
53    void setFocusable(bool focusable = true) { this->_focusable = focusable; };
54    /** @returns true if the position is inside of the Widget. @param position the position to check */
55    bool focusOverWidget(const Vector2D& position) const;
56    /** @brief overloaded function, that returns true if the cursor is on top of the Widget */
57    bool focusOverWidget(const OrxGui::GLGuiCursor* const cursor) const;
58
59    /** @returns the currently focused Widget (NULL if none is selected) */
60    static GLGuiWidget* focused() { return GLGuiWidget::_focused; };
61
62
63
64    /// CLICK
65    void click(const Vector2D& pos);
66    void release(const Vector2D& pos);
67    bool clickable() const { return this->_clickable; };
68    void setClickable(bool clickable = true) { this->_clickable = clickable; };
69
70    static void connect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver, Slot executor);
71    void connect(Signal& signal, BaseObject* receiver, Slot executor);
72
73    void disconnect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver);
74
75
76    /// MATERIAL (looks)
77    Material& backMaterial() { return this->_backMat; };
78    const Material& backMaterial() const { return this->_backMat; };
79    Rect2D& backRect() { return this->_backRect; };
80    const Rect2D& backRect() const { return this->_backRect; };
81
82    Material& frontMaterial() { return this->_frontMat; };
83    const Material& frontMaterial() const { return this->_frontMat; };
84    Rect2D& frontRect() { return this->_frontRect; };
85    const Rect2D& frontRect() const { return this->_frontRect; };
86
87    float borderSize() const { return this->_borderSize; };
88    void setBorderSize(float borderSize);
89
90
91    void setBackgroundColor(float x, float y, float z) { this->backMaterial().setDiffuse(x,y,z); };
92
93    inline void drawRect(const Rect2D& rect) const {
94      glBegin(GL_QUADS);
95      glTexCoord2i(0,0); glVertex2d(rect.left(), rect.top());
96      glTexCoord2i(0,1); glVertex2d(rect.left(), rect.bottom());
97      glTexCoord2i(1,1); glVertex2d(rect.right(), rect.bottom());
98      glTexCoord2i(1,0); glVertex2d(rect.right(), rect.top());
99      glEnd();
100    }
101
102
103    virtual void update() {};
104    virtual void draw() const;
105
106    /** @param the Event to process. @returns true if the Event has been consumed*/
107    virtual bool processEvent(const Event& event) { };
108
109  protected:
110
111    /// LOOKS
112    virtual void resize();
113
114    // if something was clickt on the GUI-widget.
115    virtual void clicking(const Vector2D& pos);
116    virtual void releasing(const Vector2D& pos);
117    virtual void receivedFocus();
118    virtual void removedFocus();
119
120    virtual void destroyed();
121
122
123    inline void beginDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); };
124    inline void endDraw() const { glPopMatrix(); };
125
126  private:
127    void init();
128
129
130  private:
131    /// LOOKS
132    Material                       _backMat;
133    Rect2D                         _backRect;
134
135    Material                       _frontMat;
136    Rect2D                         _frontRect;
137
138    float                          _borderSize;
139
140    /// EVENTS
141    bool                           _focusable;        //!< If this widget can receive focus.
142    bool                           _clickable;        //!< if this widget can be clicked upon.
143
144    bool                           _pushed;
145
146    static GLGuiWidget*            _selected;         //!< The currently selected Widget.
147    static GLGuiWidget*            _focused;          //!< The currently Focused Widget.
148
149    static GLGuiWidget*            _inputGrabber;     //!< The Widget that grabs input.
150  };
151}
152#endif /* _GLGUI_WIDGET_H */
Note: See TracBrowser for help on using the repository browser.