Example #1
0
Vec2f Button::getContentRequestedSize(void) const
{
    Vec2f Result(0.0f,0.0f);
    UIDrawObjectCanvasRefPtr DrawnDrawObject = getDrawnDrawObject();
    if(getDrawObjectToTextAlignment() == ALIGN_DRAW_OBJECT_LEFT_OF_TEXT ||
       getDrawObjectToTextAlignment() == ALIGN_DRAW_OBJECT_RIGHT_OF_TEXT)
    {
        if(getFont() != NULL)
        {
            Pnt2f TextTopLeft(0.0f,0.0f), TextBottomRight(0.0f,0.0f);
            getFont()->getBounds(getText(), TextTopLeft, TextBottomRight);
            Result[0] += (TextBottomRight - TextTopLeft).x();
            Result[1] = osgMax(Result[1],(TextBottomRight - TextTopLeft).y());
        }

        if(DrawnDrawObject != NULL)
        {
            Pnt2f DrawObjectTopLeft, DrawObjectBottomRight;
            DrawnDrawObject->getDrawObjectBounds(DrawObjectTopLeft, DrawObjectBottomRight);

            Result[0] += (DrawObjectBottomRight - DrawObjectTopLeft).x();
            Result[1] = osgMax(Result[1],(DrawObjectBottomRight - DrawObjectTopLeft).y());
        }

        if(getFont() != NULL && DrawnDrawObject != NULL)
        {
            Result[0] += getDrawObjectToTextPadding();
        }
    }
    else if(getDrawObjectToTextAlignment() == ALIGN_DRAW_OBJECT_ABOVE_TEXT ||
            getDrawObjectToTextAlignment() == ALIGN_DRAW_OBJECT_BELOW_TEXT)
    {
        if(getFont() != NULL)
        {
            Pnt2f TextTopLeft(0.0f,0.0f), TextBottomRight(0.0f,0.0f);
            getFont()->getBounds(getText(), TextTopLeft, TextBottomRight);
            Result[1] += (TextBottomRight - TextTopLeft).y();
            Result[0] = osgMax(Result[0],(TextBottomRight - TextTopLeft).x());
        }

        if(DrawnDrawObject != NULL)
        {
            Pnt2f DrawObjectTopLeft, DrawObjectBottomRight;
            DrawnDrawObject->getDrawObjectBounds(DrawObjectTopLeft, DrawObjectBottomRight);

            Result[1] += (DrawObjectBottomRight - DrawObjectTopLeft).y();
            Result[0] = osgMax(Result[0],(DrawObjectBottomRight - DrawObjectTopLeft).x());
        }

        if(getFont() != NULL && DrawnDrawObject != NULL)
        {
            Result[1] += getDrawObjectToTextPadding();
        }
    }

    return Result + Vec2f(2.0,2.0);
}
Example #2
0
void ProgressBar::drawInternal(Graphics* const Graphics, Real32 Opacity) const
{

	//Draw The ProgressBar
    UIDrawObjectCanvasRefPtr DrawObject(getDrawnDrawObject());
    if(DrawObject != NULL)
    {
        if(DrawObject->getPosition() != _ProgressBarPosition)
        {
            DrawObject->setPosition(_ProgressBarPosition);
        }
        if(DrawObject->getSize() != _ProgressBarSize)
        {
            DrawObject->setSize(_ProgressBarSize);
        }
        DrawObject->draw(Graphics,getOpacity()*Opacity);
    }
	
	//Draw The Progress String
	if(getEnableProgressString() && getFont() != NULL)
	{
		Pnt2f TopLeft, BottomRight;
		getInsideBorderBounds(TopLeft, BottomRight);

		//Draw the progress String
		std::string StringToDraw;
		if(getProgressString().compare("") == 0)
		{
            if(!getIndeterminate())
            {
			    UInt32 Percent(static_cast<Int32>( osgFloor(getPercentComplete() * 100.0f) ));

			    std::stringstream TempSStream;
			    TempSStream << Percent;

			    StringToDraw = TempSStream.str() + std::string("%");
            }
		}
		else
		{
			StringToDraw = getProgressString();
		}

		//Calculate Alignment
		Pnt2f AlignedPosition;
		Pnt2f TextTopLeft, TextBottomRight;
		getFont()->getBounds(StringToDraw, TextTopLeft, TextBottomRight);

		AlignedPosition = calculateAlignment(TopLeft, (BottomRight-TopLeft), (TextBottomRight - TextTopLeft),getAlignment().y(), getAlignment().x());

		//Draw the Text
		Graphics->drawText(AlignedPosition, StringToDraw, getFont(), getDrawnTextColor(), getOpacity()*Opacity);
	}
}
Example #3
0
void Button::drawInternal(Graphics* const TheGraphics, Real32 Opacity) const
{
    Pnt2f TopLeft, BottomRight;
    getInsideBorderBounds(TopLeft, BottomRight);

    //If I have a DrawObject then Draw it
    UIDrawObjectCanvasRefPtr DrawnDrawObject = getDrawnDrawObject();
    UIDrawObjectCanvasRefPtr BaseDrawObject = getBaseDrawObject();

    if(DrawnDrawObject != NULL)
    {
        //Get the Draw Object Size
        Pnt2f DrawObjectTopLeft, DrawObjectBottomRight;
        DrawnDrawObject->getDrawObjectBounds(DrawObjectTopLeft, DrawObjectBottomRight);

        Pnt2f BaseDrawObjectTopLeft, BaseDrawObjectBottomRight;
        BaseDrawObject->getDrawObjectBounds(BaseDrawObjectTopLeft, BaseDrawObjectBottomRight);

        if(getText() != "" && getFont() != NULL)
        {
            //Draw both the text and Draw Object

            //Get the Text Size
            Pnt2f TextTopLeft, TextBottomRight;
            getFont()->getBounds(getText(), TextTopLeft, TextBottomRight);

            Vec2f InternalsSize;
            if(getDrawObjectToTextAlignment() == ALIGN_DRAW_OBJECT_LEFT_OF_TEXT || 
               getDrawObjectToTextAlignment() == ALIGN_DRAW_OBJECT_RIGHT_OF_TEXT)
            {
                InternalsSize.setValues((TextBottomRight.x()-TextTopLeft.x()) + (DrawObjectBottomRight.x()-DrawObjectTopLeft.x()) + getDrawObjectToTextPadding(),
                                        osgMax((TextBottomRight.y()-TextTopLeft.y()), (DrawObjectBottomRight.y()-DrawObjectTopLeft.y())));
            }
            else
            {
                InternalsSize.setValues(osgMax((TextBottomRight.x()-TextTopLeft.x()), (DrawObjectBottomRight.x()-DrawObjectTopLeft.x())),
                                        (TextBottomRight.y()-TextTopLeft.y()) + (DrawObjectBottomRight.y()-DrawObjectTopLeft.y()) + getDrawObjectToTextPadding());
            }

            Pnt2f InternalAlignment;
            InternalAlignment = calculateAlignment(TopLeft, (BottomRight-TopLeft), InternalsSize,getAlignment().y(), getAlignment().x());

            //Draw Object Alignment
            Pnt2f DrawObjectAlignedPosition;
            switch(getDrawObjectToTextAlignment())
            {
                case ALIGN_DRAW_OBJECT_LEFT_OF_TEXT:
                    DrawObjectAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, (BaseDrawObjectBottomRight - BaseDrawObjectTopLeft),0.5f, 0.0);
                    break;
                case ALIGN_DRAW_OBJECT_RIGHT_OF_TEXT:
                    DrawObjectAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, (BaseDrawObjectBottomRight - BaseDrawObjectTopLeft),0.5f, 1.0);
                    break;
                case ALIGN_DRAW_OBJECT_ABOVE_TEXT:
                    DrawObjectAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, (BaseDrawObjectBottomRight - BaseDrawObjectTopLeft),0.0f, 0.5);
                    break;
                case ALIGN_DRAW_OBJECT_BELOW_TEXT:
                    DrawObjectAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, (BaseDrawObjectBottomRight - BaseDrawObjectTopLeft),1.0f, 0.5);
                    break;
            }
            //If active then translate the Text by the Active Offset
            DrawObjectAlignedPosition = DrawObjectAlignedPosition + getDrawnOffset();

            DrawnDrawObject->setPosition( DrawObjectAlignedPosition );

            //Text Alignment
            Pnt2f TextAlignedPosition;
            switch(getDrawObjectToTextAlignment())
            {
                case ALIGN_DRAW_OBJECT_LEFT_OF_TEXT:
                    TextAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, (TextBottomRight - TextTopLeft),0.5f, 1.0);
                    break;
                case ALIGN_DRAW_OBJECT_RIGHT_OF_TEXT:
                    TextAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, (TextBottomRight - TextTopLeft),0.5f, 0.0);
                    break;
                case ALIGN_DRAW_OBJECT_ABOVE_TEXT:
                    TextAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, (TextBottomRight - TextTopLeft),1.0f, 0.5);
                    break;
                case ALIGN_DRAW_OBJECT_BELOW_TEXT:
                    TextAlignedPosition = calculateAlignment(InternalAlignment, InternalsSize, (TextBottomRight - TextTopLeft),0.0f, 0.5);
                    break;
            }

            drawText(TheGraphics, TextAlignedPosition, Opacity);
        }
        else
        {
            //Just Draw the Draw Object
            Pnt2f AlignedPosition;
            AlignedPosition = calculateAlignment(TopLeft, (BottomRight-TopLeft), (BaseDrawObjectBottomRight - BaseDrawObjectTopLeft),getAlignment().y(), getAlignment().x());

            //If active then translate the Text by the Active Offset
            AlignedPosition = AlignedPosition + getDrawnOffset();

            DrawnDrawObject->setPosition( AlignedPosition );
        }

        //Draw the DrawnDrawObject
        DrawnDrawObject->draw(TheGraphics, getOpacity()*Opacity);

    }
    else if(getText() != "" && getFont() != NULL)
    {
        //Just Draw the Text
        Pnt2f AlignedPosition;
        Pnt2f TextTopLeft, TextBottomRight;
        getFont()->getBounds(getText(), TextTopLeft, TextBottomRight);

        AlignedPosition = calculateAlignment(TopLeft, (BottomRight-TopLeft), (TextBottomRight - TextTopLeft),getAlignment().y(), getAlignment().x());

        drawText(TheGraphics, AlignedPosition, Opacity);
    }
}