Page 1 of 1

Mapping Subscribe slots for use in layout?

Posted: Sat Dec 31, 2011 12:44
by Zoomulator
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? )

Re: Mapping Subscribe slots for use in layout?

Posted: Sun Jan 01, 2012 03:28
by pav
Search the wiki for Lua or PyCEGUI, I think it's exactly what you want.

Re: Mapping Subscribe slots for use in layout?

Posted: Sun Jan 01, 2012 10:39
by Zoomulator
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>

Re: Mapping Subscribe slots for use in layout?

Posted: Sun Jan 01, 2012 13:00
by CrazyEddie
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