Jump to content
  • Advertisement
  • entries
  • comments
  • views


Sign in to follow this  


Well, I fixed some problems with the old demo and added scrolling to the list box. It took about 1.5 hours. Here is a link to the new demo and here is a new screenshot.

Edit: I forgot to mention that you can add items to the listbox by typing the text into the top textbox in the middle and clicking the Add Item button at the top left.

ListBox with scrolling

Implementing scrolling was a lot easier than I thought it was going to be (though, my system might not be the best way to do it.) Here's a couple snippets:

// My children are stored in a map via map >
// This is how they're rendered
std::map<int, boost::shared_ptr >::iterator Itor = m_Children.begin();
for(int nItem = 0; nItem < m_nScrollValue && Itor != m_Children.end(); ++nItem)

for(; Itor != m_Children.end(); ++Itor)
Widget* pWidget = (*Itor).second.get();
if((*Itor).second.get()->GetType() == Widget::WidgetTypes::ListBoxItem)
if(nIndex < m_nViewableItemCount)
((ListBoxItem*)((*Itor).second.get()))->Render(nIndex, m_nItemHeight, pTexture, pGraphics, pFont);
(((*Itor).second.get()))->Render(pTexture, pGraphics, pFont);

// This is how they're scrolled:
bool ListBox::OnLeftRelease(const InputEvent& Event)
for(std::map<int, boost::shared_ptr >::iterator Itor = m_Children.begin(); Itor != m_Children.end(); ++Itor)
if(((*Itor).second.get())->GetID() == 1002)
if(m_nScrollValue + m_nViewableItemCount > m_nItemCount)
m_nScrollValue = m_nItemCount - m_nViewableItemCount;
else if(((*Itor).second.get())->GetID() == 1001)
if(m_nScrollValue < 0)
m_nScrollValue = 0;
return true;

// This is the ListBoxItem's render function
void ListBox::ListBoxItem::Render(int nIndex, int nItemHeight, Texture* pTexture, Graphics* pGraphics, Font* pFont)
Move(0, nIndex * nItemHeight);
Resize(m_pParent->GetWidth(), nItemHeight);
Render(pTexture, pGraphics, pFont);

Some things need to be changed (for instance, my 2 buttons for scrolling need to have a variable defined with their ID number.)

Sign in to follow this  


Recommended Comments

I like the widgets. I think you'll wanna add the ability to click anywhere on the sliders to move them, but that shouldn't be hard.

I don't like how the mouse is locked into the window while running in windowed mode. I'm guessing you wouldn't release a game like that, though.

Share this comment

Link to comment
Thanks for the reply Jesse! I'm going to work on adding the scrollbar when I get a chance. As for the mouse, I need to fix that. The mouse is locked in the window in code (I have bounds set to the window's width and height), but I need to code up a way to remove these in windowed mode.

Thanks again!

Share this comment

Link to comment
Wow, somehow I didn't notice that you can select the first node. I'm working on this now.

Share this comment

Link to comment

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
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!