Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

gui: slider work

File size: 4.3 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  typedef enum
27  {
28    Signal_click     = 0,
29    Signal_release,
30    Signal_rollOn,
31    Signal_rollOff,
32    Signal_open,
33    Signal_close,
34    Signal_destroy,
35
36    SignalCount,
37  } SignalType;
38
39
40  class GLGuiCursor;
41
42  //! if the Element should be visible by default.
43#define GLGUI_WIDGET_DEFAULT_VISIBLE       false
44
45  //! This is widget part of the openglGUI class
46  /**
47   * A widget is the main class of all the elements of th GUI.
48   */
49  class GLGuiWidget : public Element2D
50  {
51
52  private:
53
54  public:
55    GLGuiWidget(GLGuiWidget* parent = NULL);
56    virtual ~GLGuiWidget();
57
58    void show();
59    void hide();
60
61    /// INTERCONNECTIVITY
62    void connectSignal(SignalType signalType, BaseObject* obj, const Executor* signal);
63    void disconnectSignal(SignalType signalType);
64
65
66    /// FOCUS
67    /** @brief gives focus to this widget */
68    void giveFocus();
69    void breakFocus();
70    /** @returns true if the widget is focusable */
71    bool focusable() const { return this->_focusable; };
72    /** @param focusable sets if the Widget should be focusable */
73    void setFocusable(bool focusable = true) { this->_focusable = focusable; };
74    /** @returns true if the position is inside of the Widget. @param position the position to check */
75    bool focusOverWidget(const Vector2D& position) const;
76    /** @brief overloaded function, that returns true if the cursor is on top of the Widget */
77    bool focusOverWidget(const OrxGui::GLGuiCursor* const cursor) const;
78
79    /** @returns the currently focused Widget (NULL if none is selected) */
80    static GLGuiWidget* focused() { return GLGuiWidget::_focused; };
81
82
83
84    /// CLICK
85    void click();
86    void release();
87    bool clickable() const { return this->_clickable; };
88    void setClickable(bool clickable = true) { this->_clickable = clickable; };
89
90
91    /// MATERIAL (looks)
92    Material& backMaterial() { return this->_backMat; };
93    const Material& backMaterial() const { return this->_backMat; };
94    Rect2D& backRect() { return this->_backRect; };
95    const Rect2D& backRect() const { return this->_backRect; };
96
97    Material& frontMaterial() { return this->_frontMat; };
98    const Material& frontMaterial() const { return this->_frontMat; };
99    Rect2D& frontRect() { return this->_frontRect; };
100    const Rect2D& frontRect() const { return this->_frontRect; };
101
102    inline void drawRect(const Rect2D& rect) const {
103      glBegin(GL_QUADS);
104      glTexCoord2i(0,0); glVertex2d(rect.left(), rect.top());
105      glTexCoord2i(0,1); glVertex2d(rect.left(), rect.bottom());
106      glTexCoord2i(1,1); glVertex2d(rect.right(), rect.bottom());
107      glTexCoord2i(1,0); glVertex2d(rect.right(), rect.top());
108      glEnd();
109    }
110
111
112    virtual void update() {};
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) { };
117
118
119    DeclareSignal(testSignal, ());
120
121
122
123  protected:
124
125    /// LOOKS
126    virtual void resize();
127
128    // if something was clickt on the GUI-widget.
129    virtual void clicked();
130    virtual void released();
131    virtual void receivedFocus();
132    virtual void removedFocus();
133
134    virtual void destroyed();
135
136
137    inline void beginDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); };
138    inline void endDraw() const { glPopMatrix(); };
139
140  private:
141    void init();
142
143
144  private:
145    /// LOOKS
146    Material                       _backMat;
147    Rect2D                         _backRect;
148
149    Material                       _frontMat;
150    Rect2D                         _frontRect;
151
152
153    /// SIGNALS
154    std::vector<SignalConnector>   widgetSignals;
155
156    /// EVENTS
157    bool                           _focusable;        //!< If this widget can receive focus.
158    bool                           _clickable;        //!< if this widget can be clicked upon.
159
160    bool                           _pushed;
161
162    static GLGuiWidget*            _focused;
163    static GLGuiWidget*            _inputGrabber;
164  };
165}
166#endif /* _GLGUI_WIDGET_H */
Note: See TracBrowser for help on using the repository browser.