Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How to calculate the value from the slider  (Read 1594 times)

0 Members and 1 Guest are viewing this topic.

MarbleXeno

  • Guest
How to calculate the value from the slider
« on: August 23, 2020, 09:53:10 pm »
Hello, i've created simple menu and now im working on a slider for changing the volume but i dont know how to calculate the value from the slider to change the volume of the music. I know, this is really dumb question, its simple math but for some reason i can't calculate it! I would be grateful for some pattern.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: How to calculate the value from the slider
« Reply #1 on: August 24, 2020, 08:18:15 am »
// map the slider position to [0 .. 1]
auto ratio = static_cast<float>(y_cursor - y_slider_min) / (y_slider_max - y_slider_min);

// map the current position in [0 .. 1] to a volume value
auto volume = ratio * (volume_max - volume_min) + volume_min;
Laurent Gomila - SFML developer

MarbleXeno

  • Guest
Re: How to calculate the value from the slider
« Reply #2 on: August 24, 2020, 11:11:38 am »
Thank you very much, it worked.