button->setVisible(false) not working

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.
wheatas
Posts: 25
Joined: Fri Sep 15, 2006 8:21 am

button->setVisible(false) not working

Post 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?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Show us the parts of code that you do the hiding and unhiding etc. Might give some clues!
Image Image Image
wheatas
Posts: 25
Joined: Fri Sep 15, 2006 8:21 am

Post 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);
}
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

So does it show up if you choose 1 initially? Maybe you don't draw the GUI at all?
MikePhelps
Posts: 1
Joined: Wed Oct 04, 2006 12:47 am
Contact:

Are you sure

Post 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
wheatas
Posts: 25
Joined: Fri Sep 15, 2006 8:21 am

Post 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???
wheatas
Posts: 25
Joined: Fri Sep 15, 2006 8:21 am

Post 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...
wheatas
Posts: 25
Joined: Fri Sep 15, 2006 8:21 am

Post by wheatas »

Hi again,

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

any other idea why its not working???

thanks
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

i always used

setVisible(false);
or setVisible(true);


and never had problems, maybe its the same maybe its different. I dunno ;)
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post 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);
stef_
Posts: 53
Joined: Tue Apr 18, 2006 9:39 pm
Contact:

Post 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
wheatas
Posts: 25
Joined: Fri Sep 15, 2006 8:21 am

Post 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?
CuteAlien
Admin
Posts: 9716
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post 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.
wheatas
Posts: 25
Joined: Fri Sep 15, 2006 8:21 am

Post 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?
stef_
Posts: 53
Joined: Tue Apr 18, 2006 9:39 pm
Contact:

Post 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]
Post Reply