event questions...

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

User avatar
walaber
Not too shy to talk
Not too shy to talk
Posts: 21
Joined: Sun Jan 23, 2005 10:20
Contact:

event questions...

Postby walaber » Mon Jan 31, 2005 09:40

I'm having a lot of fun working on an editor with Ogre+CEGUI... here are some screenshots:

Image
Image

and now on to my problem:

as you can see I have a TabPane in the main rendering window, serving as my "main menu". if the user presses the "Load Mesh" button (top one), then I do pane->setEnabled(false), and I show my "LoadDialog", which is a seperate class. then, I set an event (to actually load the selected mesh), when the TabPane is Enabled (TabPane::EventEnabled).

then, when the user clicks the "OK" button in the OpenDialog window, it closes itself, and enables the TabPane... this triggers the event, and the system loads the mesh.

so far so good.

however, I also have an "AddPrimitive" button (2nd button from top). it works similarly. when the user clicks it, I dis-enable the TabPane, and show the AddPrimitiveDialog (another class). in the same way, when the user clicks OK, it enables the TabPane, and the event is triggered (this time adding a primitive to the scene).


the problem, as you have probably already guessed, is that the events "stack up". so, the first time I click OpenMesh, everything works fine. but if I try to open another mesh, it calls the OpenMesh function twice. If I click again, it calls the function (fires the event) 3 times! I assume this is because I am subscribing the event again, each time the button is clicked.

the reason I re-assign the event, is that I want a different function called when the TabPane is re-enabled, depending upon which button the user clicked.


I thought the solution would be to remove any events assigned to the TabPane after a command is complete. so I setup a simple bool variable "removeEvents". at the end of the last function in an event callback, I set this bool to "true". then in my main FrameListener, I check if the variable is true, and if it is, I call the pane->removeAllEvents() command, hoping to clear out all events assigned to this.

however it crashes, and I get an error in my CEGUI log:
Exception: No event named 'StartRender' is defined for this EventSet


so I think it's trying to delete events that don't even exist...

so to make a long story short...
as you can see, I'm trying to re-use a certain event for different purposes, by basically "over-writing" to callback function that I want to be called.... how should I be doing this?

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: event questions...

Postby CrazyEddie » Mon Jan 31, 2005 11:23

Hi,

When you subscribe to an event, you get returned an Event::Connection object; this may be used to later 'unsubscribe' from the event. There's also a ScopedConnection which auto-unsubscribes as it goes out of scope.

Spoke was looking at ways to unsubscribe by passing the signature used to originally subscribe, though I'm not sure how that went. This may still be added as a feature at some point, since it saves manually tracking all the connection objects.

There is no method that will remove all subscriptions for an event, since you may not be the only one with handlers subscribed (the system itself may be attached there too!).

The method you're calling is removing the events themselves, which is why you get the exception later on when the system tries to fire an event that you deleted ;)

HTH

CE.

User avatar
walaber
Not too shy to talk
Not too shy to talk
Posts: 21
Joined: Sun Jan 23, 2005 10:20
Contact:

Re: event questions...

Postby walaber » Mon Jan 31, 2005 15:46

nice. that cleared up a lot! I'll fix up my system using the proper ways.

I'll post more results when the program is farther along. :D

User avatar
walaber
Not too shy to talk
Not too shy to talk
Posts: 21
Joined: Sun Jan 23, 2005 10:20
Contact:

Re: event questions...

Postby walaber » Tue Feb 01, 2005 04:22

getting the hang of things.. I implemented a simple error dialog today.. :)

Image

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: event questions...

Postby CrazyEddie » Tue Feb 01, 2005 09:15

Glad you're getting into the swing of things. The screen shots look good :)

CE.

User avatar
Spoke
Quite a regular
Quite a regular
Posts: 48
Joined: Wed Jan 12, 2005 12:06
Location: Spain
Contact:

Re: event questions...

Postby Spoke » Wed Feb 23, 2005 22:26

Ups! I miss this one.

At the end I decide not to hack CEGUI directly, since I didn´t have too much time to do it properly.

I end coding some warper classes that translate CEGUI events to our internal event system and keep the connection objects.

Works just fine for us, but I really would like a cleanner solution, right now I have a class per GUI element in CEGUI.

When I manage to have some time, I will think about this and propose something. ;)
May the Force be with you!

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: event questions...

Postby CrazyEddie » Thu Feb 24, 2005 09:43

When I manage to have some time, I will think about this and propose something. ;)


Or maybe I'll beat you to it :lol:


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 11 guests