CGUIColoredBackground

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Halan
Posts: 447
Joined: Tue Oct 04, 2005 8:17 pm
Location: Germany, Freak City
Contact:

CGUIColoredBackground

Post by Halan »

Heya ,

it's me again!

In my project I needed something like a background for my gui-elements that is not as complete gui window.
So i have a little gui class that renders that background. In my project it looks like that:
Image

Header:

Code: Select all

#ifndef _INCLUDE_C_GUI_COLORED_BACKGROUND_
#define _INCLUDE_C_GUI_COLORED_BACKGROUND_

#include <irrlicht.h>

namespace irr
{
namespace gui
{

class CGUIColoredBackground : public IGUIElement
{
    public:
        CGUIColoredBackground(IGUIElement* parent, IGUIEnvironment* guiEnv, core::rect<s32> rect,
        video::SColor color, video::SColor borderColor, s32 borderThickness, s32 id = -1);

        video::SColor getColor() const;
        void setColor(video::SColor newColor);

        video::SColor getBorderColor() const;
        void setBorderColor(video::SColor newBorderColor);

        s32 getBorderThickness() const;
        void setBorderThickness(s32 newValue);

        virtual void draw();

    private:
        s32 BorderThickness;
        video::SColor Color, BorderColor;
        IGUIEnvironment* GuiEnv;
};

} //! end namespace gui
} //! end namespace irr

#endif
Main file

Code: Select all

#include "CGUIColoredBackground.h"

namespace irr
{
namespace gui
{

CGUIColoredBackground::CGUIColoredBackground(IGUIElement* parent, IGUIEnvironment* guiEnv, core::rect<s32> rect, video::SColor color,
 video::SColor borderColor, s32 borderThickness, s32 id)
    : IGUIElement(EGUIET_ELEMENT, guiEnv, parent, id, rect), BorderThickness(borderThickness), GuiEnv(guiEnv)
{
    this->setColor(color);
    this->setBorderColor(borderColor);
}

video::SColor CGUIColoredBackground::getColor() const
{
    return Color;
}

void CGUIColoredBackground::setColor(video::SColor newColor)
{
    Color = newColor;
}

video::SColor CGUIColoredBackground::getBorderColor() const
{
    return BorderColor;
}

void CGUIColoredBackground::setBorderColor(video::SColor newBorderColor)
{
    BorderColor = newBorderColor;
}

s32 CGUIColoredBackground::getBorderThickness() const
{
    return BorderThickness;
}

void CGUIColoredBackground::setBorderThickness(s32 newValue)
{
    BorderThickness = newValue;
}

void CGUIColoredBackground::draw()
{
    core::rect<s32> borderRect(AbsoluteClippingRect.UpperLeftCorner - core::position2di(BorderThickness, BorderThickness),
    AbsoluteClippingRect.LowerRightCorner + core::position2di(BorderThickness, BorderThickness));

    GuiEnv->getSkin()->draw2DRectangle(this, BorderColor, borderRect, 0);
    GuiEnv->getSkin()->draw2DRectangle(this, Color, AbsoluteClippingRect,  0);

    IGUIElement::draw();
}

} //! end namespace gui
} //! end namepsace irr
Though I don't think it is that useful ;)

greets,
Halan
Post Reply