Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
May 28, 2006, 11:25:19 PM (19 years ago)
Author:
bensch
Message:

gui: Slider is better controllable now

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

Legend:

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

    r7939 r7942  
    2525
    2626  /**
    27    * standard constructor
    28   */
     27   * @brief standard constructor
     28   */
    2929  GLGuiSlider::GLGuiSlider ()
    3030  {
     
    3535
    3636  /**
    37    * standard deconstructor
    38   */
     37   * @brief standard deconstructor
     38   */
    3939  GLGuiSlider::~GLGuiSlider()
    4040  {}
    4141
    4242  /**
    43    * initializes the GUI-element
     43   * @brief initializes the GUI-element
    4444   */
    4545  void GLGuiSlider::init()
     
    6262  }
    6363
    64 
     64  /**
     65   * @param value the new Value.
     66   * @note will automatically be set between max() and min()
     67   */
    6568  void GLGuiSlider::setValue(float value)
    6669  {
     
    7477  }
    7578
     79  /**
     80   * @param minimum the minumum of the range.
     81   *
     82   * @note will rearange value if necessary and will not be made bigger than max()
     83   */
    7684  void GLGuiSlider::setMin(float minimum)
    7785  {
    7886    if (minimum <= max())
    79      this->_minValue = minimum;
     87      this->_minValue = minimum;
    8088
    8189    if (this->value() < minimum)
     
    8391  }
    8492
     93
     94  /**
     95   * @param maximum the maximum of the range.
     96   *
     97   * @note will rearange value if necessary and will not be made smaller than min()
     98   */
    8599  void GLGuiSlider::setMax(float maximum)
    86100  {
     
    92106  }
    93107
     108  /**
     109   * @param minimum the minimum
     110   * @param maximum the maximum
     111   *
     112   * @see setMax
     113   * @see setMin
     114   */
    94115  void GLGuiSlider::setRange(float minimum, float maximum)
    95116  {
     
    105126  }
    106127
     128  /**
     129   * @brief sets the stepSize
     130   */
    107131  void GLGuiSlider::setStep(float step)
    108132  {
     
    110134  }
    111135
    112 
     136  /**
     137   * @brief makes one step into the minus direction
     138   */
     139  void GLGuiSlider::stepMinus()
     140  {
     141    this->setValue(value() - step());
     142  }
     143
     144  /**
     145   * @brief makes one step into the minus direction
     146   */
     147  void GLGuiSlider::stepPlus()
     148  {
     149    this->setValue(value() + step());
     150  }
     151
     152  /**
     153   * @brief resizes the Slider, and through this Synchronizes the GUI-size.
     154   */
    113155  void GLGuiSlider::resize()
    114156  {
    115157    GLGuiWidget::resize();
    116     this->frontRect().setTopLeft(5, this->getSizeY2D()/2.0 - borderSize());
    117     this->frontRect().setSize(this->getSizeX2D() - 10.0, borderSize());
    118   }
    119 
    120 
     158    this->frontRect().setTopLeft(5, this->getSizeY2D()/2.0 - 2.0);
     159    this->frontRect().setSize(this->getSizeX2D() - 10.0, 4.0);
     160  }
     161
     162  /**
     163   * @brief handle the clicked event.
     164   * @param pos the position the Click occured (from the topleft corner out)
     165   */
    121166  void GLGuiSlider::clicked(const Vector2D& pos)
    122167  {
     
    131176    else
    132177      this->grabbed = true;
    133 
    134 
    135 
    136     printf("clicked at position: "), pos.debug();
    137178  }
    138179
     
    149190  }
    150191
     192  /**
     193   * @returns the current SliderPosition calculated from the current value and the Silders' size.
     194   */
    151195  float GLGuiSlider::sliderPosition() const
    152196  {
    153197    return (this->_value - this->_minValue)/( this->_maxValue - this->_minValue) *
    154         (this->getSizeX2D() - 2.0*(borderSize() + _sliderWidth)) +
    155         (borderSize() +_sliderWidth);
    156   }
    157 
     198           (this->getSizeX2D() - 2.0*(borderSize() + _sliderWidth)) +
     199           (borderSize() +_sliderWidth);
     200  }
     201
     202  /**
     203   * @param position the position relative from the left border.
     204   * @returns the Value at the given position.
     205   */
    158206  float GLGuiSlider::sliderValue(float position) const
    159207  {
    160208    return (position - (borderSize()+_sliderWidth)) / (this->getSizeX2D() - 2.0*(borderSize() + _sliderWidth))
    161         *( this->_maxValue - this->_minValue) +
    162         this->_minValue ;
    163   }
    164 
    165   /*  virtual void GLGuiSlider::tick(float dt)
    166     {
    167       if (this->grabbed)
    168       {
    169         this->setValue( 1);
    170       }
    171     }*/
     209           *( this->_maxValue - this->_minValue) +
     210           this->_minValue ;
     211  }
    172212
    173213  void GLGuiSlider::tick(float dt)
    174214  {
    175 /*    this->setValue(this->value() + dt);
    176     if (this->value() >= this->max())
    177     this->setValue(this->min());
    178 */
    179215  }
    180216
     
    203239      return true;
    204240    }
     241    else if (event.bPressed)
     242    {
     243      if (event.type == SDLK_LEFT)
     244      {
     245        this->stepMinus();
     246        return true;
     247      }
     248      else if (event.type == SDLK_RIGHT)
     249      {
     250        this->stepPlus();
     251        return true;
     252      }
     253    }
    205254    return false;
    206255  }
  • branches/gui/src/lib/gui/gl_gui/glgui_slider.h

    r7939 r7942  
    4343    void setStep(float step);
    4444
     45    void stepPlus();
     46    void stepMinus();
    4547
    4648    virtual void tick(float dt);
     
    5961    float sliderPosition() const;
    6062    float sliderValue(float position) const;
     63
    6164  private:
    62 
    6365    Orientation      orientation;
    6466
Note: See TracChangeset for help on using the changeset viewer.