Custom GUI Element[SOLVED]

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
XenoZergNid
Posts: 17
Joined: Sun Oct 13, 2013 1:52 am

Custom GUI Element[SOLVED]

Post by XenoZergNid »

Well, I'm quite confused. I got a custom GUI Element with the following code, but it won't draw the children.

Toolbar.hpp

Code: Select all

 
#ifndef TOOLBAR_H
#define TOOLBAR_H
 
class Toolbar : public IGUIElement
{
    public:
        Toolbar(IGUIEnvironment*,IGUIElement*, s32, wchar_t*, core::rect<s32>);
        virtual ~Toolbar();
        void draw();
        void UpdateSize();
        void ToggleDraw();
    private:
        IGUIEnvironment *gui;
        core::rect<s32> position;
        bool Draw;
        int Size;
        IGUIListBox *StaticMeshesList;
        IGUIListBox *StaticMeshesList2;
};
 
#endif // TOOLBAR_H
 
Toolbar.cpp

Code: Select all

 
#include "../Include/Toolbar.hpp"
 
Toolbar::Toolbar(IGUIEnvironment* g,IGUIElement* parent, s32 id, wchar_t* titletext, core::rect<s32> position):IGUIElement(EGUIET_ELEMENT,g,parent,id,position),gui(g)
{
    this->position = position;
    Draw = true;
    Size = 300;
    StaticMeshesList = gui->addListBox(core::rect<int>(), this, STATIC_MESH_LIST, true);
    StaticMeshesList->addItem(L"item");
    StaticMeshesList->addItem(L"item");
    StaticMeshesList->addItem(L"item");
    StaticMeshesList->addItem(L"item");
    StaticMeshesList->addItem(L"item");
    StaticMeshesList->addItem(L"item");
    StaticMeshesList->addItem(L"item");
    StaticMeshesList->addItem(L"item");
    StaticMeshesList->addItem(L"item");
    StaticMeshesList->addItem(L"item");
 
    StaticMeshesList2 = gui->addListBox(core::rect<int>(), this, STATIC_MESH_LIST, true);
    StaticMeshesList2->addItem(L"item");
    StaticMeshesList2->addItem(L"item");
    StaticMeshesList2->addItem(L"item");
    StaticMeshesList2->addItem(L"item");
    StaticMeshesList2->addItem(L"item");
    StaticMeshesList2->addItem(L"item");
    StaticMeshesList2->addItem(L"item");
    StaticMeshesList2->addItem(L"item");
    StaticMeshesList2->addItem(L"item");
    StaticMeshesList2->addItem(L"item");
}
 
Toolbar::~Toolbar()
{
    //dtor
}
void Toolbar::ToggleDraw(){
    Draw = !Draw;
}
void Toolbar::UpdateSize(){
    int Width = gui->getVideoDriver()->getScreenSize().Width;
    int Height = gui->getVideoDriver()->getScreenSize().Height;
    position.LowerRightCorner.Y = Height-19;
    position.LowerRightCorner.X = Width;
    position.UpperLeftCorner.X = Width-Size;
    position.UpperLeftCorner.Y = 19;
    StaticMeshesList->setRelativePosition(core::rect<int>(0,0,190,140)+core::vector2d<int>(position.UpperLeftCorner.X+4,position.UpperLeftCorner.Y+24));
    StaticMeshesList2->setRelativePosition(core::rect<int>(0,0,190,140)+core::vector2d<int>(position.UpperLeftCorner.X+4,position.UpperLeftCorner.Y+400));
}
void Toolbar::draw()
{
    if(Draw){
        int BorderSize = 1;
        gui->getVideoDriver()->draw2DRectangle(video::SColor(255,100,100,100),core::rect<s32>(position.UpperLeftCorner+vector2di(0,0),position.LowerRightCorner+vector2di(BorderSize,0)));
        gui->getVideoDriver()->draw2DRectangle(video::SColor(255,212,85,0),core::rect<s32>(position.UpperLeftCorner+vector2di(BorderSize,BorderSize),position.LowerRightCorner+vector2di(0,-BorderSize)));//orange
        int temp = 0;
        core::list<IGUIElement*>::Iterator it = Children.begin();
        for (; it != Children.end(); ++it){
            (*it)->draw();
            std::cout<< temp++ << "\n";
        }
        StaticMeshesList->draw();
        StaticMeshesList2->draw();
    }
}
 
UpdateSize() is called in the main loop.

Sorry if this is an obvious question, but I can't figure it out :(
also I don't often post on the forums so I often don't provide enough information, sorry if I did that as well.
Last edited by XenoZergNid on Sun Oct 13, 2013 5:40 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9971
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Custom GUI Element

Post by CuteAlien »

You mean other children elements which you add outside the code you posted above? Can you give an example how you add them (and also how you add your own element)? It looks correct on first view - so my main suspicion would be that something with the sizes is wrong (rect is 4 positions, not position +width/height for example - that's often accidentally done wrong).

edit: This should also be very easy to debug. Just set a breakpoint at the draw call and step into it. Don't be afraid of debugging!
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
XenoZergNid
Posts: 17
Joined: Sun Oct 13, 2013 1:52 am

Re: Custom GUI Element

Post by XenoZergNid »

well...

I declared it with the following:

Code: Select all

Toolbar *MainBar = new Toolbar(guienv,guienv->getRootGUIElement(),-1,ToolbarName,core::recti(0,0,0,0));
changing "core::recti(0,0,0,0)" to "core::recti(0,0,10000,10000)" fixes it.

thanks for pointing me in the right direction.
Post Reply