Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged gui back to the trunk
merged with command
merge -r8377:HEAD https://svn.orxonox.net/orxonox/branches/gui .

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