Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

gui: click and release work (internally)

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