Hello!
I'm implementing a
vertical scrollbar for a small game project and i'm having some issues with
calculating local positions of the scrollbar
Thumb and
Content when the
Viewport rectangle moves.
At the moment, when i move the viewport, the track, thumb and content flyes all over the place.
- What i'm trying to achieve:
. Calculate the
Thumb and
Content "
local positions".
. When the
Viewport is moved, the
Thumb and
Content should
keep their local positions in relation to the new viewport position.
I'm using C#, Windows Forms and the System.Drawing Rectangle.
I'm not using the Windows Forms controls, they are all custom.
Here is a snippet of the code:
var track = new Rectangle(0, 0, 50, 100);
var thumb = new Rectangle(0, 0, 50, 100);
var content = new Rectangle(0, 0, 100, 100);
public void OnViewportPositionChanged(Point position)
{
viewport.X = position.X;
viewport.Y = position.Y;
thumb.X = viewport.X;
thumb.Y = thumb_local_position;
content.X = viewport.X;
content.Y = content_local_position;
}
public void CalculateLocalPositions()
{
content_local_position = ???;
thumb_local_position = ???;
}
Thanks in advance!
What I have tried:
I'm trying to solve these two problems since yesterday but could not find the right calculations on the web.