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.
hzsyber
Posts: 52 Joined: Tue Apr 01, 2008 2:21 pm
Location: Canton,China.
Post
by hzsyber » Wed Dec 10, 2008 12:40 pm
i use guienv->addButton() create a new button. i can see but can't click it.
why?
Code: Select all
if (stringw("Button") == xml->getNodeName())
{
x = xml->getAttributeValueAsInt(L"x");
y = xml->getAttributeValueAsInt(L"y");
w = xml->getAttributeValueAsInt(L"w");
h = xml->getAttributeValueAsInt(L"h");
uid = xml->getAttributeValueAsInt(L"uid");
caption = xml->getAttributeValue(L"caption");
IGUIButton* quit_button = guienv->addButton(rect<s32>(x, y, x + w, y + h), 0, uid, caption.c_str());
quit_button->setImage(driver->getTexture("button/button_on.JPG"));
quit_button->setPressedImage(driver->getTexture("button/button_up.JPG"));
quit_button->setUseAlphaChannel(true);
quit_button->setDrawBorder(true);
}
Code: Select all
while(device->run() && driver)
if (device->isWindowActive())
{
driver->beginScene(true, true, SColor(0,200,200,200));
guienv->drawAll();
driver->endScene();
}
vrg84
Posts: 3 Joined: Wed Dec 10, 2008 12:16 pm
Post
by vrg84 » Wed Dec 10, 2008 1:15 pm
Do you have an event receiver for the buttons?
If i look at the tutorial @
http://irrlicht.sourceforge.net/tut005.html
You should have something like this:
Code: Select all
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(const SEvent& event)
{
if (event.EventType == EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
IGUIEnvironment* env = device->getGUIEnvironment();
switch(event.GUIEvent.EventType)
{
case EGET_SCROLL_BAR_CHANGED:
if (id == 104)
{
s32 pos = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos();
for (u32 i=0; i<EGDC_COUNT ; ++i)
{
SColor col = env->getSkin()->getColor((EGUI_DEFAULT_COLOR)i);
col.setAlpha(pos);
env->getSkin()->setColor((EGUI_DEFAULT_COLOR)i, col);
}
}
break;
case EGET_BUTTON_CLICKED:
if (id == 101)
{
device->closeDevice();
return true;
}
if (id == 102)
{
listbox->addItem(L"Window created");
cnt += 30;
if (cnt > 200)
cnt = 0;
IGUIWindow* window = env->addWindow(
rect<s32>(100 + cnt, 100 + cnt, 300 + cnt, 200 + cnt),
false, // modal?
L"Test window");
env->addStaticText(L"Please close me",
rect<s32>(35,35,140,50),
true, // border?
false, // wordwrap?
window);
return true;
}
if (id == 103)
{
listbox->addItem(L"File open");
env->addFileOpenDialog(L"Please choose a file.");
return true;
}
break;
default:
break;
}
}
return false;
}
};
Then under "case EGET_BUTTON_CLICKED:" you give behaviours to each button.
hzsyber
Posts: 52 Joined: Tue Apr 01, 2008 2:21 pm
Location: Canton,China.
Post
by hzsyber » Wed Dec 10, 2008 1:32 pm
yes,i sure i have a IEventReceiver in my code.
when i click the button, no everything button event.
only mouse event.
rogerborg
Admin
Posts: 3590 Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:
Post
by rogerborg » Wed Dec 10, 2008 1:42 pm
hzsyber wrote: yes,i sure i have a IEventReceiver in my code.
when i click the button, no everything button event.
only mouse event.
And could we see your event receiver?
hzsyber
Posts: 52 Joined: Tue Apr 01, 2008 2:21 pm
Location: Canton,China.
Post
by hzsyber » Wed Dec 10, 2008 3:20 pm
rogerborg wrote: hzsyber wrote: yes,i sure i have a IEventReceiver in my code.
when i click the button, no everything button event.
only mouse event.
And could we see your event receiver?
of course!
Code: Select all
bool UIControl::OnEvent(const SEvent& event)
{
if (event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.Key == KEY_ESCAPE && event.KeyInput.PressedDown == false)
{ //close
device->closeDevice();
ExitControl = false;
}
if (event.EventType == EET_GUI_EVENT && event.GUIEvent.EventType == EGET_BUTTON_CLICKED)
{
s32 id = event.GUIEvent.Caller->getID();
stringw postuid;
s32 uid;
char conffile[100];
sprintf_s(conffile, "%s/Language/%s/%s", load->GetAppPath().c_str(), load->GetLanguage().c_str(), load->GetinfoFile().c_str());
IXMLReader* xml = device->getFileSystem()->createXMLReader(conffile);
while(xml && xml->read())
{
uid = xml->getAttributeValueAsInt(L"uid");
if (id == uid)
{
do something.
}
}
if (xml) xml->drop();
}
return true;
}
JP
Posts: 4526 Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:
Post
by JP » Wed Dec 10, 2008 3:43 pm
you should return false at the end of your event receiver if you haven't handled the event, that way it then gets passed onto things like cameras and the gui, otherwise they don't get it.
So if you handle the event and don't want the rest of irrlicht to get it return true, otherwise return false.
hzsyber
Posts: 52 Joined: Tue Apr 01, 2008 2:21 pm
Location: Canton,China.
Post
by hzsyber » Wed Dec 10, 2008 4:21 pm
JP wrote: you should return false at the end of your event receiver if you haven't handled the event, that way it then gets passed onto things like cameras and the gui, otherwise they don't get it.
So if you handle the event and don't want the rest of irrlicht to get it return true, otherwise return false.
oh! yes. i modify to false. it work!
thanks all.i love you. i love irrlicht!