button->setVisible(false) not working
button->setVisible(false) not working
Hi there,
I'm trying to hide some buttons in different conditions and let them reapear and then hide them again.
the first (initial) hide works perfectly, but after the button once was drawn it does'nt disapears again...
what could be the reason?
I'm trying to hide some buttons in different conditions and let them reapear and then hide them again.
the first (initial) hide works perfectly, but after the button once was drawn it does'nt disapears again...
what could be the reason?
in main:
for(y=0; y < 10; y++)
{
possibility[y] = environment->addButton(rect<s32>(10,120+(y*20),300,140+(y*20)), 0, 111+y, L"");
possibility[y]->setVisible(0);
}
then in the event handler after selecting a different kind of list box item
if(should be shown)
{
text = "blabla";
possibility[x]->setText(text.c_str());
possibility[x]->setVisible(1);
}
else
{
possibility[x]->setVisible(0);
}
for(y=0; y < 10; y++)
{
possibility[y] = environment->addButton(rect<s32>(10,120+(y*20),300,140+(y*20)), 0, 111+y, L"");
possibility[y]->setVisible(0);
}
then in the event handler after selecting a different kind of list box item
if(should be shown)
{
text = "blabla";
possibility[x]->setText(text.c_str());
possibility[x]->setVisible(1);
}
else
{
possibility[x]->setVisible(0);
}
-
- Posts: 1
- Joined: Wed Oct 04, 2006 12:47 am
- Contact:
Are you sure
Are you sure your event is actually being called? Also you my try checking the visable property after setting it. If for some reason IRRLICHT is not allowing an update, then it should stay at zero.
Mike
Mike
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
or could it even be, your button(it looks like anyways) is possiblity[y] yet yor don't ever set it visible anywhere, only possibility x...wheatas wrote:in main:
for(y=0; y < 10; y++)
{
possibility[y] = environment->addButton(rect<s32>(10,120+(y*20),300,140+(y*20)), 0, 111+y, L"");
possibility[y]->setVisible(0);
}
then in the event handler after selecting a different kind of list box item
if(should be shown)
{
text = "blabla";
possibility[x]->setText(text.c_str());
possibility[x]->setVisible(1);
}
else
{
possibility[x]->setVisible(0);
}
try chainging
possibility[x]->setText(text.c_str());
possibility[x]->setVisible(1);
to
possibility[y]->setText(text.c_str());
possibility[y]->setVisible(1);
My 2 cents.
I have tried with the following code and wheatas is right, it doesn't work.
Only the first time button2 appears, that it does not disappear.
Bye
I have tried with the following code and wheatas is right, it doesn't work.
Only the first time button2 appears, that it does not disappear.
Code: Select all
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace gui;
#pragma comment(lib, "Irrlicht.lib")
IGUIButton *button1, *button2;
class MyEventReceiver : public IEventReceiver
{
public:
bool OnEvent(SEvent event)
{
if (event.EventType == irr::EET_GUI_EVENT &&
event.GUIEvent.EventType == irr::gui::EGET_BUTTON_CLICKED &&
event.GUIEvent.Caller -> getID() == 100) {
printf("TOGGLE\n");
button2->setVisible(~button2->isVisible());
}
return false;
}
};
int main()
{
IrrlichtDevice *device =
createDevice(video::EDT_SOFTWARE2, dimension2d<s32>(640, 480), 16,
false, false, false, 0);
device->setWindowCaption(L"test button");
IVideoDriver *driver = device->getVideoDriver();
ISceneManager *smgr = device->getSceneManager();
IGUIEnvironment *guienv = device -> getGUIEnvironment ();
button1 = guienv->addButton (irr::core::rect<s32> (0, 0, 100, 20), NULL, 100, L"button1");
button2 = guienv->addButton (irr::core::rect<s32> (110, 0, 210, 20), NULL, 200, L"button2");
button2->setVisible(false);
device->setEventReceiver(new MyEventReceiver());
while(device->run())
{
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
guienv->drawAll ();
device->run();
driver->endScene();
}
device->drop();
return 0;
}
@moneycracks
i always used
setVisible(false);
or setVisible(true);
tried it, same behaviour...
and for the second answer:
ok, for the first time a use a for loop with y, and the second time its again a for loop but with x. Perhaps I should have printet it aswell...
sorry
@stef_
thanks for trying...
any idea how to solve it?
i always used
setVisible(false);
or setVisible(true);
tried it, same behaviour...
and for the second answer:
ok, for the first time a use a for loop with y, and the second time its again a for loop but with x. Perhaps I should have printet it aswell...
sorry
@stef_
thanks for trying...
any idea how to solve it?
That's not correct, you can't do that with bools.stef_ wrote:Code: Select all
button2->setVisible(~button2->isVisible());
If you don't believe it try this short programme:
Code: Select all
#include <stdio.h>
int main()
{
bool isTrue = true;
isTrue = ~isTrue;
printf("true ? %d \n", isTrue ? 1 : 0);
return 0;
}
I'm quite sure setVisible works as expected, as i'm using it quite often (and all it does is setting a flag which is checked before drawing the button).
So chances are that you don't update the gui after enabling/diabling it, or you don't enable/disable the button when you expect to do it, or what also often happens is that you do it all correct - but you overwrite the change in another part of the programme again.
sorry to all!
it works!
@CuteAlien
thanks, yes it is:
button2->setVisible(not button2->isVisible());
(this morning I was programmin in C.. )
Code with correction:
it works!
@CuteAlien
thanks, yes it is:
button2->setVisible(not button2->isVisible());
(this morning I was programmin in C.. )
Code with correction:
Code: Select all
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace gui;
#pragma comment(lib, "Irrlicht.lib")
IGUIButton *button1, *button2;
class MyEventReceiver : public IEventReceiver
{
public:
bool OnEvent(SEvent event)
{
if (event.EventType == irr::EET_GUI_EVENT &&
event.GUIEvent.EventType == irr::gui::EGET_BUTTON_CLICKED &&
event.GUIEvent.Caller -> getID() == 100) {
printf("TOGGLE\n");
button2->setVisible(not button2->isVisible());
}
return false;
}
};
int main()
{
IrrlichtDevice *device =
createDevice(video::EDT_SOFTWARE2, dimension2d<s32>(640, 480), 16,
false, false, false, 0);
device->setWindowCaption(L"test button");
IVideoDriver *driver = device->getVideoDriver();
ISceneManager *smgr = device->getSceneManager();
IGUIEnvironment *guienv = device -> getGUIEnvironment ();
button1 = guienv->addButton (irr::core::rect<s32> (0, 0, 100, 20), NULL, 100, L"button1");
button2 = guienv->addButton (irr::core::rect<s32> (110, 0, 210, 20), NULL, 200, L"button2");
button2->setVisible(false);
device->setEventReceiver(new MyEventReceiver());
while(device->run())
{
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
guienv->drawAll ();
device->run();
driver->endScene();
}
device->drop();
return 0;
}
[quote][/quote]