Esempio n. 1
0
//[-------------------------------------------------------]
//[ Protected virtual PLGui::Widget functions             ]
//[-------------------------------------------------------]
void GuiButton::OnDraw(Graphics &cGraphics)
{
	// Call base implementation
	Widget::OnDraw(cGraphics);

	// Draw background
	if (m_cBackground.GetPointer())
		cGraphics.DrawImage(*m_cBackground.GetPointer(), Vector2i::Zero, GetSize());

	// Is the font valid?
	if (m_pFont) {
		// Get the text color to use
		const Color4 &cColor = m_bMouseOver ? m_cMouseOverColor : m_cColor;

		// Get text alignment
		if (m_nAlign == AlignLeft) {
			// Left aligned
			uint32 nHeight = cGraphics.GetTextHeight(*m_pFont, m_sText);
			cGraphics.DrawText(*m_pFont, cColor, Color4::Transparent, Vector2i(0, GetSize().y/2 - nHeight/2), m_sText);
		} else if (m_nAlign == AlignRight) {
			// Right aligned
			uint32 nWidth = cGraphics.GetTextWidth(*m_pFont, m_sText);
			uint32 nHeight = cGraphics.GetTextHeight(*m_pFont, m_sText);
			cGraphics.DrawText(*m_pFont, cColor, Color4::Transparent, Vector2i(GetSize().x - nWidth, GetSize().y/2 - nHeight/2), m_sText);
		} else if (m_nAlign == AlignCenter) {
			// Centered
			uint32 nWidth = cGraphics.GetTextWidth(*m_pFont, m_sText);
			uint32 nHeight = cGraphics.GetTextHeight(*m_pFont, m_sText);
			cGraphics.DrawText(*m_pFont, cColor, Color4::Transparent, Vector2i((GetSize().x - nWidth)/2, GetSize().y/2 - nHeight/2), m_sText);
		} else if (m_nAlign == AlignBlock) {
			// Draw block text
			Vector2i vPos (0, 0);
			Vector2i vSize(GetSize());

			// Draw text word for word
			RegEx cRegEx("\\s*([^\\s]+)");
			uint32 nParsePos = 0;
			while (cRegEx.Match(m_sText, nParsePos)) {
				// Get word
				nParsePos = cRegEx.GetPosition();
				String sWord = cRegEx.GetResult(0);

				// Get text width
				int nWidth = cGraphics.GetTextWidth(*m_pFont, sWord);
				if (vPos.x + nWidth >= vSize.x) {
					// Line break
					vPos.x = 0;
					vPos.y = vPos.y + cGraphics.GetTextHeight(*m_pFont, sWord);
				}

				// Draw word
				cGraphics.DrawText(*m_pFont, cColor, Color4::Transparent, vPos, sWord);

				// Next word
				vPos.x += nWidth + 8;
			}
		}
	}
}
Esempio n. 2
0
int DrawInfoBox(Graphics & g,DrawFlags flags,int state,AlphaComponent alpha)
{
	Rect rc(10,30,550,30);

	static const char * szFuncs [] = 
	{
		"DrawFast",
		"Draw",
		"Draw + Clip Source",
		"DrawStretch",
		"DrawStretch + Clip Source",
		"DrawRotate",
	};

	g.DrawRoundRectFill(rc, 5,Color(45,10,200,200));
	g.DrawRoundRect(rc, 5,Color(45,10,200));

	g.DrawText(Point(15,40),szFuncs[state],Color(255,255,0,200));

	long lastpos = strlen(szFuncs[state])*8;

	if(flags.HasFlag(DrawFlags::horizontalFlip) && state > 0)
	{
		g.DrawText(Point(15 + lastpos,40)," + flipH",Color(255,255,0,200));
		lastpos += 8*8;
	}

	if(flags.HasFlag(DrawFlags::verticalFlip) && state > 0)
	{
		g.DrawText(Point(15 + lastpos,40)," + flipV",Color(255,255,0,200));
		lastpos += 8*8;
	}

	if(flags.HasFlag(DrawFlags::noAntiAlias) && state > 2)
	{
		g.DrawText(Point(15 + lastpos,40)," + noAntiAlias",Color(255,255,0,200));
		lastpos += 14*8;
	}

	if(alpha < 255 && state > 0)
	{
		char szAlpha[20];
		sprintf(szAlpha," (alpha %d)",alpha);

		g.DrawText(Point(15 + lastpos,40),szAlpha,Color(150,255,0,210));
		lastpos += strlen(szAlpha)*8;
	}

	return 0;
}
Esempio n. 3
0
void Component::paint( Graphics& g )
{
	if ( needsOwnerDraw() == FALSE ) return; 

	if ( isLightWeight() == FALSE )
	
		mSize = getSize();

	// default paiting code for leight-weight components

	wxBrush br( wxColour( 255, 255, 255 ), wxSOLID );
	wxPen pen ( wxColour( 255,   0,   0 ), 1, wxSOLID );

	g.SetBrush( br );
	g.SetPen( pen );

	g.DrawRectangle( 0,0, mSize.width, mSize.height );

	if ( mName != "" ) 
	{
		g.SetClippingRegion( 2,2, mSize.width-4, mSize.height-4 );

		long w = 0, h = 0;
		g.GetTextExtent( mName, &w, &h );

		g.DrawText( mName, ( mSize.width  - w ) / 2, 
						   ( mSize.height - h ) / 2  );

		g.DestroyClippingRegion();
	}
}
Esempio n. 4
0
//[-------------------------------------------------------]
//[ Protected virtual Widget functions                    ]
//[-------------------------------------------------------]
void SlimEntry::OnDraw(Graphics &cGraphics)
{
	// Draw image
//	cGraphics.DrawImage(m_cImage, Vector2i(0, 0), Vector2i::Zero);

	// Draw text
	Font cFont(*GetGui());
	cGraphics.DrawText(cFont, Color4::Black, Color4::Transparent, Vector2i(20, 4), "Hello World!");
}
Esempio n. 5
0
    void GameOverState::Draw(Graphics& graphics)
    {
        if (!loaded)
        {
            loaded = true;

            graphics.RenderText(text);
        }

        graphics.DrawText(text, 40, 500);
    }