(solved) Creating a new Event

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

zarroba
Not too shy to talk
Not too shy to talk
Posts: 22
Joined: Tue Jul 11, 2006 12:54

(solved) Creating a new Event

Postby zarroba » Thu Nov 22, 2007 10:39

I'm implementing a new ItemEntry widget that is, basically, a TreeItem. This widget has a button where I click to open its children. I want to add an event to this widget to tell when this button is pressed. I created the const variable in my CEGUITreeItem:

Code: Select all

const String TreeItem::EventTreeItemExpanded( "TreeItemExpanded" );


I wired the click of the button to a new method (I'm using a toggle button created by me):

Code: Select all

button->subscribeEvent(ToggleButton::EventCheckStateChanged, Event::Subscriber(&CEGUI::TreeItem::button_SelectionHandler, this));


and in button_SelectionHandler I fire an event:

Code: Select all

bool TreeItem::button_SelectionHandler(const EventArgs& e)
{
    this->setExpanded(!this->isExpanded());

    WindowEventArgs args(this);
    onExpandedChanged(args);

    return true;
}


and onExpandedChanged code:

Code: Select all

void TreeItem::onExpandedChanged(WindowEventArgs& e)
{
        fireEvent(EventTreeItemExpanded, e, EventNamespace);
}


In my application I subscribe the list with this event:

Code: Select all

WindowManager::getSingleton().getWindow("Demo7/Window2/Listbox")->
        subscribeEvent(TreeItem::EventTreeItemExpanded, Event::Subscriber(&Demo7Sample::handleExpand, this));


But when I click the button all these methods are executed but the one in my application. Because the use I'll have with these trees is very dynamic I wouldn't like to subscribe each node of the tree. How can I make this event to be subscribed by the list and make it work?

Thanks,
José Tavares
Last edited by zarroba on Thu Nov 22, 2007 15:49, edited 1 time in total.

zarroba
Not too shy to talk
Not too shy to talk
Posts: 22
Joined: Tue Jul 11, 2006 12:54

Postby zarroba » Thu Nov 22, 2007 10:50

Well while I was writing this post I had an idea. I stil wrote and post it because it could be of use by someone. What I did whas to change the onExpandedChanged to this:

Code: Select all

void TreeItem::onExpandedChanged(WindowEventArgs& e)
{
        d_ownerList->fireEvent(EventTreeItemExpanded, e, EventNamespace);
}


But I somehow doubt that this is the right way to do it. It works and because you can get the selected item from the list, you can still access the node you clicked on. Is this the right way to do it? is there a better way?

Thanks,
José Pedro Tavares

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Thu Nov 22, 2007 11:27

Sounds like a good apprauch, especially since you say you don't want to subscribe to all nodes.

You know that there is already a tree control in SVN, don't you? ;)
Check out my released snake game using Cegui!

zarroba
Not too shy to talk
Not too shy to talk
Posts: 22
Joined: Tue Jul 11, 2006 12:54

Postby zarroba » Thu Nov 22, 2007 11:41

Yes, but the use I'll make of the tree has some specificities that made me easier to create a new one rather than adapt an existent one. It's almost finish so I won't have much more work to do with them.

José Tavares

User avatar
fjeronimo
CEGUI Tools Developer (Retired)
Posts: 59
Joined: Tue Sep 11, 2007 16:57
Location: Lisbon, Portugal
Contact:

Postby fjeronimo » Fri Nov 23, 2007 09:50

Always nice to see another portuguese... :)
Frederico Jerónimo
Ignite Games - http://www.ignite-games.com
Ignite Games Institutional Site - http://we.ignite-games.com


Return to “Help”

Who is online

Users browsing this forum: No registered users and 13 guests