Button click event not work

Irrlicht.Net is no longer developed or supported, Irrlicht.Net Cross Platform is a much more complete wrapper. Please ask your C# related questions on their forums first.
Locked
Sergio Cossa
Posts: 22
Joined: Fri Jun 03, 2005 2:00 pm
Location: Argentina

Button click event not work

Post by Sergio Cossa »

Hi!

I don't know if this is a bug, or I make a mistake in something, or it is not still implemented.

I am working with c#and Irrlicht 0.11

In my main module I have a device.GUIEnvironment and also a device.EventReceiver.
Also, I have added a button with

Code: Select all

guiEnv.AddButton( new Rect(10, 10, 100, 100), null, 101, "Quit");
When it happens an event, I call to the following code:

Code: Select all

public bool OnEvent(Irrlicht.Event e)
{
   if (e.Type == EventType.GUIEvent)
   {
      switch (e.GUIEventType)
     {
        case GUIEvent.ELEMENT_HOVERED:
       {
           // Mi GUI code here
           return true;
       }
        case GUIEvent.BUTTON_CLICKED:
       {
           // Mi GUI code here
           return true;
       }
   }
   return false;
}
The event ELEMENT_HOVERED is fired correctly, but BUTTON_CLICKED is never fired.

Any help, please?

All the best!
Sergio Cossa
Argentina
Sergio Cossa
Posts: 22
Joined: Fri Jun 03, 2005 2:00 pm
Location: Argentina

Post by Sergio Cossa »

Does somebody have an answer for my?

Are all of hollidays in the summer of the north hemisphere? :D

All the best!
Sergio Cossa
Argentina
MindGames

Post by MindGames »

I have just done something pretty similar and it worked OK for me so I doubt it is a bug in Irrlicht. About the only difference in my code is that I also check to see if it is the correct button Id before reacting to the event.
Sergio Cossa
Posts: 22
Joined: Fri Jun 03, 2005 2:00 pm
Location: Argentina

Post by Sergio Cossa »

MindGames,

I modified my code:

Code: Select all

public bool OnEvent(Irrlicht.Event e) 
{ 
   if (e.Type == EventType.GUIEvent) 
   { 
      int id = e.GUIEventCaller.ID;
      if (id == 120) // My button id
         if (e.GUIEventType == GUIEvent.BUTTON_CLICKED)
            // Mi GUI code here 
            return true; 
   } 
   return false; 
} 
I insert a breakpoint in the "return true" line, but the pointer never reaches there.
If I control the events ELEMENT_HOVERED and ELEMENT_LEFT, these are read correctly. Only with BUTTON_CLICKED I don't have answer.

All the best!

EDIT:
I use C# Express 2005 Beta Edition.
Sergio Cossa
Argentina
MindGames

Post by MindGames »

Yeah, I didn't think that the Id would make a difference, I was mainly posting to tell you it does work and is not just an obvious bug.

I am using Visual Studio 2005 Beta2 so it isn't likely to be a .Net 2.0 problem unless of course we are on different versions. I can send you my code to try if you like, I only started playing around with it last night so it is only a few files. It will at least tell you it is an environmental problem.

Post an address I can send it to if you want me to.
Sergio Cossa
Posts: 22
Joined: Fri Jun 03, 2005 2:00 pm
Location: Argentina

Post by Sergio Cossa »

Hi MindGames,

I am also making my first tests, to decide if finally I will use Irrlicht for my game.
I know that it is a great engine and I am sure when the community .NET qrows will have an excellent tool.
Please, send me the code to compare where my error can be, since I am not able to solve it.

My email:
chechocossa@hotmail.com

All the best!
Sergio Cossa
Argentina
karim1a2004
Posts: 41
Joined: Sat Jan 15, 2005 8:03 pm
Contact:

in vb.net

Post by karim1a2004 »

the code

Dim b As GUI.IGUIEnvironment = device.GUIEnvironment
b.AddButton(New Core.Rect(10, 10, 50, 50), Nothing, -1, "Quit")

Public Class MyEventReceiver
Implements IEventReceiver
Public Function OnEvent(ByVal e As [Event]) As Boolean Implements IEventReceiver.OnEvent
If e.Type = EventType.GUIEvent Then
If e.GUIEventType = GUIEvent.BUTTON_CLICKED = True Then End
Return True
End If
Return False

End Function

End Class
Sergio Cossa
Posts: 22
Joined: Fri Jun 03, 2005 2:00 pm
Location: Argentina

Post by Sergio Cossa »

karim,

I test your code and I didn't have answers, but...

I from inside the OnEvent also controlled the event EventType.MouseInput ( in other if )

I made the test of erasing those code lines and YES!!! :D the BUTTON_CLICKED event is captured correctly.

MindGames, I can also close GUI windows from the closing button :D

All the best!
Sergio Cossa
Argentina
karim1a2004
Posts: 41
Joined: Sat Jan 15, 2005 8:03 pm
Contact:

Post by karim1a2004 »

you must declared an event for each type
Public Function OnEvent(ByVal e As [Event]) As Boolean Implements IEventReceiver.OnEvent
If e.Type = EventType.GUIEvent Then
If e.GUIEventType = GUIEvent.BUTTON_CLICKED = True Then End
Return True
End If
Return False

End Function
Public Function OnEvent(ByVal I As [Event]) As Boolean Implements IEventReceiver.OnEvent
If I.Type = EventType.KeyInput Then
If I.Key = 27 Then End
Return True

End If
Return False

A other for the mouse

End Function
MindGames
Posts: 32
Joined: Sat Jul 16, 2005 2:02 am

Post by MindGames »

Ah yes, obvious now that someone points it out! :oops: I had just read that in the docs the other night.

I take it you won't need my code now. I too am looking at whether Irrlicht will do for my game. Looks quite good so far. The progress that Niko is making on the .NET stuff appears to be quite rapid.

I have looked at a lot of other engines and this appears most suitable for me so far. It has most the features I think I need and appears to be quite simple to work with (a bit of a must for me as graphics are not my favourite part of the game).

Axiom/Ogre would be my other option but while it does appear to be a bit more feature rich, it a big and complex solution to a not so big and complicated requirement. Also, the Axiom progress is somewhat lethargic and with the size of Ogre and the fact that they are rewriting it completely in .Net, this means a long time before anything commercially viable is complete
Sergio Cossa
Posts: 22
Joined: Fri Jun 03, 2005 2:00 pm
Location: Argentina

Post by Sergio Cossa »

Thank you karim.
I didn't know about that separation of the events :?

But... the good thing when the things don't work it is that they force to
investigate :D

MingGames, thank you, I no longer need their example code :D

I also test RealmForge engine, it is based on the support of Axiom. I think that it will be a great engine, but for the time being, in their state alpha, I find very complicated to begin...
Sergio Cossa
Argentina
karim1a2004
Posts: 41
Joined: Sat Jan 15, 2005 8:03 pm
Contact:

Post by karim1a2004 »

Public Class MyEventReceiver
Implements IEventReceiver

Public Function OnEvent(ByVal e As [Event]) As Boolean Implements IEventReceiver.OnEvent
If e.Type = EventType.KeyInput Then
If e.Key = 27 Then End

Return True
End If
Return False
End Function
Public Function OnGuiEvent(ByVal i As [Event]) As Boolean Implements IEventReceiver.OnEvent
If i.Type = EventType.GUIEvent Then
If i.GUIEventType = GUIEvent.BUTTON_CLICKED Then End

Return True
End If
Return False


End Function

End Class

this code is tested ok from my
karim1a2004
Posts: 41
Joined: Sat Jan 15, 2005 8:03 pm
Contact:

Post by karim1a2004 »

again a other event type
Public Class MyEventReceiver
Implements IEventReceiver

Public Function OnEvent(ByVal e As [Event]) As Boolean Implements IEventReceiver.OnEvent
If e.Type = EventType.KeyInput Then
If e.Key = 32 Then End
Return True
End If
If e.Type = EventType.GUIEvent Then
If e.GUIEventType = GUIEvent.MESSAGEBOX_OK Then End

Return True
End If
Return False
End Function


End Class
Locked