Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8664 in orxonox.OLD for branches/gui/src


Ignore:
Timestamp:
Jun 21, 2006, 11:04:44 AM (18 years ago)
Author:
bensch
Message:

better handling

Location:
branches/gui/src/lib/gui/gl
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/gui/src/lib/gui/gl/glgui_handler.cc

    r8653 r8664  
    104104    {
    105105      case  EV_MOUSE_BUTTON_LEFT:
    106         if (GLGuiWidget::mouseFocused() != NULL)
     106        if (GLGuiWidget::mouseFocused() != NULL && event.bPressed)
    107107        {
    108           if (event.bPressed)
     108          // if clickable select the Widget.
     109          if (GLGuiWidget::mouseFocused()->clickable())
    109110          {
    110             if (GLGuiWidget::mouseFocused()->clickable())
    111             {
    112               Vector2D cursorPos = (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(event.x, event.y);
    113               GLGuiWidget::mouseFocused()->select();
    114               GLGuiWidget::mouseFocused()->click(cursorPos - GLGuiWidget::mouseFocused()->getAbsCoor2D());
    115             }
    116           }
    117           else
    118           {
    119             if (GLGuiWidget::mouseFocused()->clickable())
    120             {
    121               Vector2D cursorPos = (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(event.x, event.y);
    122               GLGuiWidget::mouseFocused()->release(cursorPos - GLGuiWidget::mouseFocused()->getAbsCoor2D());
    123             }
     111            Vector2D cursorPos = (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(event.x, event.y);
     112            GLGuiWidget::mouseFocused()->select();
     113            GLGuiWidget::selected()->click(cursorPos - GLGuiWidget::mouseFocused()->getAbsCoor2D());
    124114          }
    125115        }
     116        else if (GLGuiWidget::selected != NULL && !event.bPressed)
     117        {
     118          if (GLGuiWidget::selected()->clickable())
     119          {
     120            Vector2D cursorPos = (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(event.x, event.y);
     121            GLGuiWidget::selected()->release(cursorPos - GLGuiWidget::selected()->getAbsCoor2D());
     122          }
     123        }
     124
    126125        break;
    127126      case EV_LEAVE_STATE:
     127        if (GLGuiWidget::selected() != NULL)
     128          GLGuiWidget::selected()->unselect();
     129
    128130        if (GLGuiWidget::mouseFocused() != NULL)
    129131          GLGuiWidget::mouseFocused()->breakMouseFocus();
     
    138140
    139141
    140     if (GLGuiWidget::selected())
     142    if (GLGuiWidget::selected() != NULL)
    141143    {
    142144      GLGuiWidget::selected()->processEvent(event);
     
    178180  void GLGuiHandler::tick(float dt)
    179181  {
     182    // do not change if we already clicked into a Widget.
     183    if (GLGuiWidget::selected() != NULL && GLGuiWidget::selected()->clicked())
     184      return ;
    180185
    181186    // CHECK THE COLLISIONS.
  • branches/gui/src/lib/gui/gl/glgui_widget.cc

    r8653 r8664  
    9595    this->_pushed = false;
    9696    this->_state = OrxGui::Normal;
     97    this->_clicked = false;
    9798
    9899
     
    167168
    168169
     170  /**
     171   * @brief selects the Widget, unselecting the old one (if existing)
     172   */
    169173  void GLGuiWidget::select()
    170174  {
    171     if (GLGuiWidget::selected() != NULL)
     175    if (GLGuiWidget::_selected != NULL)
    172176      GLGuiWidget::selected()->unselect();
    173177    GLGuiWidget::_selected = this;
    174178  }
    175179
     180  /**
     181   * @brief unselects the current Widget.
     182   *
     183   * if the current Widget is not selected, nothing is done here.
     184   */
    176185  void GLGuiWidget::unselect()
    177186  {
    178     if (GLGuiWidget::selected() != this)
    179       _selected = NULL;
     187    if (GLGuiWidget::_selected != this)
     188      return;
     189
     190    GLGuiWidget::_selected = NULL;
    180191  }
    181192
     
    217228  void GLGuiWidget::clicking(const Vector2D& pos)
    218229  {
     230    this->_clicked = true;
    219231    this->switchState(OrxGui::Selected);
    220232  }
     
    222234  void GLGuiWidget::releasing(const Vector2D& pos)
    223235  {
     236    this->_clicked = false;
    224237    this->switchState(OrxGui::Normal);
    225238  }
     
    236249  }
    237250
    238   void GLGuiWidget::destroyed()
     251  void GLGuiWidget::selecting()
     252  {
     253    this->switchState(OrxGui::Selected);
     254  }
     255
     256  void GLGuiWidget::unselecting()
     257  {
     258    this->switchState(OrxGui::Normal);
     259  }
     260
     261
     262  void GLGuiWidget::destroying()
    239263  {}
    240264  ;
     
    737761  void GLGuiWidget::tick(float dt)
    738762  {
    739         if (this->_animating)
     763    if (this->_animating)
    740764    {
    741765      this->foregroundColor();
     
    778802    for (unsigned int i = 0; i < GLGUI_STATE_COUNT; ++i)
    779803      if (stateName == OrxGui::StateString[i])
    780     {
    781       *state = (OrxGui::State)i;
    782       return true;
    783     }
     804      {
     805        *state = (OrxGui::State)i;
     806        return true;
     807      }
    784808    return false;
    785809  }
     
    788812   * @brief print out some nice debug output about the Widget.
    789813   */
    790   void GLGuiWidget::debug() const
     814  void GLGuiWidget::debug(unsigned int level) const
    791815  {
    792816    PRINT(0)("Debug of %s::%s - WidgetPart ", this->getClassName(), this->getName());
  • branches/gui/src/lib/gui/gl/glgui_widget.h

    r8653 r8664  
    4242
    4343    /// FOCUS
    44     /** @brief gives focus to this widget */
     44    /** @brief gives mouse - focus to this widget */
    4545    void giveMouseFocus();
    4646    void breakMouseFocus();
     47
    4748    /** @returns true if the widget is focusable */
    4849    bool focusable() const { return this->_focusable; };
     
    5455    bool focusOverWidget(const OrxGui::GLGuiCursor* const cursor) const;
    5556
    56     /** @returns the currently focused Widget (NULL if none is selected) */
     57    /** @returns the currently mouse - focused Widget (NULL if none is focused). */
    5758    static GLGuiWidget* mouseFocused() { return GLGuiWidget::_mouseFocused; };
    5859
    5960    /// SELECT
    60     static GLGuiWidget* selected() { return GLGuiWidget::_selected; };
    6161    void select();
    6262    void unselect();
     63    /** @returns true if the Widget is selectable */
     64    bool selectable() const { return this->_selectable; }
     65    /** @param selectable true if the widget should be selectable */
     66    void setSelectable(bool selectable) { this->_selectable = selectable; }
     67
     68    /** @returns the currently Selected Widget (NULL if none is selected). */
     69    static GLGuiWidget* selected() { return GLGuiWidget::_selected; };
    6370
    6471    /// CLICK
     72    bool clicked() { return _clicked; };
    6573    void click(const Vector2D& pos);
    6674    void release(const Vector2D& pos);
     
    8593    void animateBack();
    8694
    87     /// STYLE
     95    ///////////////////////////////////////////////////////////////////////////////////
     96    /// STYLE /////////////////////////////////////////////////////////////////////////
    8897    ////////////////////////////////
    8998    /// Retrieve Current Values. ///
     
    205214    void setAnimatedStateChanges(bool animated);
    206215    void switchState(OrxGui::State state);
    207 
     216    ///////////////////////////////////////////////////////////////////////////////////
    208217
    209218
     
    229238
    230239  protected:
     240    /// RENDERING
     241    inline void beginDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); };
     242    inline void endDraw() const { glPopMatrix(); };
     243
     244
    231245    /// LOOKS
    232246    virtual void resize();
     
    234248    virtual void hiding() {};
    235249    virtual void showing() {};
     250
    236251    virtual void updateFrontColor() {};
    237252
    238     inline void beginDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); };
    239     inline void endDraw() const { glPopMatrix(); };
    240253
    241254    /// EVENTS
    242     // if something was clickt on the GUI-widget.
     255    // mouse clicking
    243256    virtual void clicking(const Vector2D& pos);
    244257    virtual void releasing(const Vector2D& pos);
     258    // mouse focusing
    245259    virtual void receivedFocus();
    246260    virtual void removedFocus();
    247 
    248     virtual void destroyed();
    249 
    250     virtual void debug() const;
     261    // selecting either with the mouse by clicking, or by the keybord traversing to it.
     262    virtual void selecting();
     263    virtual void unselecting();
     264    // destroying the Widget.
     265    virtual void destroying();
     266
     267
     268    virtual void debug(unsigned int level) const;
    251269
    252270  private:
     
    269287    /// EVENTS
    270288    OrxGui::State                  _state;
     289    bool                           _clicked;
    271290
    272291    bool                           _focusable;        //!< If this widget can receive focus.
    273292    bool                           _clickable;        //!< if this widget can be clicked upon.
     293    bool                           _selectable;       //!< If this widget can be selected.
    274294
    275295    bool                           _pushed;
     
    280300    typedef struct
    281301    {
    282       float             _borderLeft;           //!< The Distance to the left Border of the widget, before any internal Element starts.
    283       float             _borderRight;          //!< The Distance to the right Border of the widget, before any internal Element starts.
    284       float             _borderTop;            //!< The Distance to the top Border of the widget, before any internal Element starts
    285       float             _borderBottom;         //!< The Distance to the bottom Border of the widget, before any internal Element starts
    286 
    287       float             _textSize;             //!< The TextSize of the Widget.
    288 
    289       Material          _background;           //!< The Background Material of the Widget.
    290 
    291       Material          _foreground;           //!< The foreground Material of the Widget.
     302      float                        _borderLeft;           //!< The Distance to the left Border of the widget, before any internal Element starts.
     303      float                        _borderRight;          //!< The Distance to the right Border of the widget, before any internal Element starts.
     304      float                        _borderTop;            //!< The Distance to the top Border of the widget, before any internal Element starts
     305      float                        _borderBottom;         //!< The Distance to the bottom Border of the widget, before any internal Element starts
     306
     307      float                        _textSize;             //!< The TextSize of the Widget.
     308
     309      Material                     _background;           //!< The Background Material of the Widget.
     310
     311      Material                     _foreground;           //!< The foreground Material of the Widget.
    292312    }
    293313    StatedStyle;
    294314
    295315
    296     StatedStyle         _style[GLGUI_STATE_COUNT]; //!< Styles configured for different States
    297 
    298     FeaturePosition     _featurePosition;      //!< The Position a Feature will be layed at (checkbox(box), slider(text),...)
    299     Font*               _font;                 //!< The Font used in the current Widget.
     316    StatedStyle                    _style[GLGUI_STATE_COUNT]; //!< Styles configured for different States
     317
     318    FeaturePosition                _featurePosition;      //!< The Position a Feature will be layed at (checkbox(box), slider(text),...)
     319    Font*                          _font;                 //!< The Font used in the current Widget.
    300320
    301321
    302322    /// ANIMATION STUFF:
    303     bool                _animatedStateChanges; //!< If the Transitions between States are Animated automatically.
    304 
    305     bool                _animating;            //!< If the Widget is animated at the moment (Texture might be an AnimatedTexture.)
    306     float               _animationCycle;
    307     float               _animationDuration;
    308     StatedStyle         _currentStyle;
     323    bool                           _animatedStateChanges; //!< If the Transitions between States are Animated automatically.
     324
     325    bool                           _animating;            //!< If the Widget is animated at the moment (Texture might be an AnimatedTexture.)
     326    float                          _animationCycle;
     327    float                          _animationDuration;
     328    StatedStyle                    _currentStyle;
    309329
    310330  };
Note: See TracChangeset for help on using the changeset viewer.