Sign in to follow this  
TheBinaryMan

Making Scrollbars

Recommended Posts

If anyone has had any experience in making a scrollbar can you please share some explanation of how to make one? For example I let the user load a picture, and the picture is displayed in a view rectangle that is only 145 pixels wide and 515 pixels high. So far, if the user loads a picture bigger than the dimensions of the view rectangle it will display the top left side of the picture (the width and height of the view rectangle). But I can't seem to figure out how big the scrollbar slider should be and how to make the picture slide depending on the users control of the scrollbar. Any suggestions?

Share this post


Link to post
Share on other sites
Mentioning things like programming language and platform would probably be a good place to start.

Share this post


Link to post
Share on other sites
when the program registers that the scroll bar has been clicked, just increase/decrease the x/y value of the image accordingly

if(MouseIsClicked)
{

if(mouse is within scroll bar)
{

YWhenClicked = Mouse.y;

Clicked = true;
}
}

if(Clicked)
{

Img.x += Mouse.x - YWhenClicked;
}



sometihng along those lines

Share this post


Link to post
Share on other sites
Thanks for the reply but it is a little more complicated than that. I want the scrollbars to work like they do in a windows application. The slider for the scrollbar should be sized according to how big the picture being loaded in is. I know how to scroll the picture, i just don't know how the relationship between the scrollbar and the picture works.

Share this post


Link to post
Share on other sites
You know the size of the rectangle, you know the size of the image (right? how else would you know to use the scroll bars?). These will be directly proportional to the size of the slider vs the scroll area.

Share this post


Link to post
Share on other sites
When the user loads a specific image the scrollbar slider should be sized big enough so that when it scrolls it has enough room to slide through the entire scrollbar as well as the entire image.

What Im trying to find out is how to get the size of the slider once the image is loaded. The scrollbar width is 145 pixels wide. I need to figure out the width of the slider so that when scrolling the start of the slider coordinates with the start of the image and the end of the slider coordinates with the end of the image.

Share this post


Link to post
Share on other sites
You dont really need to find out the width, as you need to choose it. Your bar is 145 pixels wide. Make the bar 16 pixels wide. The center of the slider will always be 8 pixels from whatever side its against, so just ignore those pixels, and the total sliding pixels is 139. Its a weird number, but its just an example.

Now you just use the ratio of (imagewidth : 139) and you should have what your looking for. At least, thats what Ive put together for my sliders, which, arent quite in the works yet (working on a console... still in the displaying text part, let alone scrolling it)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this