Page 1 of 2

button->setVisible(false) not working

Posted: Tue Oct 03, 2006 7:03 pm
by wheatas
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?

Posted: Tue Oct 03, 2006 8:14 pm
by JP
Show us the parts of code that you do the hiding and unhiding etc. Might give some clues!

Posted: Tue Oct 03, 2006 8:27 pm
by wheatas
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);
}

Posted: Tue Oct 03, 2006 8:29 pm
by hybrid
So does it show up if you choose 1 initially? Maybe you don't draw the GUI at all?

Are you sure

Posted: Wed Oct 04, 2006 12:50 am
by MikePhelps
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

Posted: Wed Oct 04, 2006 8:25 am
by wheatas
@hybrid:
yes, if I set visible to 1 initialy it shows up right from the beginning...

@MikePhelps
yes, I'm sure the event is called, because the text of some of the buttons changes... (the ones that should stay visible)

but when irrlicht does'nt allow to set it visible, why does it appear???

Posted: Wed Oct 04, 2006 8:28 am
by wheatas
but when irrlicht does'nt allow to set it visible, why does it appear???

comment: this should not mean that I checked this till now...

Posted: Wed Oct 04, 2006 8:35 am
by wheatas
Hi again,

ok checked it and the isVisible returns 1 so ...

any other idea why its not working???

thanks

Posted: Wed Oct 04, 2006 11:07 am
by monkeycracks
i always used

setVisible(false);
or setVisible(true);


and never had problems, maybe its the same maybe its different. I dunno ;)

Posted: Wed Oct 04, 2006 11:09 am
by monkeycracks
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);
}
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...

try chainging
possibility[x]->setText(text.c_str());
possibility[x]->setVisible(1);
to
possibility[y]->setText(text.c_str());
possibility[y]->setVisible(1);

Posted: Wed Oct 04, 2006 12:05 pm
by stef_
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.

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;
}
Bye

Posted: Wed Oct 04, 2006 12:22 pm
by wheatas
@moneycracks
i always used

setVisible(false);
or setVisible(true);

tried it, same behaviour... :cry:

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?

Posted: Wed Oct 04, 2006 12:35 pm
by CuteAlien
stef_ wrote:

Code: Select all

			button2->setVisible(~button2->isVisible());
That's not correct, you can't do that with bools.
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;
}
@wheatas:
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.

Posted: Wed Oct 04, 2006 1:00 pm
by wheatas
sounds more like it...

now I tried to do
environment->drawAll();
after the new selection of visible buttons...


(tried only button->draw() before)

but still does'nt work...
is there any other proceedure to draw the gui or is it correct with drawAll?

Posted: Wed Oct 04, 2006 1:19 pm
by stef_
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:

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]