event handler: how to create class?

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

Chosker
Just popping in
Just popping in
Posts: 4
Joined: Tue Feb 05, 2008 22:37
Location: Madrid

event handler: how to create class?

Postby Chosker » Thu Feb 07, 2008 18:36

hello there,
I'm new here, new to CEGUI and also kinda new to programming as well. I know I should be starting with more basic stuff, but I've gotten my way around a few of the things I want to do with my project so I want to keep on doing it.

anyway, I got my gui on screen and now I want to have an event handler so that my buttons actually do something. therefore I need to create a new function, and here's where the problem kicks in.
the tutorial/snippet/whatever says I should add a new function by adding something like the following code:

Code: Select all

bool ButtonHandler(const CEGUI::EventArgs& e)
{
     //Code you want Button1 to do
    return true;
}


now if I do it that way then my function is isolated from everything else in my app, which means I have to make the function part of the app class, just like calling-the-mainmenu's function, which is

Code: Select all

void EliumApp::setupCEGUI()
{
... blah blah cegui init code ...
}

instead of just

Code: Select all

void setupCEGUI()
{
... blah blah cegui init code ...
}

(yes, EliumApp is my app)

therefore my new ButtonHandler function must start with:

Code: Select all

bool EliumApp::ButtonHandler(const CEGUI::EventArgs& e)

and as such, I must go back to the EliumApp class definition to add the definition of "ButtonHandler" on it

now here's where the real problem kicks in.
my SetupCEGUI function is defined like this:

Code: Select all

   void setupCEGUI();

so I thought I could define ButtonHandler like that, but since it's got all that "const CEGUI::EventArgs& e" stuff on it, the definition won't work like:

Code: Select all

   bool ButtonHandler();


so, anyone that can tell me the correct way to define my function?
I know this is just basic stuff I should know but I don't :) so plz help me out :)
thanks!

Rackle
CEGUI Team (Retired)
Posts: 534
Joined: Mon Jan 16, 2006 11:59
Location: Montréal

Postby Rackle » Thu Feb 07, 2008 20:12

You could do it like this:

Code: Select all

#include "cegui.h"

class EliumApp
{
public:
  void setupCEGUI();
  bool ButtonHandler(const CEGUI::EventArgs& e)
};


I recommend you read the following code/article: Managing Game States with OGRE. This allows you to spread out your application/game across multiple classes thereby making medium to large applications easier to follow.

Chosker
Just popping in
Just popping in
Posts: 4
Joined: Tue Feb 05, 2008 22:37
Location: Madrid

Postby Chosker » Thu Feb 07, 2008 23:40

yeah that works, that's just the line of code I needed for the definition to work.
now my new game menu handles buttons and does stuff properly. I can start game and quit now :)

mmm that gamestates thing seems interesting, definately would be good to take into account if my game was my own engine (or ogre), but I already have a game alpha (coded by a former team member) and it's based on an existing engine (Nebula2).
I'm just trying to improve the code and add small features while I learn, but adding an elaborate thing like that doesn't seem doable for me

anyway, thanks for the help!


Return to “Help”

Who is online

Users browsing this forum: No registered users and 17 guests