Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gl_gui/glgui_widget.h @ 8063

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

gui: merged the gui back to the trunk

File size: 4.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
37  {
[5366]38  public:
[8035]39    GLGuiWidget(GLGuiWidget* parent = NULL);
[5366]40    virtual ~GLGuiWidget();
[2036]41
[5366]42    void show();
[6431]43    void hide();
[5364]44
45
[8035]46    void setParentWidget(GLGuiWidget* parent);
47    GLGuiWidget* parent() const { return this->_parent; }
[7868]48
[7919]49    /// FOCUS
50    /** @brief gives focus to this widget */
51    void giveFocus();
52    void breakFocus();
53    /** @returns true if the widget is focusable */
54    bool focusable() const { return this->_focusable; };
55    /** @param focusable sets if the Widget should be focusable */
56    void setFocusable(bool focusable = true) { this->_focusable = focusable; };
57    /** @returns true if the position is inside of the Widget. @param position the position to check */
58    bool focusOverWidget(const Vector2D& position) const;
59    /** @brief overloaded function, that returns true if the cursor is on top of the Widget */
60    bool focusOverWidget(const OrxGui::GLGuiCursor* const cursor) const;
61
62    /** @returns the currently focused Widget (NULL if none is selected) */
63    static GLGuiWidget* focused() { return GLGuiWidget::_focused; };
64
65
66    /// CLICK
[8035]67    void click(const Vector2D& pos);
68    void release(const Vector2D& pos);
[7919]69    bool clickable() const { return this->_clickable; };
70    void setClickable(bool clickable = true) { this->_clickable = clickable; };
71
[8035]72    static void connect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver, Slot executor);
73    void connect(Signal& signal, BaseObject* receiver, Slot executor);
[7868]74
[8035]75    void disconnect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver);
[7919]76
[8035]77
[7919]78    /// MATERIAL (looks)
[8035]79    Material& backMaterial() { return this->_backMat; };
80    const Material& backMaterial() const { return this->_backMat; };
81    Rect2D& backRect() { return this->_backRect; };
82    const Rect2D& backRect() const { return this->_backRect; };
[7868]83
[8035]84    Material& frontMaterial() { return this->_frontMat; };
85    const Material& frontMaterial() const { return this->_frontMat; };
86    Rect2D& frontRect() { return this->_frontRect; };
87    const Rect2D& frontRect() const { return this->_frontRect; };
[7868]88
[8035]89    float borderSize() const { return this->_borderSize; };
90    void setBorderSize(float borderSize);
91
92    void setWidgetSize(const Vector2D& size);
93    void setWidgetSize(float x, float y);
94
95
96    void setBackgroundColor(float x, float y, float z) { this->backMaterial().setDiffuse(x,y,z); };
97
98    inline void drawRect(const Rect2D& rect) const {
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() {};
109    virtual void draw() const;
110
[7919]111    /** @param the Event to process. @returns true if the Event has been consumed*/
112    virtual bool processEvent(const Event& event) { };
113
[8035]114  protected:
[7919]115
[8035]116    /// LOOKS
117    virtual void resize();
[7919]118
[8035]119    // if something was clickt on the GUI-widget.
120    virtual void clicking(const Vector2D& pos);
121    virtual void releasing(const Vector2D& pos);
[7919]122    virtual void receivedFocus();
123    virtual void removedFocus();
[5391]124
[7919]125    virtual void destroyed();
[5391]126
[7855]127
[8035]128    inline void beginDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); };
[6287]129    inline void endDraw() const { glPopMatrix(); };
130
[7779]131  private:
132    void init();
133
[7855]134
[7919]135  private:
[8035]136    GLGuiWidget*                   _parent;           //!< The parent of this Widget.
137
[7919]138    /// LOOKS
[8035]139    Material                       _backMat;
140    Rect2D                         _backRect;
[7855]141
[8035]142    Material                       _frontMat;
143    Rect2D                         _frontRect;
[7855]144
[8035]145    float                          _borderSize;
[3245]146
[7919]147    /// EVENTS
148    bool                           _focusable;        //!< If this widget can receive focus.
149    bool                           _clickable;        //!< if this widget can be clicked upon.
[5391]150
[7919]151    bool                           _pushed;
152
[8035]153
154    static GLGuiWidget*            _selected;         //!< The currently selected Widget.
155    static GLGuiWidget*            _focused;          //!< The currently Focused Widget.
156
157    static GLGuiWidget*            _inputGrabber;     //!< The Widget that grabs input.
[7779]158  };
159}
[5362]160#endif /* _GLGUI_WIDGET_H */
Note: See TracBrowser for help on using the repository browser.