Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/lib/gui/gl_gui/glgui_widget.h @ 8002

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

gui: multiple Connections also work

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