• entries
707
1173
• views
433750

Hooray

76 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 renderedstd::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 functionvoid 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.)

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.

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!

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

Create an account

Register a new account