Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7931 in orxonox.OLD


Ignore:
Timestamp:
May 28, 2006, 8:18:03 PM (18 years ago)
Author:
bensch
Message:

gui: Slider can be slided

Location:
branches/gui/src/lib
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/gui/src/lib/event/event_handler.cc

    r7928 r7931  
    380380      case SDL_MOUSEBUTTONUP:
    381381        ev.bPressed = false;
     382        ev.x = event.motion.x;
     383        ev.y = event.motion.y;
    382384        ev.type = event.button.button + SDLK_LAST;
    383385        break;
    384386      case SDL_MOUSEBUTTONDOWN:
    385387        ev.bPressed = true;
     388        ev.x = event.motion.x;
     389        ev.y = event.motion.y;
    386390        ev.type = event.button.button + SDLK_LAST;
    387391        break;
  • branches/gui/src/lib/gui/gl_gui/glgui_handler.cc

    r7929 r7931  
    108108            if (GLGuiWidget::focused()->clickable())
    109109            {
    110               GLGuiWidget::focused()->click(Vector2D(event.x, event.y) - GLGuiWidget::focused()->getAbsCoor2D());
     110              Vector2D cursorPos = (this->cursor != NULL) ? this->cursor->getAbsCoor2D() : Vector2D(event.x, event.y);
     111              GLGuiWidget::focused()->click(cursorPos - GLGuiWidget::focused()->getAbsCoor2D());
    111112            }
    112113          }
     
    114115          {
    115116            if (GLGuiWidget::focused()->clickable())
    116               GLGuiWidget::focused()->release(Vector2D(event.x, event.y) - GLGuiWidget::focused()->getAbsCoor2D());
     117            {
     118              Vector2D cursorPos = (this->cursor != NULL) ? this->cursor->getAbsCoor2D() : Vector2D(event.x, event.y);
     119              GLGuiWidget::focused()->release(cursorPos - GLGuiWidget::focused()->getAbsCoor2D());
     120            }
    117121          }
    118122        }
     
    139143
    140144  }
     145
     146
     147  Vector2D GLGuiHandler::cursorPositionOverFocusedWidget() const
     148  {
     149    return (this->cursor != NULL) ? this->cursor->getAbsCoor2D() : Vector2D(0,0);
     150  }
     151
    141152
    142153  void GLGuiHandler::draw()
  • branches/gui/src/lib/gui/gl_gui/glgui_handler.h

    r7919 r7931  
    3030    GLGuiCursor* getCursor() const { return this->cursor; }
    3131
     32    Vector2D cursorPositionOverFocusedWidget() const;
     33
    3234    void activate();
    3335    void deactivate();
  • branches/gui/src/lib/gui/gl_gui/glgui_slider.cc

    r7929 r7931  
    1717
    1818#include "glgui_slider.h"
     19#include "event_def.h"
    1920
    2021namespace OrxGui
     
    3536  */
    3637  GLGuiSlider::~GLGuiSlider()
    37   {
    38   }
     38  {}
    3939
    4040  /**
     
    5353    this->_maxValue = 1.0;
    5454    this->_step = 0.1;
     55    this->_sliderWidth = 5.0;
     56    this->grabbed = false;
    5557
    5658    this->setSize2D(100, 30);
     
    6163  void GLGuiSlider::setValue(float value)
    6264  {
    63     this->_value = value;
     65    if (value < this->min())
     66      this->_value = min();
     67    else if (value > max())
     68      this->_value = max();
     69    else
     70      this->_value = value;
     71    printf("VALUE %f\n", _value);
    6472  }
    6573
    6674  void GLGuiSlider::setMin(float minimum)
    6775  {
    68     this->_minValue = minimum;
     76    if (minimum <= max())
     77     this->_minValue = minimum;
     78
     79    if (this->value() < minimum)
     80      this->_value = minimum;
    6981  }
    7082
    7183  void GLGuiSlider::setMax(float maximum)
    7284  {
    73     this->_maxValue = maximum;
     85    if (maximum >= min())
     86      this->_maxValue = maximum;
     87
     88    if (this->value() > maximum)
     89      this->_value = maximum;
    7490  }
    7591
    7692  void GLGuiSlider::setRange(float minimum, float maximum)
    7793  {
    78     this->_minValue = minimum;
    79     this->_maxValue = maximum;
     94    if (minimum < maximum)
     95    {
     96      this->_minValue = minimum;
     97      this->_maxValue = maximum;
     98    }
     99    if (this->value() < minimum)
     100      this->_value = minimum;
     101    else if (this->value() > maximum)
     102      this->_value = maximum;
    80103  }
    81104
     
    93116  }
    94117
     118
     119  void GLGuiSlider::clicked(const Vector2D& pos)
     120  {
     121    GLGuiWidget::clicked(pos);
     122
     123    float sliderPosition = this->sliderPosition();
     124    if (sliderPosition > pos.x + this->_sliderWidth)
     125      this->setValue(this->value() - this->step());
     126
     127    else if (sliderPosition < pos.x - this->_sliderWidth)
     128      this->setValue(this->value() + this->step());
     129    else
     130      this->grabbed = true;
     131
     132
     133
     134    printf("clicked at position: "), pos.debug();
     135  }
     136
     137  void GLGuiSlider::released(const Vector2D& pos)
     138  {
     139    GLGuiWidget::released(pos);
     140    this->grabbed = false;
     141  }
     142
     143  void GLGuiSlider::removedFocus()
     144  {
     145    GLGuiWidget::removedFocus();
     146    this->grabbed = false;
     147  }
     148
     149  float GLGuiSlider::sliderPosition() const
     150  {
     151    return (this->_value - this->_minValue)/( this->_maxValue - this->_minValue) * (this->getSizeX2D() - 4.0) + 2.0;
     152  }
     153
     154  float GLGuiSlider::sliderValue(float position) const
     155  {
     156    return (position - 2.0) / (this->getSizeX2D() - 4.0)  *( this->_maxValue - this->_minValue) +this->_minValue ;
     157  }
     158
     159  /*  virtual void GLGuiSlider::tick(float dt)
     160    {
     161      if (this->grabbed)
     162      {
     163        this->setValue( 1);
     164      }
     165    }*/
     166
    95167  /**
    96168   * @brief draws the GLGuiSlider
     
    104176    this->drawRect(this->frontRect());
    105177
    106     float percentagePosition = (this->_value - this->_minValue)/( this->_maxValue - this->_minValue);
    107 
    108     this->drawRect(Rect2D(percentagePosition* this->getSizeX2D(), 2, 5, this->getSizeY2D() - 4));
     178    this->drawRect(Rect2D(this->sliderPosition()-_sliderWidth/2.0, 2, _sliderWidth, this->getSizeY2D() - 4));
    109179
    110180    this->endDraw();
    111181  }
     182
     183  bool GLGuiSlider::processEvent( const Event& event )
     184  {
     185    if (this->grabbed && event.type == EV_MOUSE_MOTION)
     186    {
     187      this->setValue(sliderValue(event.x - this->getAbsCoor2D().x));
     188      return true;
     189    }
     190    return false;
     191  }
    112192}
  • branches/gui/src/lib/gui/gl_gui/glgui_slider.h

    r7929 r7931  
    4343    void setStep(float step);
    4444
     45
     46//    virtual void tick(float dt);
     47    virtual bool processEvent(const Event& event);
    4548    virtual void draw() const;
    4649
    4750  protected:
    48     void resize();
     51    virtual void resize();
     52
     53    virtual void clicked(const Vector2D& pos);
     54    virtual void released(const Vector2D& pos);
     55    virtual void removedFocus();
    4956
    5057  private:
    5158    void init();
     59    float sliderPosition() const;
     60    float sliderValue(float position) const;
    5261  private:
    5362
     
    6069    float            _value;
    6170
     71    float            _sliderWidth;
     72
     73    bool             grabbed;
     74
    6275  };
    6376}
Note: See TracChangeset for help on using the changeset viewer.