bool CompoundBorder::isContained(const Pnt2f& p, const Real32& x, const Real32& y , const Real32& Width, const Real32& Height) const
{
	Real32 LeftIn, RightIn, BottomIn, UpperIn;
	getOuterBorder()->getInsets(LeftIn, RightIn, UpperIn, BottomIn);
    return (getInnerBorder()->isContained(p,x+LeftIn, y+UpperIn, Width-LeftIn-RightIn, Height-UpperIn-BottomIn) ||
            getOuterBorder()->isContained(p,x,y,Width,Height));
}
void CompoundBorder::activateInternalDrawConstraints(const GraphicsWeakPtr g, const Real32& x, const Real32& y , const Real32& Width, const Real32& Height) const
{
	Real32 LeftIn, RightIn, BottomIn, UpperIn;
	getOuterBorder()->getInsets(LeftIn, RightIn, UpperIn, BottomIn);
    getOuterBorder()->activateInternalDrawConstraints(g,x,y,Width,Height);
    getInnerBorder()->activateInternalDrawConstraints(g,x+LeftIn, y+UpperIn, Width-LeftIn-RightIn, Height-UpperIn-BottomIn);
}
void CompoundBorder::getInsets(Real32& Left, Real32& Right,Real32& Top,Real32& Bottom) const
{
	Real32 LeftIn, LeftIn2, RightIn, RightIn2, BottomIn, BottomIn2, UpperIn, UpperIn2;
	getOuterBorder()->getInsets(LeftIn, RightIn, UpperIn, BottomIn);
	getInnerBorder()->getInsets(LeftIn2, RightIn2,UpperIn2, BottomIn2) ;
	Left = LeftIn+LeftIn2;
	Right = RightIn+RightIn2;
	Bottom = BottomIn+BottomIn2;
	Top = UpperIn+UpperIn2;
}
void CompoundBorder::draw(const GraphicsWeakPtr g, const Real32 x, const Real32 y , const Real32 Width, const Real32 Height, const Real32 Opacity, bool Clipping) const
{

	Real32 LeftIn, RightIn, BottomIn, UpperIn;
    getOuterBorder()->getInsets(LeftIn, RightIn, UpperIn, BottomIn);
	getInnerBorder()->draw(g, x+LeftIn, y+UpperIn, Width-LeftIn-RightIn, Height-UpperIn-BottomIn, Opacity);

	getOuterBorder()->draw(g, x, y, Width, Height, Opacity);
	
}
bool WindowBorder::isContained(const Pnt2f& p, const Real32& x, const Real32& y , const Real32& Width, const Real32& Height) const
{
    Real32 LeftIn, RightIn, BottomIn, UpperIn;
    getOuterBorder()->getInsets(LeftIn, RightIn, UpperIn, BottomIn);
    if(getTitlebar() != NULL)
    {
        UpperIn += getTitlebar()->getSize().y();
    }
    return (getInnerBorder()->isContained(p,x+LeftIn, y+UpperIn, Width-LeftIn-RightIn, Height-UpperIn-BottomIn) ||
            getOuterBorder()->isContained(p,x,y,Width,Height));
}
void WindowBorder::activateInternalDrawConstraints(Graphics* const g, const Real32& x, const Real32& y , const Real32& Width, const Real32& Height) const
{
    Real32 LeftIn, RightIn, BottomIn, UpperIn;
    getOuterBorder()->getInsets(LeftIn, RightIn, UpperIn, BottomIn);
    if(getTitlebar() != NULL)
    {
        UpperIn += getTitlebar()->getSize().y();
    }
    getOuterBorder()->activateInternalDrawConstraints(g, x, y, Width, Height);
    getInnerBorder()->activateInternalDrawConstraints(g,x+LeftIn, y+UpperIn, Width-LeftIn-RightIn, Height-UpperIn-BottomIn);
}
void WindowBorder::draw(Graphics* const g, const Real32 x, const Real32 y , const Real32 Width, const Real32 Height, const Real32 Opacity, bool Clipping) const
{
    Real32 LeftIn, RightIn, BottomIn, UpperIn;
    getOuterBorder()->getInsets(LeftIn, RightIn, UpperIn, BottomIn);
    if(getTitlebar() != NULL)
    {
        UpperIn += getTitlebar()->getSize().y();
    }
    getInnerBorder()->draw(g, x+LeftIn, y+UpperIn, Width-LeftIn-RightIn, Height-UpperIn-BottomIn, Opacity);
    getOuterBorder()->draw(g, x, y, Width, Height, Opacity);

}
void WindowBorder::getInsets(Real32& Left, Real32& Right,Real32& Top,Real32& Bottom) const
{
    Real32 LeftIn, LeftIn2, RightIn, RightIn2, BottomIn, BottomIn2, UpperIn, UpperIn2;
    getOuterBorder()->getInsets(LeftIn, RightIn, UpperIn, BottomIn);
    getInnerBorder()->getInsets(LeftIn2, RightIn2,UpperIn2, BottomIn2) ;
    Left = LeftIn+LeftIn2;
    Right = RightIn+RightIn2;
    Bottom = BottomIn+BottomIn2;
    Top = UpperIn+UpperIn2;

    if(getTitlebar() != NULL)
    {
        Top += getTitlebar()->getSize().y();
    }
}