Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gl/glgui_widget.h @ 8774

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

orxonox/trunk: Font in Button-Widget used

File size: 13.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
[8619]11#include "glgui_defs.h"
12
[6295]13#include "material.h"
[8769]14#include "font.h"
15
[8448]16#include "rect2D.h"
[6295]17
[7919]18#include "event.h"
[7779]19#include "signal_connector.h"
[5690]20
[7779]21namespace OrxGui
[5391]22{
23
[7919]24  class GLGuiCursor;
25
[5387]26
[7779]27  //! This is widget part of the openglGUI class
28  /**
29   * A widget is the main class of all the elements of th GUI.
30   */
31  class GLGuiWidget : public Element2D
[8448]32  {
[5366]33  public:
[8035]34    GLGuiWidget(GLGuiWidget* parent = NULL);
[5366]35    virtual ~GLGuiWidget();
[2036]36
[5366]37    void show();
[6431]38    void hide();
[5364]39
[8035]40    void setParentWidget(GLGuiWidget* parent);
41    GLGuiWidget* parent() const { return this->_parent; }
[7868]42
[7919]43    /// FOCUS
[8717]44    /** @brief gives mouse - focus to this widget */
45    void giveMouseFocus();
46    void breakMouseFocus();
47
[7919]48    /** @returns true if the widget is focusable */
49    bool focusable() const { return this->_focusable; };
50    /** @returns true if the position is inside of the Widget. @param position the position to check */
51    bool focusOverWidget(const Vector2D& position) const;
52    /** @brief overloaded function, that returns true if the cursor is on top of the Widget */
53    bool focusOverWidget(const OrxGui::GLGuiCursor* const cursor) const;
54
[8717]55    /** @returns the currently mouse - focused Widget (NULL if none is focused). */
56    static GLGuiWidget* mouseFocused() { return GLGuiWidget::_mouseFocused; };
[7919]57
[8717]58    /// SELECT
59    void select();
60    void unselect();
61    /** @returns true if the Widget is selectable */
62    bool selectable() const { return this->_selectable; }
[7919]63
[8717]64    /** @returns the currently Selected Widget (NULL if none is selected). */
65    static GLGuiWidget* selected() { return GLGuiWidget::_selected; };
66
[7919]67    /// CLICK
[8717]68    bool pushed() { return _pushed; };
[8035]69    void click(const Vector2D& pos);
70    void release(const Vector2D& pos);
[7919]71    bool clickable() const { return this->_clickable; };
72
[8035]73    static void connect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver, Slot executor);
74    void connect(Signal& signal, BaseObject* receiver, Slot executor);
[7868]75
[8035]76    void disconnect(GLGuiWidget* sender, Signal& signal, BaseObject* receiver);
[7919]77
[8619]78    OrxGui::State state() const { return this->_state; };
[8035]79
80    Rect2D& backRect() { return this->_backRect; };
81    const Rect2D& backRect() const { return this->_backRect; };
[7868]82
[8448]83    void setFrontColor(const Color& frontColor, bool instantaniously = false);
[7868]84
[8619]85    void setWidgetSize(const Vector2D& size);
86    void setWidgetSize(float x, float y);
[8035]87
[8619]88    void animateBack();
[8115]89
[8717]90    ///////////////////////////////////////////////////////////////////////////////////
91    /// STYLE /////////////////////////////////////////////////////////////////////////
[8619]92    ////////////////////////////////
93    /// Retrieve Current Values. ///
94    ////////////////////////////////
95    /** @returns current left borderWidth */
96    inline float borderLeft() const { return _currentStyle._borderLeft; }
97    /** @returns current right borderWidth */
98    inline float borderRight() const { return _currentStyle._borderRight; }
99    /** @returns current top borderWidth */
100    inline float borderTop() const { return _currentStyle._borderTop; }
101    /** @returns burrent bottom borderWidth */
102    inline float borderBottom() const { return _currentStyle._borderBottom; }
[8115]103
[8035]104
[8619]105    /** @returns current textSize */
106    inline float textSize() const { return _currentStyle._textSize; }
107    /** @returns the Background Color */
108    inline const Color& backgroundColor() const { return _currentStyle._background.diffuseColor(); }
109    /** @returns the current Background Material. */
110    inline const Material& background() const { return _currentStyle._background; }
111    /** @returns the current background Texture. */
112    inline const Texture& backgroundTexture() const { return _currentStyle._background.diffuseTexture(); }
113    /** @returns the current foreground Color */
114    inline const Color& foregroundColor() const { return _currentStyle._foreground.diffuseColor(); }
115    /** @returns the current ForeGroung Material. */
116    inline const Material& foreground() const { return _currentStyle._foreground; }
[8035]117
118
[8619]119    /** @returns FeaturePosition */
120    inline FeaturePosition featurePosition() const { return _featurePosition; }
121    /** @returns the font */
[8769]122    inline const Font& font() const { return _font; }
[8619]123    /** @returns true if the Element is Animated */
124    inline bool animating() const { return _animating; }
125    /** @returns true if State-Changes are animated */
126    inline bool animatedStateChanges() const { return _animatedStateChanges; }
127
128
129    ///////////////////////////////////////////////////////////////
130    /// Retrieve Values for the Saved Values inside the States. ///
131    ///////////////////////////////////////////////////////////////
132    /** @returns left borderWidth @param state the State to retrieve from */
133    inline float borderLeft(OrxGui::State state) const { return _style[state]._borderLeft; }
134    /** @returns right borderWidth @param state the State to retrieve from */
135    inline float borderRight(OrxGui::State state) const { return _style[state]._borderRight; }
136    /** @returns top borderWidth @param state the State to retrieve from */
137    inline float borderTop(OrxGui::State state) const { return _style[state]._borderTop; }
138    /** @returns bottom borderWidth @param state the State to retrieve from */
139    inline float borderBottom(OrxGui::State state) const { return _style[state]._borderBottom; }
140
141    /** @returns textSize @param state the State to retrieve from */
142    inline float textSize(OrxGui::State state) const { return _style[state]._textSize; }
143    /** @returns the Background Color @param state the State to retrieve from */
144    inline const Color& backgroundColor(OrxGui::State state) const { return _style[state]._background.diffuseColor(); }
145    /** @returns the Background Material. @param state the state to retrieve from */
146    inline const Material& background(OrxGui::State state) const { return _style[state]._background; }
147    /** @returns background Texture. @param state the State to retrieve from */
148    inline const Texture& backgroundTexture(OrxGui::State state) const { return _style[state]._background.diffuseTexture(); }
149    /** @returns the foreground Color @param state the State to retrieve from */
150    inline const Color& foregroundColor(OrxGui::State state) const { return _style[state]._foreground.diffuseColor(); }
151    /** @returns the ForeGroung Material. @param state the state to retrieve from */
152    inline const Material& foreground(OrxGui::State state) const { return _style[state]._foreground; }
153
154
155    /// SETUP
156    void resetStyle();
157    void loadParams(const TiXmlElement* root);
158
159    void setBorderLeft(float value);
160    void setBorderLeft(float value, OrxGui::State state);
161    void setBorderLeftS(float value, const std::string& stateName);
162
163    void setBorderRight(float value);
164    void setBorderRight(float value, OrxGui::State state);
165    void setBorderRightS(float value, const std::string& stateName);
166
167    void setBorderTop(float value);
168    void setBorderTop(float value, OrxGui::State state);
169    void setBorderTopS(float value, const std::string& stateName);
170
171    void setBorderBottom(float value);
172    void setBorderBottom(float value, OrxGui::State state);
173    void setBorderBottomS(float value, const std::string& stateName);
174
175    void setTextSize(float value);
176    void setTextSize(float value, OrxGui::State state);
177    void setTextSizeS(float value, const std::string& stateName);
178
179    void setBackgroundColor(const Color& color);
180    void setBackgroundColor(const Color& color, OrxGui::State state);
181    void setBackgroundColorS(float r, float g, float b, float a, const std::string& stateName);
182
183    void setBackgroundTexture(const Texture& texture);
184    void setBackgroundTexture(const std::string& textureName);
185    void setBackgroundTexture(const Texture& texture, OrxGui::State state);
186    void setBackgroundTexture(const std::string& textureName, const std::string& stateName);
187
188    void setForegroundColor(const Color& color);
189    void setForegroundColor(const Color& color, OrxGui::State state);
190    void setForegroundColorS(float r, float g, float b, float a, const std::string& stateName);
191
192    void loadBackgroundMaterial(const Material& material);
193    void loadBackgroundMaterial(const Material& material, OrxGui::State state);
194    void loadBackgroundMaterial(const TiXmlElement* element);
195    void loadBackgroundMaterial(const TiXmlElement* element, OrxGui::State state);
196    void loadBackgroundMaterialS(const TiXmlElement* element, const std::string& stateName);
197
198    void loadForegroundMaterial(const Material& material);
199    void loadForegroundMaterial(const Material& material, OrxGui::State state);
200    void loadForegroundMaterial(const TiXmlElement* element, OrxGui::State state);
201    void loadForegroundMaterialS(const TiXmlElement* element, const std::string& stateName);
202
203    void setFeaturePosition(FeaturePosition featurePosition);
204    void setFeaturePositionS(const std::string& featurePosition);
205
[8769]206    void setFont(const Font& font);
207    void setFont(const std::string& fontName, unsigned int renderSize);
[8619]208
209    void setAnimatedStateChanges(bool animated);
210    void switchState(OrxGui::State state);
[8717]211    ///////////////////////////////////////////////////////////////////////////////////
[8619]212
213
[8448]214    inline void drawRect(const Rect2D& rect) const
215    {
[8035]216      glBegin(GL_QUADS);
217      glTexCoord2i(0,0); glVertex2d(rect.left(), rect.top());
218      glTexCoord2i(0,1); glVertex2d(rect.left(), rect.bottom());
219      glTexCoord2i(1,1); glVertex2d(rect.right(), rect.bottom());
220      glTexCoord2i(1,0); glVertex2d(rect.right(), rect.top());
221      glEnd();
222    }
223
224
225    virtual void update() {};
[8448]226    virtual void tick(float dt);
[8035]227    virtual void draw() const;
228
[7919]229    /** @param the Event to process. @returns true if the Event has been consumed*/
[8148]230    virtual bool processEvent(const Event& event) { return false; };
[7919]231
[8619]232    bool getState(const std::string& stateName, OrxGui::State* state);
[8448]233
[8035]234  protected:
[8717]235    /** @param focusable sets if the Widget should be focusable */
236    void setFocusable(bool focusable = true) { this->_focusable = focusable; };
237    /** @param selectable true if the widget should be selectable */
238    void setSelectable(bool selectable) { this->_selectable = selectable; }
239    /** @param focusable true if the widget should be focusable */
240    void setClickable(bool clickable = true) { this->_clickable = clickable; };
241
242
243    /// RENDERING
244    inline void beginDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); };
245    inline void endDraw() const { glPopMatrix(); };
246
247
[8035]248    /// LOOKS
249    virtual void resize();
[7919]250
[8115]251    virtual void hiding() {};
252    virtual void showing() {};
[8717]253
[8448]254    virtual void updateFrontColor() {};
255
256
257    /// EVENTS
[8717]258    // mouse clicking
[8035]259    virtual void clicking(const Vector2D& pos);
[8717]260    virtual void releasing(const Vector2D& pos, bool focused);
261    // mouse focusing
[7919]262    virtual void receivedFocus();
263    virtual void removedFocus();
[8717]264    // selecting either with the mouse by clicking, or by the keybord traversing to it.
265    virtual void selecting();
266    virtual void unselecting();
267    // destroying the Widget.
268    virtual void destroying();
[5391]269
270
[8717]271    virtual void debug(unsigned int level) const;
[8619]272
[7779]273  private:
274    void init();
275
[7919]276  private:
[8619]277    static GLGuiWidget*            _selected;         //!< The currently selected Widget.
[8717]278    static GLGuiWidget*            _mouseFocused;     //!< The currently Focused Widget (mouse-focus).
279    static GLGuiWidget*            _inputGrabber;     //!< The Widget that grabs input (keyboard-focus).
[8619]280
281
282    /// WIDGET
[8035]283    GLGuiWidget*                   _parent;           //!< The parent of this Widget.
284
[7919]285    /// LOOKS
[8035]286    Rect2D                         _backRect;
[8140]287    Vector2D                       _minSize;
288
[8448]289
[7919]290    /// EVENTS
[8619]291    OrxGui::State                  _state;
[8717]292    bool                           _pushed;
[8619]293
[7919]294    bool                           _focusable;        //!< If this widget can receive focus.
295    bool                           _clickable;        //!< if this widget can be clicked upon.
[8717]296    bool                           _selectable;       //!< If this widget can be selected.
[5391]297
[7919]298
[8035]299
300
[8619]301    /// STYLE - Variables.
302    typedef struct
303    {
[8717]304      float                        _borderLeft;           //!< The Distance to the left Border of the widget, before any internal Element starts.
305      float                        _borderRight;          //!< The Distance to the right Border of the widget, before any internal Element starts.
306      float                        _borderTop;            //!< The Distance to the top Border of the widget, before any internal Element starts
307      float                        _borderBottom;         //!< The Distance to the bottom Border of the widget, before any internal Element starts
[8619]308
[8717]309      float                        _textSize;             //!< The TextSize of the Widget.
[8619]310
[8717]311      Material                     _background;           //!< The Background Material of the Widget.
[8619]312
[8717]313      Material                     _foreground;           //!< The foreground Material of the Widget.
[8619]314    }
315    StatedStyle;
316
317
[8717]318    StatedStyle                    _style[GLGUI_STATE_COUNT]; //!< Styles configured for different States
[8619]319
[8717]320    FeaturePosition                _featurePosition;      //!< The Position a Feature will be layed at (checkbox(box), slider(text),...)
[8769]321    Font                           _font;                 //!< The Font used in the current Widget.
[8619]322
323
324    /// ANIMATION STUFF:
[8717]325    bool                           _animatedStateChanges; //!< If the Transitions between States are Animated automatically.
[8619]326
[8717]327    bool                           _animating;            //!< If the Widget is animated at the moment (Texture might be an AnimatedTexture.)
328    float                          _animationCycle;
329    float                          _animationDuration;
330    StatedStyle                    _currentStyle;
[8619]331
[7779]332  };
333}
[5362]334#endif /* _GLGUI_WIDGET_H */
Note: See TracBrowser for help on using the repository browser.