Hi. How to, as line are added to the list, make the list scroll down?
I want to make a in-game chat, and this is kinda needed
gui help needed :)
-
- Posts: 39
- Joined: Sat Oct 30, 2004 4:35 pm
- Location: Boston, MA
- Contact:
-
- Posts: 39
- Joined: Sat Oct 30, 2004 4:35 pm
- Location: Boston, MA
- Contact:
I just looked at the API documentation for a bit, and you're right that making a scrolling list box looks a little tricky
this is the best way that occurs to me without going in and adding new functions to the engine itself to make it easier:
basically we keep a second listbox as a buffer so we can add a new thing to the top of the buffer, then add all old items, then copy those back over to the chat box
there might be better ways, but this at least works.. adding to the bottom of a listbox instead of the top is trickier, cause there doesn't seem to be a way to make it scroll to the bottom, that's why I went for the top
this is the best way that occurs to me without going in and adding new functions to the engine itself to make it easier:
Code: Select all
gui::IGUIListBox* listbox = 0, *bufbox = 0;
chatbox = device->getGUIEnvironment()->addListBox(core::rect<s32>(100, 30, 600, 100), 0, 1111, true);
bufbox = device->getGUIEnvironment()->addListBox(core::rect<s32>(100, 30, 600, 100), 0, 1111, true);
bufbox->setVisible(false);
// to test this I put the code in an event handler I had lying around that gives the 3d coords of where the mouse was clicked
wchar_t buf[100];
swprintf(buf, 100, L"mouse down: %g %g %g\n", target.X, target.Y, target.Z); // this was just my test data for adding to the box
bufbox->clear();
bufbox->addItem(buf);
for(int i=0; i<chatbox->getItemCount(); i++)
bufbox->addItem(chatbox->getListItem(i));
chatbox->clear();
for(i=0; i<bufbox->getItemCount();i++)
chatbox->addItem(bufbox->getListItem(ii));
there might be better ways, but this at least works.. adding to the bottom of a listbox instead of the top is trickier, cause there doesn't seem to be a way to make it scroll to the bottom, that's why I went for the top