Making Scrollbars

Started by
6 comments, last by BreathOfLife 15 years, 8 months ago
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?
Advertisement
Mentioning things like programming language and platform would probably be a good place to start.
Yeah sorry, im using c++ with allegro library on windows xp.
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
--------------------------------------Not All Martyrs See Divinity, But At Least You Tried
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.
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.
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.
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)

This topic is closed to new replies.

Advertisement