Crystal Space
Welcome, Guest. Please login or register.
July 30, 2014, 08:24:43 am

Login with username, password and session length
Search:     Advanced search
9009 Posts in 2047 Topics by 8259 Members
Latest Member: Robinfallon
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  [Resolved] CEGUI subscribeEvent
« previous next »
Pages: [1] Print
Author Topic: [Resolved] CEGUI subscribeEvent  (Read 5494 times)
Rage
Newbie
*
Posts: 5


View Profile Email
« on: February 27, 2008, 10:58:25 pm »

- Version of CS : 1.2
- Version of winlibs package (if on windows) : 1.2_002
- Operating system : Windows XP SP2
- Compiler : Visual studio 2008 Express

Hi,

I'm new to CS and I have again a problem...

I have followed some tutorials and subscribing an event to a pushButton seems easy. It works well when the code is in the 'main' csApplicationFramework, but when I want to change the subscribing to another class, it does not work no more.

Here is the code (which works) in the main class:
Code:
csRef<iCEGUI> cegui = csQueryRegistry<iCEGUI> (GetObjectRegistry());
CEGUI::WindowManager* winMgr = cegui->GetWindowManagerPtr ();
CEGUI::Window* btn = winMgr->getWindow("Tools/Quit");
btn->subscribeEvent(CEGUI::PushButton::EventClicked,
CEGUI::Event::Subscriber(&GameEditor::OnExitButtonClicked, this));

And here is the code (which do not works) in another class:
Code:
csRef<iCEGUI> cegui = csQueryRegistry<iCEGUI> (objectRegistry);
CEGUI::Window* btn = winMgr->getWindow("Tools/Quit");
btn->subscribeEvent(CEGUI::PushButton::EventClicked,
CEGUI::Event::Subscriber(&Gui::OnExitButtonClicked, this));

You can notice that there isn't a big difference between the two. This is why I don't understand the problem.

The method is declared public in the 2 classes. Here is the code of the non working class
Header:
Code:
#ifndef __GAME_EDITOR_GUI_H__
#define __GAME_EDITOR_GUI_H__

#include <crystalspace.h>
#include "ivaria/icegui.h"
#include <CEGUI.h>

class Gui
{
public:
bool Initialize(iObjectRegistry* objectRegistry);
void Draw();

bool OnExitButtonClicked (const CEGUI::EventArgs& e);

private:
    csRef<iCEGUI> cegui;
iObjectRegistry* objectRegistry;
};

#endif // __GAME_EDITOR_GUI_H__

source:
Code:
#include <CEGUIWindowManager.h>

#include "Gui.h"

bool Gui::Initialize(iObjectRegistry* objectRegistry)
{
//this->objectRegistry = objectRegistry;

//Load and initialize Cegui plugin
cegui = CS_QUERY_REGISTRY (objectRegistry, iCEGUI);
if (!cegui) {
return false;
}

if(!cegui->Initialize()) {
return false;
}

cegui->GetLoggerPtr ()->setLoggingLevel(CEGUI::Informative);

//Change directory to ice directory
csRef<iVFS> vfs = CS_QUERY_REGISTRY (objectRegistry, iVFS);
vfs->ChDir ("/PremiersAges/gui/");

//Load a scheme
cegui->GetSchemeManagerPtr ()->loadScheme("ice.scheme");

//define cursor
cegui->GetSystemPtr ()->setDefaultMouseCursor("ice", "MouseArrow");

//Defines font
CEGUI::Font* font = cegui->GetFontManagerPtr ()->createFont("FreeType", "Vera", "/fonts/ttf/Vera.ttf");
font->setProperty("PointSize", "10");
font->load();

//setup CEGUI callback functions
CEGUI::WindowManager* winMgr = cegui->GetWindowManagerPtr ();

// Load layout and set as root
CEGUI::Window* sheet = winMgr->loadWindowLayout("ice.layout");

csRef<iCEGUI> cegui = csQueryRegistry<iCEGUI> (objectRegistry);
CEGUI::Window* btn = winMgr->getWindow("Tools/Quit");
btn->subscribeEvent(CEGUI::PushButton::EventClicked,
CEGUI::Event::Subscriber(&Gui::OnExitButtonClicked, this));

return true;
}

void Gui::Draw()
{
cegui->Render ();
}

bool Gui::OnExitButtonClicked (const CEGUI::EventArgs&)
{
  return true;
}

The error is an access violation and occurs on this line :
Code:
CEGUI::Event::Subscriber(&Gui::OnExitButtonClicked, this)


Please help me !!

Regards,

Rage
« Last Edit: February 29, 2008, 09:15:36 pm by Rage » Logged
Panch
Jr. Member
**
Posts: 80


View Profile Email
« Reply #1 on: February 28, 2008, 07:14:12 pm »

I had this problem and had to initialize CS objects outside of the "main" class in a different manner then GetObjectRegistry(). Here is an example:

Code:
// Initialize the Keyboard class
bool Keyboard::Initialize(iObjectRegistry* obj_reg)
{
    object_reg = obj_reg;
randSteps = 0;
battleEnd = false;
done = false;

    keybd = csQueryRegistryOrLoad<iKeyboardDriver> (object_reg,
        "crystalspace.driver.input.generic.keyboard");
    if (!keybd)
    {
        csReport (object_reg,
    CS_REPORTER_SEVERITY_ERROR, "Phage.keyboard",
"Can't load the keyboard driver!");
        return false;
    }   

    return true;
}

The problem here is that you need to get the specific plug-in name which puts you are the mercy of the public API (they are given in the General Description of the class, if at all). Or you can ask for help on the boards looking for the specific plug-in name.
Logged
Rage
Newbie
*
Posts: 5


View Profile Email
« Reply #2 on: February 29, 2008, 08:12:05 pm »

Thanks for the  response,

I'm very bad in English and I not sure to have well understood all that you was saying, but  I have loaded the library outside of my "main" class now, and the problem still persists.
I have made this changed "cegui = csQueryRegistryOrLoad<iCEGUI> (objectRegistry, "crystalspace.cegui.wrapper");" like in your example.

cegui is loaded well, because all its method are successfully called, except the "subscribeEvent" one.

perhaps I have missed something...

If you have another idea...

Regards,

Rage
Logged
Rage
Newbie
*
Posts: 5


View Profile Email
« Reply #3 on: February 29, 2008, 09:15:07 pm »

And the response is...

#include <CEGUIWindowManager.h>

I had this include at the top of my Gui class implementation.
I have removed it, and it works!

Don't ask me why...

Regards and thanks,

Rage
Logged
Panch
Jr. Member
**
Posts: 80


View Profile Email
« Reply #4 on: February 29, 2008, 10:58:42 pm »

Ah good Smiley

If you referenced one of the other header files that already had CEGUIWindowManager.h included then you had it referenced twice; I've seen weird issues when that happens.
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 6.292 seconds with 15 queries.