Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7882 in orxonox.OLD


Ignore:
Timestamp:
May 27, 2006, 1:24:03 AM (18 years ago)
Author:
bensch
Message:

gui: remove-focus works

Location:
branches/gui/src/lib/gui/gl_gui
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/gui/src/lib/gui/gl_gui/glgui_button.cc

    r7875 r7882  
    5151  {
    5252    this->setClassID(CL_GLGUI_BUTTON, "GLGuiButton");
     53    this->setFocusable(true);
     54    this->setClickable(true);
    5355
    5456    this->label.setParent2D(this);
  • branches/gui/src/lib/gui/gl_gui/glgui_handler.cc

    r7881 r7882  
    107107      {
    108108        GLGuiWidget* widget = dynamic_cast<GLGuiWidget*>(*it);
    109         if (widget->isVisible() && widget->focusOverWidget(this->cursor->getAbsCoor2D().x, this->cursor->getAbsCoor2D().y))
     109
     110        if (widget->isVisible() &&
     111            widget->focusable() &&
     112            widget->focusOverWidget(this->cursor))
    110113        {
    111114          // receiving Focus
     
    113116          {
    114117            widget->giveFocus();
    115             printf("%s\n", widget->getClassName());
    116118          }
     119          return ;
    117120        }
    118121      }
     122      if (GLGuiWidget::focused() != NULL)
     123        GLGuiWidget::focused()->breakFocus();
    119124    }
    120125  }
  • branches/gui/src/lib/gui/gl_gui/glgui_widget.cc

    r7880 r7882  
    1717
    1818#include "glgui_widget.h"
     19
     20#include "glgui_cursor.h"
    1921
    2022#include "material.h"
     
    5355    this->setClassID(CL_GLGUI_WIDGET, "GLGuiWidget");
    5456
    55     this->focusable = true;
    56     this->clickable = true;
     57    this->_focusable = false;
     58    this->_clickable = false;
    5759    this->setVisibility(GLGUI_WIDGET_DEFAULT_VISIBLE);
    5860
     
    6567
    6668
    67   bool GLGuiWidget::focusOverWidget(float x, float y) const
     69  bool GLGuiWidget::focusOverWidget(const Vector2D& position) const
    6870  {
    69     if (this->getAbsCoor2D().x < x && this->getAbsCoor2D().x + this->getSizeX2D() > x &&
    70         this->getAbsCoor2D().y < y && this->getAbsCoor2D().y + this->getSizeY2D() > y)
    71       return true;
    72     else
    73       return false;
     71    return (this->getAbsCoor2D().x < position.x && this->getAbsCoor2D().x + this->getSizeX2D() > position.x &&
     72        this->getAbsCoor2D().y < position.y && this->getAbsCoor2D().y + this->getSizeY2D() > position.y);
    7473  }
     74
     75  bool GLGuiWidget::focusOverWidget(const GLGuiCursor* const cursor) const
     76  {
     77    return this->focusOverWidget(cursor->getAbsCoor2D());
     78  }
     79
    7580
    7681  /**
  • branches/gui/src/lib/gui/gl_gui/glgui_widget.h

    r7880 r7882  
    1919namespace OrxGui
    2020{
    21 
    2221  typedef enum
    2322  {
     
    3433
    3534
     35  class GLGuiCursor;
     36
    3637  //! if the Element should be visible by default.
    3738#define GLGUI_WIDGET_DEFAULT_VISIBLE       false
     
    4344  class GLGuiWidget : public Element2D
    4445  {
     46
    4547  private:
    4648
     
    5254    void hide();
    5355
    54     void giveFocus() { GLGuiWidget::_focused = this; this->receivedFocus(); };
    55 
     56    /// INTERCONNECTIVITY
    5657    void connectSignal(SignalType signalType, BaseObject* obj, const Executor* signal);
    5758    void disconnectSignal(SignalType signalType);
    58     bool focusOverWidget(float x, float y) const;
     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; };
    5981
    6082
     
    6284    virtual void draw() const;
    6385
     86
     87    /// MATERIAL (looks)
    6488    Material& backMaterial() { return this->backMat; };
    6589    const Material& backMaterial() const { return this->backMat; };
     
    7094
    7195
    72     static const GLGuiWidget* const focused() { return GLGuiWidget::_focused; };
    7396
    7497
     
    91114
    92115
    93 
    94 
    95116  protected:
    96117    Material                       backMat;
     
    103124    std::vector<SignalConnector>   widgetSignals;
    104125
    105     bool                           focusable;        //!< If this widget can receive focus.
    106     bool                           clickable;        //!< if this widget can be clicked upon.
     126    bool                           _focusable;        //!< If this widget can receive focus.
     127    bool                           _clickable;        //!< if this widget can be clicked upon.
    107128
    108129    static GLGuiWidget*            _focused;
Note: See TracChangeset for help on using the changeset viewer.