gui help needed :)

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
ManTis
Posts: 12
Joined: Mon Sep 06, 2004 7:29 pm

gui help needed :)

Post by ManTis »

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 ;)
ManTis
Posts: 12
Joined: Mon Sep 06, 2004 7:29 pm

Post by ManTis »

also: how to get CHAR * from Edit box?

I use:

s = root->getElementFromId(903, true)->getText();
// SendTextMsg(s.c_str());

but i need char* instead of const char* for SendTextMsg[/b]

TIA
digfarenough
Posts: 39
Joined: Sat Oct 30, 2004 4:35 pm
Location: Boston, MA
Contact:

Post by digfarenough »

if your SendTextMsg function doesn't change the string it's passed (and I can't think of why it would) then you can just change it to accept a const char*

otherwise couldn't you just explicitly cast it to be a char * with SendTextMsg((char*)s.c_str());?
ManTis
Posts: 12
Joined: Mon Sep 06, 2004 7:29 pm

Post by ManTis »

jeez you're right -__-

that's what 3 days of programming non-stop, no caffeine included, does to my brain...

any idea about the list box scroll?
digfarenough
Posts: 39
Joined: Sat Oct 30, 2004 4:35 pm
Location: Boston, MA
Contact:

Post by digfarenough »

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:

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));
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
ManTis
Posts: 12
Joined: Mon Sep 06, 2004 7:29 pm

Post by ManTis »

thanks :))))
Post Reply