Page 1 of 1

[SOLVED]problems creating a new IGUIElement...

Posted: Wed Jun 13, 2007 8:40 pm
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 ^^)

Posted: Wed Jun 13, 2007 8:49 pm
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) 

Posted: Wed Jun 13, 2007 9:26 pm
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 :)