Page 1 of 1

creating a horizontal slider - problems

Posted: Thu Mar 10, 2005 22:18
by SupSuper
no, this isn't a thread on how to create one, i've figured that out myself ;)

rather, this is one to see if any of you can figure out what's wrong with the code for one. basically, i've changed all the TaharezLook's Slider code so it would work horizontally, instead of vertically. however, when i drag the thumb left/right, it moves up/down (though it snaps back to place when i let it go), and i can't find out why! i've kept looking and looking but can't find out why, GAH! :x
i've attached the code so you can have a look and see if you can find the problem.

Re: creating a horizontal slider - problems

Posted: Fri Mar 11, 2005 09:23
by CrazyEddie
I'll have a look and get back to you a bit later on :)

Re: creating a horizontal slider - problems

Posted: Fri Mar 11, 2005 14:34
by CrazyEddie
Okay :)

Two small mistakes...

In the updateThumb method:

Code: Select all

d_thumb->setPosition(Point(0, absoluteToRelativeX_impl(this, slideExtent - (fltVal * (slideExtent / posExtent)))));


becomes:

Code: Select all

d_thumb->setPosition(Point(absoluteToRelativeX_impl(this, (fltVal * (slideExtent / posExtent))), 0));

The main issue was you had the x and y co-ords round the wrong way ;) The other change was to remove the inversion that is required for vertical bars with 0 at the bottom.

In the getValueFromThumb method

Code: Select all

return d_maxValue - (d_thumb->getAbsoluteXPosition() / (slideExtent / posExtent));


Becomes:

Code: Select all

return (d_thumb->getAbsoluteXPosition() / (slideExtent / posExtent));

Required to remove the inversion mentioned above.

HTH

CE.

Re: creating a horizontal slider - problems

Posted: Fri Mar 11, 2005 15:23
by SupSuper
thanks, it works now :)