Windows closing

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

pista75
Not too shy to talk
Not too shy to talk
Posts: 22
Joined: Sun May 15, 2011 10:41

Windows closing

Postby pista75 » Wed Sep 21, 2011 15:58

Hi guys.
My problem is very simple.
I write popup windows,and close with the X button in the corner.
I so far always write new function to all windows.
e.g.:
If two window:

Code: Select all


//...
PopupW1->subscribeEvent(FrameWindow::EventCloseClicked, Event::Subscriber(&EventButtonDown::PopupW1, EventDown));
//...
 bool EventButtonDown::PopupW1(const CEGUI::EventArgs& /*e*/)
 {
  CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();
 
  wmgr.destroyWindow(PopupW1);
  return true;
 }

//...
PopupW2->subscribeEvent(FrameWindow::EventCloseClicked, Event::Subscriber(&EventButtonDown::PopupW2, EventDown));
//...
 bool EventButtonDown::PopupW2(const CEGUI::EventArgs& /*e*/)
 {
  CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();
 
  wmgr.destroyWindow(PopupW2);
  return true;
 }


If ten window:

Code: Select all

 
//...
PopupW1->subscribeEvent(FrameWindow::EventCloseClicked, Event::Subscriber(&EventButtonDown::PopupW1, EventDown));
//...
 bool EventButtonDown::PopupW1(const CEGUI::EventArgs& /*e*/)
 {
  CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();
 
  wmgr.destroyWindow(PopupW1);
  return true;
 }

//...
PopupW2->subscribeEvent(FrameWindow::EventCloseClicked, Event::Subscriber(&EventButtonDown::PopupW2, EventDown));
//...
 bool EventButtonDown::PopupW2(const CEGUI::EventArgs& /*e*/)
 {
  CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();
 
  wmgr.destroyWindow(PopupW2);
  return true;
 }

//...
PopupW3->subscribeEvent(FrameWindow::EventCloseClicked, Event::Subscriber(&EventButtonDown::PopupW3, EventDown));
//...
 bool EventButtonDown::PopupW3(const CEGUI::EventArgs& /*e*/)
 {
  CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();
 
  wmgr.destroyWindow(PopupW2);
  return true;
 }
//...
PopupW4->subscribeEvent(FrameWindow::EventCloseClicked, Event::Subscriber(&EventButtonDown::PopupW4, EventDown));
//...
 bool EventButtonDown::PopupW4(const CEGUI::EventArgs& /*e*/)
 {
  CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();
 
  wmgr.destroyWindow(PopupW2);
  return true;
 }
//And the other to 6 ...


It's very difficult that each window plus function in my code.

Is there a simpler way,that close windows?

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: Windows closing

Postby Kulik » Wed Sep 21, 2011 17:02

1) Subclass and subscribe the callback in constructor
2) Templated callback (fancy but I wouldn't use this)

These are two solutions that popped up in my head right now. Maybe there are more :-)

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Re: Windows closing

Postby Jamarr » Wed Sep 21, 2011 17:43

Another option is to subscribe to the event globally via the CEGUI::GlobalEventSet. There are plenty of references demonstrating how to subscribe to global events, which you can find by searching these forums.
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!

ShadowTiger
Quite a regular
Quite a regular
Posts: 46
Joined: Fri Mar 19, 2010 05:31

Re: Windows closing

Postby ShadowTiger » Fri Sep 23, 2011 05:17

This is how I would do it. I think it is the simplest solution.

Code: Select all

PopupW1->subscribeEvent(FrameWindow::EventCloseClicked, Event::Subscriber(&EventButtonDown::PopupW, EventDown));
PopupW2->subscribeEvent(FrameWindow::EventCloseClicked, Event::Subscriber(&EventButtonDown::PopupW, EventDown));
PopupW3->subscribeEvent(FrameWindow::EventCloseClicked, Event::Subscriber(&EventButtonDown::PopupW, EventDown));

bool EventButtonDown::PopupW(const CEGUI::EventArgs& eArgs)
 {
  CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();

  const CEGUI::WindowEventArgs& we = static_cast<const CEGUI::WindowEventArgs&>(eArgs);

  wmgr.destroyWindow(we.window);
  return true;
 }

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: Windows closing

Postby Kulik » Fri Sep 23, 2011 06:25

ShadowTiger is right, templating is not needed for this.


Return to “Help”

Who is online

Users browsing this forum: Google [Bot] and 6 guests