Page 1 of 1

addButton problem.

Posted: Wed Dec 10, 2008 12:40 pm
by hzsyber
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();
	}

Posted: Wed Dec 10, 2008 1:15 pm
by vrg84
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.

Posted: Wed Dec 10, 2008 1:32 pm
by hzsyber
yes,i sure i have a IEventReceiver in my code.

when i click the button, no everything button event.

only mouse event.

Posted: Wed Dec 10, 2008 1:42 pm
by rogerborg
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?

Posted: Wed Dec 10, 2008 3:20 pm
by hzsyber
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;
}

Posted: Wed Dec 10, 2008 3:43 pm
by JP
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.

Posted: Wed Dec 10, 2008 4:21 pm
by hzsyber
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!