Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: merged the water-branche back here
removed the HACK in GameWorld in the Process (hope it is not needed anymore…

merged with command:
svn merge https://svn.orxonox.net/orxonoanches/water/src/lib/gui/gl_gui src/lib/gui/gl/ -r8063:HEAD

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