<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://cegui.org.uk/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Wang37921</id>
		<title>CEGUI Wiki - Crazy Eddie's GUI System (Open Source) - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://cegui.org.uk/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Wang37921"/>
		<link rel="alternate" type="text/html" href="http://cegui.org.uk/wiki/Special:Contributions/Wang37921"/>
		<updated>2026-04-11T03:43:34Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.24.1</generator>

	<entry>
		<id>http://cegui.org.uk/wiki/index.php?title=Identifying_Multiple_Event_Sources_From_A_Single_Callback&amp;diff=3350</id>
		<title>Identifying Multiple Event Sources From A Single Callback</title>
		<link rel="alternate" type="text/html" href="http://cegui.org.uk/wiki/index.php?title=Identifying_Multiple_Event_Sources_From_A_Single_Callback&amp;diff=3350"/>
				<updated>2010-01-09T15:46:47Z</updated>
		
		<summary type="html">&lt;p&gt;Wang37921: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Sometimes you would like to identify the sender of an event from within your callback function.  For example, you would like to execute some common code for your buttons, like triggering a sound to be played on CEGUI::PushButton::EventClicked.  Here is an example [http://www.cegui.org.uk/api_reference/classCEGUI_1_1PushButton.html CEGUI::PushButton] we would like to wire up:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;cpp/&amp;gt;&lt;br /&gt;
CEGUI::PushButton* pushButton = &lt;br /&gt;
  static_cast&amp;lt;CEGUI::PushButton*&amp;gt;&lt;br /&gt;
    (CEGUI::WindowManager::getSingleton().createWindow(&amp;quot;WindowsLook/Button&amp;quot;, &amp;quot;TheButton&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
pushButton-&amp;gt;subscribeEvent(CEGUI::PushButton::EventClicked,&lt;br /&gt;
                           CEGUI::Event::Subscriber(&amp;amp;MainMenu::OnButtonClick, this));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To do this, simply cast the [http://www.cegui.org.uk/api_reference/classCEGUI_1_1EventArgs.html CEGUI::EventArgs] in your callback to a [http://www.cegui.org.uk/api_reference/classCEGUI_1_1WindowEventArgs.html CEGUI::WindowEventArgs]. The CEGUI::WindowEventArgs object contains a pointer to the [http://www.cegui.org.uk/api_reference/classCEGUI_1_1Window.html CEGUI::Window] that sent the event.  Now its as easy as calling CEGUI::Window::getName().  Obviously, you can do much more now that you have a pointer to the window who fired the event, but this is just an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;cpp/&amp;gt;&lt;br /&gt;
bool MainMenu::OnButtonClick(const CEGUI::EventArgs&amp;amp; e)&lt;br /&gt;
{&lt;br /&gt;
  const CEGUI::MouseEventArgs&amp;amp; we = &lt;br /&gt;
    static_cast&amp;lt;const CEGUI::MouseEventArgs&amp;amp;&amp;gt;(e);&lt;br /&gt;
&lt;br /&gt;
  CEGUI::String senderID = we.window-&amp;gt;getName();&lt;br /&gt;
&lt;br /&gt;
  if (senderID == &amp;quot;TheButton&amp;quot;)&lt;br /&gt;
  {&lt;br /&gt;
    // code for dealing with a &amp;quot;TheButton&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  return true;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Wang37921</name></author>	</entry>

	</feed>