Custom GUI element

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Galhad
Posts: 13
Joined: Sat Mar 20, 2010 6:20 pm
Location: Zielona Gora, Poland

Custom GUI element

Post by Galhad »

Hi, I'm writing custom gui element and it wont draw until I call function draw(), here is code:
CustomGUIelement.h

Code: Select all

#include "irrlicht.h"

using namespace irr;
using namespace gui;

class CustomGUIelement:public IGUIElement
{
    public:
        CustomGUIelement(IGUIEnvironment*,IGUIElement*, s32, wchar_t*, core::rect<s32>);
        virtual ~CustomGUIelement();

        virtual bool OnEvent(const SEvent& event);
        void draw();
    protected:
    private:
        IGUIEnvironment *gui;
        IGUIStaticText *title;
};
CustomGUIelement.cpp

Code: Select all


CustomGUIelement::CustomGUIelement(IGUIEnvironment* g,IGUIElement* parent, s32 id, wchar_t* titletext, core::rect<s32> position):IGUIElement(EGUIET_ELEMENT,g,parent,id,position),gui(g)
{
    title=gui->addStaticText(titletext,core::rect<s32>(0,0,100,100),false,false,this);
}

CustomGUIelement::~CustomGUIelement()
{
    //dtor
}

bool CustomGUIelement::OnEvent(const SEvent& event)
{
    return true;
}

void CustomGUIelement::draw()
{
    IGUIElement::draw();
}
main.cpp

Code: Select all


#include "irrlicht.h"
#include "CustomGUIelement.h"

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

int main()
{
    IrrlichtDevice * device = createDevice(EDT_OPENGL, core::dimension2d<u32>(640, 480));

    device->setWindowCaption(L"Irrlicht Engine - User Interface Demo");
    device->setResizable(true);

    IVideoDriver* driver = device->getVideoDriver();
    IGUIEnvironment* env = device->getGUIEnvironment();

    CustomGUIelement* cos=new CustomGUIelement(env,0,-1,L"TEST KONTROLKI",rect<s32>(0,0,640,480));

    while(device->run() && driver)
    {
        if (device->isWindowActive())
        {
                driver->beginScene(true, true, SColor(0,200,200,200));

                env->drawAll();
                cos->draw();//without this line it wont work :(

                driver->endScene();
        }
    }
    device->drop();
    return 0;
}
Please, help me..
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

bc you didn't set a parent.
The gui as well uses a render tree.
just set the parent to env->getRootGUIElement()
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Galhad
Posts: 13
Joined: Sat Mar 20, 2010 6:20 pm
Location: Zielona Gora, Poland

Post by Galhad »

Thanks, now everything is okay :D
Post Reply