Skip to main content
GameDev.net gamedev.net
🔒 Locked

Programming a 2D Scrollbar (C++)

Started by ajm113 Oct 3, 2010 at 2:02 PM 0 replies 700+ views
Original Post
ajm113
ajm113
Hello all I'm programming a Scrollbar for my software in OpenGL and so far so good I have my scrollbar able to perform up and down movement and stop at the areas I want it too with the mouse.

The problem is at this point is too determine the amount of movement the text will move up or down determining how many rows there are so the scrollbar can go through the hole list of rows correctly.

This is what I have:
//Is the scroll bar staying in it's area?					if((LayerScrollBar.vec1.m_Y + Dir.m_Y) >= 140 && (LayerScrollBar.vec1.m_Y + Dir.m_Y) <= 230)					{//Move the scrollbar in the direction the mouse is moving.						LayerScrollBar.vec1.m_Y += Dir.m_Y;							if(Dir.m_Y > 0)						{//Are we scrolling up?						if(m_Layers.m_Layers.size() > 13 && LayerScrollPos+13 < m_Layers.m_Layers.size())							LayerScrollPos++;						}						else						{							//Are we scrolling down?                        if(m_Layers.m_Layers.size() > 13 && LayerScrollPos > 0)						LayerScrollPos--;						}					}


The problem with that code is that if there is too little text then I have space on my Scrollbar that's wasting space and if there is more ... you get the point. Whats a good way to fix my scrollbar so that it will move through everything? I don't have my scrollbar resize by the way I was thinking it would be easier just to have it keep it's size no matter how big the list is.

Thanks, Andrew.

[Edited by - ajm113 on October 3, 2010 2:32:39 PM]
Check out my open source code projects/libraries! My Homepage You may learn something.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.