Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/lib/gui/gl/glgui_widget.h @ 8419

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

Better coloring sceme

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
[8419]37  {
[5366]38  public:
[8419]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;
[8144]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
[8419]94    void setFrontColor(const Color& frontColor) { this->_frontColor = frontColor; this->updateFrontColor(); };
[8378]95    const Color& frontColor() const { return this->_frontColor; };
[7868]96
[8115]97    /** @brief sets all borders to the same value. */
[8035]98    void setBorderSize(float borderSize);
[8115]99    void setBorderLeft(float borderLeft);
100    void setBorderRight(float borderRight);
101    void setBorderTop(float borderTop);
102    void setBorderBottom(float borderBottom);
[8035]103
[8115]104    float borderLeft() const { return this->_borderLeft; };
105    float borderRight() const { return this->_borderRight; };
106    float borderTop() const { return this->_borderTop; };
107    float borderBottom() const { return this->_borderBottom; };
108
109
[8035]110    void setWidgetSize(const Vector2D& size);
111    void setWidgetSize(float x, float y);
112
113
114    void setBackgroundColor(float x, float y, float z) { this->backMaterial().setDiffuse(x,y,z); };
115
[8419]116    inline void drawRect(const Rect2D& rect) const
117    {
[8035]118      glBegin(GL_QUADS);
119      glTexCoord2i(0,0); glVertex2d(rect.left(), rect.top());
120      glTexCoord2i(0,1); glVertex2d(rect.left(), rect.bottom());
121      glTexCoord2i(1,1); glVertex2d(rect.right(), rect.bottom());
122      glTexCoord2i(1,0); glVertex2d(rect.right(), rect.top());
123      glEnd();
124    }
125
126
127    virtual void update() {};
128    virtual void draw() const;
129
[7919]130    /** @param the Event to process. @returns true if the Event has been consumed*/
[8148]131    virtual bool processEvent(const Event& event) { return false; };
[7919]132
[8419]133
[8035]134  protected:
135    /// LOOKS
136    virtual void resize();
[7919]137
[8115]138    virtual void hiding() {};
139    virtual void showing() {};
[8419]140    virtual void updateFrontColor() {};
141
142    inline void beginDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); };
143    inline void endDraw() const { glPopMatrix(); };
144
145    /// EVENTS
[8035]146    // if something was clickt on the GUI-widget.
147    virtual void clicking(const Vector2D& pos);
148    virtual void releasing(const Vector2D& pos);
[7919]149    virtual void receivedFocus();
150    virtual void removedFocus();
[5391]151
[7919]152    virtual void destroyed();
[5391]153
[7779]154  private:
155    void init();
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
[8378]164    Color                          _frontColor;
[7855]165
[8115]166    float                          _borderLeft;
167    float                          _borderRight;
168    float                          _borderTop;
169    float                          _borderBottom;
[3245]170
[8140]171    Vector2D                       _minSize;
172
[7919]173    /// EVENTS
174    bool                           _focusable;        //!< If this widget can receive focus.
175    bool                           _clickable;        //!< if this widget can be clicked upon.
[5391]176
[7919]177    bool                           _pushed;
178
[8035]179
180    static GLGuiWidget*            _selected;         //!< The currently selected Widget.
181    static GLGuiWidget*            _focused;          //!< The currently Focused Widget.
182
183    static GLGuiWidget*            _inputGrabber;     //!< The Widget that grabs input.
[7779]184  };
185}
[5362]186#endif /* _GLGUI_WIDGET_H */
Note: See TracBrowser for help on using the repository browser.