How to create my own window?

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

kofight
Just popping in
Just popping in
Posts: 8
Joined: Tue Dec 12, 2006 02:01

How to create my own window?

Postby kofight » Thu Dec 14, 2006 05:33

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.

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Postby lindquist » Thu Dec 14, 2006 05:54

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

kofight
Just popping in
Just popping in
Posts: 8
Joined: Tue Dec 12, 2006 02:01

Postby kofight » Thu Dec 14, 2006 07:06

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?

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Postby lindquist » Thu Dec 14, 2006 08:07

what doesn't work? please post any:
* compiler errors
* errors in the cegui log file
* crashes
* etc

kofight
Just popping in
Just popping in
Posts: 8
Joined: Tue Dec 12, 2006 02:01

Postby kofight » Thu Dec 14, 2006 08:37

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?

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Postby lindquist » Thu Dec 14, 2006 11:04

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


Return to “Help”

Who is online

Users browsing this forum: No registered users and 29 guests