void MenuItem::drawText(Graphics* const TheGraphics, const Pnt2f& TopLeft, Real32 Opacity) const
{
   //If I have Text Then Draw it
   if(getText() != "" && getFont() != NULL)
   {
       Pnt2f b, BottomRight;
       getInsideBorderBounds(b, BottomRight);
      //Calculate Alignment
      Pnt2f AlignedPosition;
      Pnt2f TextTopLeft, TextBottomRight;
      getFont()->getBounds(getText(), TextTopLeft, TextBottomRight);

      AlignedPosition = calculateAlignment(TopLeft, (BottomRight-TopLeft), (TextBottomRight - TextTopLeft),0.5, 0.0);

	  //Draw the Text
      TheGraphics->drawText(AlignedPosition, getText(), getFont(), getDrawnTextColor(), getOpacity()*Opacity);

      //Draw the Mnemonic Underline
      if(_MnemonicTextPosition != -1)
      {
          TheGraphics->drawTextUnderline(AlignedPosition, getText().substr(_MnemonicTextPosition,1), getFont(), getDrawnTextColor(), getOpacity()*Opacity);
      }
      
      //Draw the Accelerator Text
      if(_AcceleratorText.compare("") != 0)
      {
          Pnt2f AcceleratorTextTopLeft, AcceleratorTextBottomRight;
          getFont()->getBounds(_AcceleratorText, AcceleratorTextTopLeft, AcceleratorTextBottomRight);
          Pnt2f AcceleratorAlignedPosition = calculateAlignment(TopLeft, (BottomRight-TopLeft), (AcceleratorTextBottomRight - AcceleratorTextTopLeft),0.5, 1.0);

          TheGraphics->drawText(AcceleratorAlignedPosition, _AcceleratorText, getFont(), getDrawnTextColor(), getOpacity()*Opacity);
      }

   }
}
Exemple #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);
	}
}
void Button::drawText(Graphics* const TheGraphics, const Pnt2f& TopLeft, Real32 Opacity) const
{
    //If I have Text Then Draw it
    if(getText() != "" && getFont() != NULL)
    {
        //Calculate Alignment
        Pnt2f Position =  TopLeft + getDrawnOffset();

        //Draw the Text
        TheGraphics->drawText(Position, getText(), getFont(), getDrawnTextColor(), getOpacity()*Opacity);
    }
}
void Label::drawInternal(Graphics* const TheGraphics, Real32 Opacity) const
{
    if(getText() != "" && getFont() != NULL)
    {
        Pnt2f TopLeft, BottomRight;
        Pnt2f TempPos;
        getInsideBorderBounds(TopLeft, BottomRight);
        TempPos = calculateAlignment(TopLeft, BottomRight-TopLeft, getFont()->getBounds(getText()), getAlignment().y(), getAlignment().x());
        
        //Text Color
        Color4f TextColor = getDrawnTextColor();

        if(_TextSelectionStart >= _TextSelectionEnd)
        {
            TheGraphics->drawText(TempPos, getText(), getFont(), TextColor, getOpacity()*Opacity);
        }
        else
        {
            //Draw Text Before the Selection
            TheGraphics->drawText(TempPos, getText().substr(0, _TextSelectionStart), getFont(), TextColor, getOpacity()*Opacity);

            //Draw Selection
            Pnt2f TextTopLeft, TextBottomRight;
            getFont()->getBounds(getText().substr(0, _TextSelectionStart), TextTopLeft, TextBottomRight);

            TheGraphics->drawQuad(TempPos + Vec2f(TextBottomRight.x(),0),
                                  TempPos + Vec2f(getFont()->getBounds(getText().substr(0, _TextSelectionEnd)).x(), 0),
                                  TempPos + Vec2f(getFont()->getBounds(getText().substr(0, _TextSelectionEnd))),
                                  TempPos + Vec2f(TextBottomRight),
                                  getSelectionBoxColor(),  getSelectionBoxColor(),  getSelectionBoxColor(),  getSelectionBoxColor(), getOpacity()*Opacity);

            //Draw Selected Text
            TheGraphics->drawText(TempPos + Vec2f(TextBottomRight.x(), 0), 
                                  getText().substr(_TextSelectionStart, _TextSelectionEnd-_TextSelectionStart), getFont(), getSelectionTextColor(), getOpacity()*Opacity);

            //Draw Text After selection
            getFont()->getBounds(getText().substr(0, _TextSelectionEnd), TextTopLeft, TextBottomRight);
            TheGraphics->drawText(TempPos + Vec2f(TextBottomRight.x(), 0),
                                  getText().substr(_TextSelectionEnd, getText().size()-_TextSelectionEnd), getFont(), TextColor, getOpacity()*Opacity);
        }
    }
}
void TextField::drawInternal(Graphics* const TheGraphics, Real32 Opacity) const
{
    Pnt2f Alignment;
    Pnt2f TopLeft, BottomRight;
    getInsideBorderBounds(TopLeft, BottomRight);

    //Text Color
    Color4f TextColor = getDrawnTextColor();

    if(getDrawnText() != "" && getFont() != NULL)
    {
        Alignment = calculateAlignment(TopLeft, BottomRight-TopLeft, getFont()->getBounds(getDrawnText()), getAlignment().y(), getAlignment().x());


        if(_TextSelectionStart >= _TextSelectionEnd)
        {
            TheGraphics->drawText(Alignment, getDrawnText(), getFont(), TextColor, getOpacity()*Opacity);
        }
        else
        {
            //Draw Text Befor the Selection
            TheGraphics->drawText(Alignment, getDrawnText().substr(0, _TextSelectionStart), getFont(), TextColor, getOpacity()*Opacity);

            //Draw Selection
            Pnt2f TextTopLeft, TextBottomRight;
            getFont()->getBounds(getDrawnText().substr(0, _TextSelectionStart), TextTopLeft, TextBottomRight);

            TheGraphics->drawQuad(Alignment + Vec2f(TextBottomRight.x(),0),
                                  Alignment + Vec2f(getFont()->getBounds(getDrawnText().substr(0, _TextSelectionEnd)).x(), 0),
                                  Alignment + Vec2f(getFont()->getBounds(getDrawnText().substr(0, _TextSelectionEnd))),
                                  Alignment + Vec2f(TextBottomRight),
                                  getSelectionBoxColor(),  getSelectionBoxColor(),  getSelectionBoxColor(),  getSelectionBoxColor(), getOpacity());

            //Draw Selected Text
            TheGraphics->drawText(Alignment + Vec2f(TextBottomRight.x(), 0), 
                                  getDrawnText().substr(_TextSelectionStart, _TextSelectionEnd-_TextSelectionStart), getFont(), getSelectionTextColor(), getOpacity()*Opacity);

            //Draw Text After selection
            getFont()->getBounds(getDrawnText().substr(0, _TextSelectionEnd), TextTopLeft, TextBottomRight);
            TheGraphics->drawText(Alignment + Vec2f(TextBottomRight.x(), 0),
                                  getDrawnText().substr(_TextSelectionEnd, getDrawnText().size()-_TextSelectionEnd), getFont(), TextColor, getOpacity()*Opacity);
        }
    }
    else
    {
        Alignment = calculateAlignment(TopLeft, BottomRight-TopLeft, getFont()->getBounds("|"), getAlignment().y(), getAlignment().x());
    }

    if(getEnabled() && getEditable() && getFocused() && _CurrentCaretBlinkElps <= 0.5*LookAndFeelManager::the()->getLookAndFeel()->getTextCaretRate())
    {
        //Draw the caret
        TheGraphics->drawLine(Alignment+Vec2f(getFont()->getBounds(getDrawnText().substr(0, getCaretPosition())).x(), 0),
                              Alignment + Vec2f(getFont()->getBounds(getDrawnText().substr(0, getCaretPosition())).x(),  getFont()->getBounds(getDrawnText()).y()), 
                              .5, TextColor, getOpacity()*Opacity);
    }

    //Draw the Descriptive text if empty
    if(getDrawnText().empty() && !getEmptyDescText().empty()  && getEmptyDescTextFont() != NULL)
    {
        Alignment = calculateAlignment(TopLeft, BottomRight-TopLeft, getEmptyDescTextFont()->getBounds(getEmptyDescText()), getAlignment().y(), getAlignment().x());
        TheGraphics->drawText(Alignment, getEmptyDescText(), getEmptyDescTextFont(), getEmptyDescTextColor(), getOpacity()*Opacity);
    }
}