Page 1 of 1
How to create my own window?
Posted: Thu Dec 14, 2006 05:33
by kofight
When using a derived window public from CEGUI::Window, how to create it.
Window *wnd = winMgr.createWindow("TaharezLook/FrameWindow", "Demo Window"); //It works
root->addChildWindow(wnd);
Window *wnd = new CTitleWindow("TaharezLook/FrameWindow", "Demo Window"); //Nothing showed up
root->addChildWindow(wnd);
CTitleWindow is a class public from CEGUI::Window, and did nothing.
Posted: Thu Dec 14, 2006 05:54
by lindquist
You must create a WindowFactory class for your new Window class and register it with the WindowFactoryManager.
The base widgets all use a macro to create the factory class and are registered in CEGUISystem.cpp
Posted: Thu Dec 14, 2006 07:06
by kofight
Thank you, I found that I need a WindowFactory, so I do that, but...
this is TitleWindow.h
#pragma once
#include <CEGUI/CEGUIWindow.h>
#include <CEGUI/CEGUIWindowFactory.h>
class CTitleWindow : public CEGUI::Window
{
public:
static const CEGUI::String WidgetTypeName; //!< Window factory name
CTitleWindow(const CEGUI::String& type, const CEGUI::String& name);
virtual ~CTitleWindow();
};
namespace CEGUI
{
CEGUI_DECLARE_WINDOW_FACTORY(CTitleWindow)
}
This is TitleWindow.cpp
#include "TitleWindow.h"
using namespace CEGUI;
const String CTitleWindow::WidgetTypeName("TitleWindow");
namespace CEGUI
{
CEGUI_DEFINE_WINDOW_FACTORY(CTitleWindow)
}
CTitleWindow::CTitleWindow(const String& type, const String& name)
:Window(type, name)
{
}
CTitleWindow::~CTitleWindow()
{
}
And the code to create window.
WindowFactoryManager& wfMgr = WindowFactoryManager::getSingleton();
wfMgr.addFactory(&CEGUI_WINDOW_FACTORY(CTitleWindow));
//Window *wnd = new CTitleWindow("TaharezLook/FrameWindow", "Demo Window");
Window *wnd = winMgr.createWindow("TitleWindow", "Title Window");
root->addChildWindow(wnd);
It does'n work. What's wrong?
Posted: Thu Dec 14, 2006 08:07
by lindquist
what doesn't work? please post any:
* compiler errors
* errors in the cegui log file
* crashes
* etc
Posted: Thu Dec 14, 2006 08:37
by kofight
I found a sample in Sample_MineSweeper, and solve the problem.
The code I post can compile and run, but didn't show my TitleWindow.
Then I found the reason. I didn't assign any skin to TitleWindow, so it can't be seen. I add a "TaharezLook/FrameWindow" child window to Title window, and the window showed up.
But I still have some question, how could I assign skins to my window? The regular way is createWindow("TaharezLook/FrameWindow");
But I createWindow("MyWindowType").
Can I assign a skin to my window, instead of add a childWindow, to let my window be visible?
Posted: Thu Dec 14, 2006 11:04
by lindquist
First. There is a lot more to using a skin made for FrameWindow than just assigning it to a random widget derived from Window.
The easiest to map skins to widgets is by using falagard mappings. All the default skin do this in the .scheme files.
you can also do it explicitly by doing:
wnd->setWindowRenderer("Falagard/Default");
wnd->setLookNFeel("MyLookNFeel");
HTH