Page 1 of 1
Button click event not work
Posted: Wed Jul 13, 2005 4:16 pm
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!
Posted: Fri Jul 15, 2005 12:50 pm
by Sergio Cossa
Does somebody have an answer for my?
Are all of hollidays in the summer of the north hemisphere?
All the best!
Posted: Fri Jul 15, 2005 2:33 pm
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.
Posted: Fri Jul 15, 2005 3:24 pm
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.
Posted: Fri Jul 15, 2005 11:04 pm
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.
Posted: Sat Jul 16, 2005 11:45 am
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!
in vb.net
Posted: Sat Jul 16, 2005 2:10 pm
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
Posted: Sat Jul 16, 2005 2:46 pm
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!!!

the BUTTON_CLICKED event is captured correctly.
MindGames, I can also close GUI windows from the closing button
All the best!
Posted: Sat Jul 16, 2005 3:41 pm
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
Posted: Sun Jul 17, 2005 11:24 am
by MindGames
Ah yes, obvious now that someone points it out!

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
Posted: Mon Jul 18, 2005 12:01 pm
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
MingGames, thank you, I no longer need their example code
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...
Posted: Wed Jul 20, 2005 10:25 am
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
Posted: Wed Jul 20, 2005 12:46 pm
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