Mapping Subscribe slots for use in layout?

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

Zoomulator
Just popping in
Just popping in
Posts: 8
Joined: Tue Dec 20, 2011 22:12

Mapping Subscribe slots for use in layout?

Postby Zoomulator » Sat Dec 31, 2011 12:44

So I'm a bit new at this, so correct me if I'm wrong.

AFAIK, when you define a window in a layout XML and load it, you gotta fetch that window by name in c++ to attach a subscriber slot for an event.

Code: Select all

Window* win = static_cast<Window*>( windowmgr.getWindow( "myWindow" ) );
win->subscribeEvent( Window::EventClicked, SubscriberSlot( &handler, obj) );


So if I chose to remove or rename a window in the layout file it will throw an exception when trying to access the window by name in the c++ code. Kind of defeats part of the purpose of using the layout file..

Is there a way to make these bindings more dynamic? I'd like to register the SubscriberSlots somewhere and then link them by declaring the event and slot in the layout file, not in the c++ code.

If there's no system in place to do this already, I'd like to suggest it! ( Should I post it in another forum in that case? )

pav
Not too shy to talk
Not too shy to talk
Posts: 37
Joined: Thu Dec 01, 2011 14:17

Re: Mapping Subscribe slots for use in layout?

Postby pav » Sun Jan 01, 2012 03:28

Search the wiki for Lua or PyCEGUI, I think it's exactly what you want.

Zoomulator
Just popping in
Just popping in
Posts: 8
Joined: Tue Dec 20, 2011 22:12

Re: Mapping Subscribe slots for use in layout?

Postby Zoomulator » Sun Jan 01, 2012 10:39

Myeah... kind of right, just want it without the lua =P

I guess lua is fine, but then I'd have to bind my C++ functions/methods to lua first in order to use them in the XML, which just seems like a pointless indirection if I've got the whole setup with the subscriberslot eventhandlers already.

Registering a SubscriberSlot, without directly tying it to a window in c++, and then using <Event Name="Clicked" Function="myCppEventHandler" /> would be even better imo. No chance of doing that?

Here's an imaginary piece of code of how I'd like to go about registering a function to a window:

Code: Select all


// --- In C++
CEGUI::System::RegisterEventHandler( "myCppEventHandler" /*handlerName*/, SubscriberSlot( &myObj::doStuff, obj ) ); 
/* Or similar 'global' registry*/

// --- In layout XML
<?xml version="1.0"?>
 <GUILayout>
 <Window Type="TaharezLook/Button" Name="CPP_powered_button">
 <Property Name="Width" Value="0.1" />
 <Property Name="Height" Value="0.1" />
 <Property Name="XPosition" Value="0.1" />
 <Property Name="YPosition" Value="0.1" />
 <Event Name="Clicked" Function="myCppEventHandler" />
 </Window>
 </GUILayout>

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

Re: Mapping Subscribe slots for use in layout?

Postby CrazyEddie » Sun Jan 01, 2012 13:00

Basically you can do this by using (abusing?) the ScriptModule interface. Rather than using Lua or some other existing ScriptModule, you would create on which does exactly as you suggest - allows you to register function names which can be subscribed via layouts.

This article is mostly still valid - it gives a good starting point from which you can expand: http://www.cegui.org.uk/wiki/index.php/ ... tingModule

CE


Return to “Help”

Who is online

Users browsing this forum: No registered users and 26 guests