[SOLVED]problems creating a new IGUIElement...

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
eneru
Posts: 40
Joined: Tue Apr 10, 2007 8:38 am

[SOLVED]problems creating a new IGUIElement...

Post by eneru »

i want to create a new IGUIElement which would just draw a background of a certain color, but can't get something to work :s

my class def :

Code: Select all

        protected :
            irr::video::SColor color;

        public:
            //! constructor
            /*!
                constructor (cf Irrlicht's IGUIElements)
                \param irr::gui::IGUIEnvironment* environment
                \param irr::gui::IGUIElement* parent
                \param irr::s32 id
                \param irr::core::rect<irr::s32> rectangle : where to draw
            */
            MaximaGUIBackground(
                irr::gui::IGUIEnvironment* environment,
                irr::gui::IGUIElement* parent, irr::s32 id,
                irr::core::rect<irr::s32> rectangle);


            //! destructor
            ~MaximaGUIBackground();


            //! sets the background color
            virtual void setColor(irr::video::SColor color);

            //! draws the element and its children
            virtual void draw();
^ nothing which differs much from a IGUIImage by example..

and in the .cpp :

Code: Select all

// constructor (i am sure i screwed up something, though there ain't much ^^")
GUIBackground::GUIBackground(
    irr::gui::IGUIEnvironment* environment,
    irr::gui::IGUIElement* parent,
    s32 id,
    core::rect<s32> rectangle)
    : IGUIElement(EGUIET_ELEMENT, environment, parent, id, rectangle)
{
    // by default, the color is black and without transparency
    this->color = SColor(0, 0, 0, 0);   // ARGB
}

// just to set a new color :
void GUIBackground::setColor(irr::video::SColor color)
{
    this->color = color;
}

// and the draw :
void GUIBackground::draw()
{
    if (!IsVisible)
        return;

    // we draw the background color
    Environment->getVideoDriver()->draw2DRectangle(this->color, AbsoluteRect, &AbsoluteClippingRect);
// ^ i don't know exactly what are these absoluteRect and clippingRect, but i intended
// to discover it once i could get something to be actually drawn....

    IGUIElement::draw();
}
I have tried to draw an image (as in the CGUIImage class), but it doesn't help.... so either this doesn't work, or (and there is a high chance for that) my init is screwed and my GUIBackground is not attached to the GUIEnvironment, and thus isn't drawn in the loop....

anyway, thanks to anyone with an advice on this :D


ps : i don't intend to modify the IGUIEnvironment class and as of now i just my constructor and set the color directly (not via a "addBg" fonction)... i have looked at the addXX functions to see if they did add important things and it seems it is not the case, thus i doubt the problem comes from this (i am saying it just in case ^^)
Last edited by eneru on Wed Jun 13, 2007 9:27 pm, edited 1 time in total.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

if 0 is your parent then it wont get added. try this in your constructor-

Code: Select all

GUIBackground::GUIBackground(
    irr::gui::IGUIEnvironment* environment,
    irr::gui::IGUIElement* parent,
    s32 id,
    core::rect<s32> rectangle)
    : IGUIElement(EGUIET_ELEMENT, environment, parent ? parent : environment->getRootGUIElement(), id, rectangle) 
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
eneru
Posts: 40
Joined: Tue Apr 10, 2007 8:38 am

Post by eneru »

thanks a lot !!

i thought that "0" was considered as the "root parent" (aka its value) and didn't get there was this test to be made to "convert it" if necessary !
have a nice day :)
Post Reply