• entries
    707
  • comments
    1173
  • views
    434145

Hooray

Sign in to follow this  

79 views

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)
++Itor;

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);
++nIndex;
}
}
else
(((*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())->OnLeftRelease(Event))
{
if(((*Itor).second.get())->GetID() == 1002)
{
++m_nScrollValue;
if(m_nScrollValue + m_nViewableItemCount > m_nItemCount)
m_nScrollValue = m_nItemCount - m_nViewableItemCount;
}
else if(((*Itor).second.get())->GetID() == 1001)
{
--m_nScrollValue;
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.)

Question/comments/suggestions?
Sign in to follow this  


3 Comments


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

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