当前位置: 首页>>代码示例>>C++>>正文


C++ Graphics::DrawText方法代码示例

本文整理汇总了C++中Graphics::DrawText方法的典型用法代码示例。如果您正苦于以下问题:C++ Graphics::DrawText方法的具体用法?C++ Graphics::DrawText怎么用?C++ Graphics::DrawText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Graphics的用法示例。


在下文中一共展示了Graphics::DrawText方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: OnDraw

//[-------------------------------------------------------]
//[ 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;
			}
		}
	}
}
开发者ID:ByeDream,项目名称:pixellight,代码行数:62,代码来源:GuiButton.cpp

示例2: DrawInfoBox

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;
}
开发者ID:smglaksn,项目名称:troll2d,代码行数:50,代码来源:test_blit.cpp

示例3: paint

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();
	}
}
开发者ID:stahta01,项目名称:wxCode_components,代码行数:31,代码来源:awt_emul.cpp

示例4: OnDraw

//[-------------------------------------------------------]
//[ 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!");
}
开发者ID:ByeDream,项目名称:pixellight,代码行数:12,代码来源:SlimEntry.cpp

示例5: Draw

    void GameOverState::Draw(Graphics& graphics)
    {
        if (!loaded)
        {
            loaded = true;

            graphics.RenderText(text);
        }

        graphics.DrawText(text, 40, 500);
    }
开发者ID:Natman64,项目名称:BearAttack,代码行数:11,代码来源:GameOverState.cpp


注:本文中的Graphics::DrawText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。