Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

gui: added timer class for a more exact time

File size: 3.6 KB
Line 
1/*!
2 * @file glgui_widget.h
3 * The gl_widget of the openglGUI
4 */
5
6#ifndef _GLGUI_WIDGET_H
7#define _GLGUI_WIDGET_H
8
9#include "element_2d.h"
10#include "event.h"
11#include "material.h"
12
13#include "glincl.h"
14#include "signal_connector.h"
15#include <vector>
16
17// FORWARD DECLARATION
18class Material;
19
20namespace OrxGui
21{
22  typedef enum
23  {
24    Signal_click     = 0,
25    Signal_release,
26    Signal_rollOn,
27    Signal_rollOff,
28    Signal_open,
29    Signal_close,
30    Signal_destroy,
31
32    SignalCount,
33  } SignalType;
34
35
36  class GLGuiCursor;
37
38  //! if the Element should be visible by default.
39#define GLGUI_WIDGET_DEFAULT_VISIBLE       false
40
41  //! This is widget part of the openglGUI class
42  /**
43   * A widget is the main class of all the elements of th GUI.
44   */
45  class GLGuiWidget : public Element2D
46  {
47
48  private:
49
50  public:
51    GLGuiWidget();
52    virtual ~GLGuiWidget();
53
54    void show();
55    void hide();
56
57    /// INTERCONNECTIVITY
58    void connectSignal(SignalType signalType, BaseObject* obj, const Executor* signal);
59    void disconnectSignal(SignalType signalType);
60
61
62    /// FOCUS
63    /** @brief gives focus to this widget */
64    void giveFocus();
65    void breakFocus();
66    /** @returns true if the widget is focusable */
67    bool focusable() const { return this->_focusable; };
68    /** @param focusable sets if the Widget should be focusable */
69    void setFocusable(bool focusable = true) { this->_focusable = focusable; };
70    /** @returns true if the position is inside of the Widget. @param position the position to check */
71    bool focusOverWidget(const Vector2D& position) const;
72    /** @brief overloaded function, that returns true if the cursor is on top of the Widget */
73    bool focusOverWidget(const OrxGui::GLGuiCursor* const cursor) const;
74
75    /** @returns the currently focused Widget (NULL if none is selected) */
76    static GLGuiWidget* focused() { return GLGuiWidget::_focused; };
77
78
79    /// CLICK
80    void click();
81    void release();
82    bool clickable() const { return this->_clickable; };
83    void setClickable(bool clickable = true) { this->_clickable = clickable; };
84
85    virtual void update() {};
86    virtual void draw() const;
87
88
89    /// MATERIAL (looks)
90    Material& backMaterial() { return this->backMat; };
91    const Material& backMaterial() const { return this->backMat; };
92
93    Material& frontMaterial() { return this->frontMat; };
94    const Material& frontMaterial() const { return this->frontMat; };
95
96    /** @param the Event to process. @returns true if the Event has been consumed*/
97    virtual bool processEvent(const Event& event) { };
98
99
100    DeclareSignal(testSignal, ());
101
102  protected:
103        // if something was clickt on the GUI-widget.
104    virtual void clicked();
105    virtual void released();
106    virtual void receivedFocus();
107    virtual void removedFocus();
108
109    virtual void destroyed();
110
111
112    inline void startDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); };
113    inline void endDraw() const { glPopMatrix(); };
114
115  private:
116    void init();
117
118
119  protected:
120    Material                       backMat;
121    GLuint                         backModel;
122
123    Material                       frontMat;
124    GLuint                         frontModel;
125
126  private:
127    std::vector<SignalConnector>   widgetSignals;
128
129    bool                           _focusable;        //!< If this widget can receive focus.
130    bool                           _clickable;        //!< if this widget can be clicked upon.
131
132    bool                           _pushed;
133
134    static GLGuiWidget*            _focused;
135    static GLGuiWidget*            _inputGrabber;
136  };
137}
138#endif /* _GLGUI_WIDGET_H */
Note: See TracBrowser for help on using the repository browser.