Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8203 was 8148, checked in by bensch, 19 years ago

trunk: output of EventListener Nicer

File size: 5.8 KB
RevLine 
[4838]1/*!
[5391]2 * @file glgui_widget.h
3 * The gl_widget of the openglGUI
4 */
[1853]5
[5362]6#ifndef _GLGUI_WIDGET_H
7#define _GLGUI_WIDGET_H
[1853]8
[5362]9#include "element_2d.h"
[7919]10#include "rect2D.h"
11
[6295]12#include "material.h"
13
[7919]14#include "event.h"
[7779]15#include "signal_connector.h"
[5690]16
[7919]17#include "glincl.h"
18
19#include <vector>
20
[4838]21// FORWARD DECLARATION
[5365]22class Material;
[3543]23
[7779]24namespace OrxGui
[5391]25{
26
[7919]27  class GLGuiCursor;
28
[7779]29  //! if the Element should be visible by default.
[5387]30#define GLGUI_WIDGET_DEFAULT_VISIBLE       false
31
[7779]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
[8144]37{
[5366]38  public:
[8144]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:
[8035]50    GLGuiWidget(GLGuiWidget* parent = NULL);
[5366]51    virtual ~GLGuiWidget();
[2036]52
[5366]53    void show();
[6431]54    void hide();
[5364]55
56
[8035]57    void setParentWidget(GLGuiWidget* parent);
58    GLGuiWidget* parent() const { return this->_parent; }
[7868]59
[7919]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
[8035]78    void click(const Vector2D& pos);
79    void release(const Vector2D& pos);
[7919]80    bool clickable() const { return this->_clickable; };
81    void setClickable(bool clickable = true) { this->_clickable = clickable; };
82
[8035]83    static void connect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver, Slot executor);
84    void connect(Signal& signal, BaseObject* receiver, Slot executor);
[7868]85
[8035]86    void disconnect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver);
[7919]87
[8035]88
[7919]89    /// MATERIAL (looks)
[8035]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; };
[7868]94
[8035]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; };
[7868]99
[8115]100    /** @brief sets all borders to the same value. */
[8035]101    void setBorderSize(float borderSize);
[8115]102    void setBorderLeft(float borderLeft);
103    void setBorderRight(float borderRight);
104    void setBorderTop(float borderTop);
105    void setBorderBottom(float borderBottom);
[8035]106
[8115]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
[8035]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
[7919]132    /** @param the Event to process. @returns true if the Event has been consumed*/
[8148]133    virtual bool processEvent(const Event& event) { return false; };
[7919]134
[8035]135  protected:
[7919]136
[8035]137    /// LOOKS
138    virtual void resize();
[7919]139
[8115]140    virtual void hiding() {};
141    virtual void showing() {};
[8035]142    // if something was clickt on the GUI-widget.
143    virtual void clicking(const Vector2D& pos);
144    virtual void releasing(const Vector2D& pos);
[7919]145    virtual void receivedFocus();
146    virtual void removedFocus();
[5391]147
[7919]148    virtual void destroyed();
[5391]149
[7855]150
[8035]151    inline void beginDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); };
[6287]152    inline void endDraw() const { glPopMatrix(); };
153
[7779]154  private:
155    void init();
156
[7855]157
[7919]158  private:
[8035]159    GLGuiWidget*                   _parent;           //!< The parent of this Widget.
160
[7919]161    /// LOOKS
[8035]162    Material                       _backMat;
163    Rect2D                         _backRect;
[7855]164
[8035]165    Material                       _frontMat;
166    Rect2D                         _frontRect;
[7855]167
[8115]168    float                          _borderLeft;
169    float                          _borderRight;
170    float                          _borderTop;
171    float                          _borderBottom;
[3245]172
[8140]173    Vector2D                       _minSize;
174
[7919]175    /// EVENTS
176    bool                           _focusable;        //!< If this widget can receive focus.
177    bool                           _clickable;        //!< if this widget can be clicked upon.
[5391]178
[7919]179    bool                           _pushed;
180
[8035]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.
[7779]186  };
187}
[5362]188#endif /* _GLGUI_WIDGET_H */
Note: See TracBrowser for help on using the repository browser.