Not able to click a button

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.
Post Reply
Worteltaart
Posts: 17
Joined: Sat Mar 24, 2007 5:03 pm
Location: Holland

Not able to click a button

Post by Worteltaart »

Though I've written the code in a .NET wrapper for Irrlicht (CP) I won't have any trouble converting code from c++ to C#, that being said, the following problem occurs when I try to add a Button to my project.

First I make a pointer to the GUIEnvironment using:

Code: Select all

GUIEnvironment guienv = device.GUIEnvironmentl
After which I simply add a button to the guienv:

Code: Select all

guienv.AddButton(myRect, guienv.RootElement, 1001, "testButton");
After which I have the guienv being drawn in my main loop:

Code: Select all

if (device.WindowActive)
{
    driver.BeginScene(true, true, new Color(0, 100, 100, 100));
    guienv.DrawAll();
    smgr.DrawAll();
    driver.EndScene(); 
}
The button gets drawn as it should, but I can't click it, any ideas?
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

Do you have an event receiver to catch the click? Are you calling device.run() in the loop?
If you don't have anything nice to say, don't say anything at all.
Worteltaart
Posts: 17
Joined: Sat Mar 24, 2007 5:03 pm
Location: Holland

Post by Worteltaart »

Yes, I have done both,
Code for my event delegate (in short ofc.):

Code: Select all

public bool OnEvent(Event p_e)
{
    int eventID = p_e.Caller.ID;

    if (p_e.Type == EventType.GUIEvent)
    {
        switch (p_e.GUIEvent)
        {
            case(GUIEventType.ButtonClicked) :
            {
                 if (eventID == 101)
                 {
                      // perform_magic();
                      return true;
                  }
                  break;
                 // snip snip
              }
          }
      }
     return true;
}
Thing is, the button gets drawn as it's supposed to be, but it's just not clickable (even without an event catcher, it still would look like it's been clicked if you click it, like it's being pushed, you get the idea)
Masterhawk
Posts: 299
Joined: Mon Nov 27, 2006 6:52 pm
Location: GERMANY
Contact:

Post by Masterhawk »

Try "return false;" at the end instead of "return true;"
Image
Worteltaart
Posts: 17
Joined: Sat Mar 24, 2007 5:03 pm
Location: Holland

Post by Worteltaart »

The return true at the bottom was a typo.

I have loaded a "world" from textures and a heightmap, and I try to draw the GUI over it, maybe this causes the error, any clues?

In other words, I render both a scene and a guienv in my device.run() loop, is this the problem, and if so, how to fix :)

I could post the code I've written, but it's in two files (+ some texture files) and well, it's quite messy ;)
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Post by xDan »

Do you handle mouse input? EMIE_LMOUSE_PRESSED_DOWN etc, the solution for me was to return false at that point (as Masterhawk said).
Worteltaart
Posts: 17
Joined: Sat Mar 24, 2007 5:03 pm
Location: Holland

Post by Worteltaart »

That's exactly what went wrong indeed.

I commented out the mouse handlers, but what now?
I need the mouse handler for scrolling the map!
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Post by xDan »

Don't comment it out, just make sure you return false within it (or them) not true.

e.g.

Code: Select all

if (e.EventType == EET_MOUSE_INPUT_EVENT && e.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
{
	// blah
	return false;
}
Worteltaart
Posts: 17
Joined: Sat Mar 24, 2007 5:03 pm
Location: Holland

Post by Worteltaart »

Ah I see, thanks a bunch, works perfectly!
Common sense is what tells you the world is flat.
Post Reply