Feb 10, 2015 at 10:12am UTC
Im trying to create a slide bar. My problem is that when i drag the slider then let go of the mouse button the slider goes back to the start 0
im pre sure its because im setting sliderx inside function.
im not sure how to set the sliderx float from the sliderValue
Last edited on Mar 11, 2015 at 5:46am UTC
Feb 10, 2015 at 11:15am UTC
Okay so we're just going to do some algebra to figure out how to calculate sliderx given SliderValue.
We know the following.
SliderValue = ((max - min) / (w))*(sliderx - x + sliderw / 2);
If we divide both sides by ((max - min) / (w)) we now have
SliderValue/ ((max - min) / (w)) = (sliderx - x + sliderw / 2);
If we add x to both sides we get
(SliderValue/ ((max - min) / (w)) ) + x = (sliderx + sliderw / 2);
And finally, if we subtract sliderw/2 from both sides we get
(SliderValue/ ((max - min) / (w)) ) + x - sliderw/2 = sliderx;
Therefore, we can calculate sliderx by doing
sliderx = (SliderValue/ ((max - min) / (w)) ) + x - sliderw/2;
Last edited on Feb 10, 2015 at 11:19am UTC
Feb 10, 2015 at 11:27am UTC
omg thanks so much.
solved
Feb 10, 2015 at 11:28am UTC
Could you please click the check mark so that people can see that the topic was solved without clicking on it?
And no problem, glad I could help. :)
Feb 13, 2015 at 1:38am UTC
Sorry i have one small problem.
if i draw my slider with (min = 0, max = 100) it works fine
but if i draw it with (min = 50, max = 100) the sliders min ends up being 0 and the max ends up as 50