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


C++ Style::getBorderThickness方法代码示例

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


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

示例1: drawAt

void ButtonWidget::drawAt ( Drawer &drawer, MenuWidget* parent, int x, int y, Align align )
{
	if ( !show )
	{
		return;
	}

	// Choose correct style
	Style * currentStyle = getCurrentStyle ();

	if ( this->textCache == nullptr )
	{
		this->prepare ( drawer );
		lastStyle = style;
	}
	else
	{
		if ( currentStyle != lastStyle )
		{
			prepare ( drawer, *currentStyle );
			lastStyle = currentStyle;
		}
	}

	// draw
	if ( currentStyle == nullptr )
	{
		SDL_Point alignedPos = this->getAlignedPos( x, y, align );
		lastPos = alignedPos;
		this->textCache->drawAt( alignedPos );
	}
	else
	{
		SDL_Point alignedPos = this->getAlignedPos( x, y, align );
		SDL_Rect size = { alignedPos.x, alignedPos.y, this->getWidth(), this->getHeight() };
		lastPos = alignedPos;

		drawer.setClipRect( size );

		// draw background
		currentStyle->drawBackground( drawer, size );

		// draw text
		DirSize padding = style->getPadding();
		SDL_Point innerPos = { alignedPos.x + padding.left, alignedPos.y + padding.top };
		if ( !hasDynamicWidth() )
		{
			int innerWidth = style->getWidth() - padding.left - padding.right;
			innerPos.x += (innerWidth - textCache->getWidth()) / 2;
		}
		if ( !hasDynamicHeight() )
		{
			int innerHeight = style->getHeight() - padding.top - padding.bottom;
			innerPos.y += (innerHeight - textCache->getHeight()) / 2;
		}
		
		this->textCache->drawAt( innerPos );

		// draw border
		SDL_Rect border = size;

		drawer.setDrawingColor( currentStyle->getBorderColor() );
		for ( int i = 0; i < currentStyle->getBorderThickness(); i++ )
		{
			drawer.drawRect( border );
			border.x++;
			border.y++;
			border.w -= 2;
			border.h -= 2;
		}

		drawer.cancelClipRect();
	}
}
开发者ID:Outfl3sh,项目名称:maturitni-projekt,代码行数:74,代码来源:buttonwidget.cpp

示例2: drawAt

void TextInputWidget::drawAt( Drawer & drawer, MenuWidget * parent, int x, int y, Align align )
{
	if ( !show )
	{
		return;
	}

	if ( active && !SDL_IsTextInputActive() )
	{
		SDL_StartTextInput();
	}

	// Choose correct style
	Style * currentStyle = getCurrentStyle();

	if ( this->textCache == nullptr )
	{
		this->prepare( drawer, *currentStyle );
		lastStyle = style;
	}
	else
	{
		if ( currentStyle != lastStyle || textChanged )
		{
			prepare( drawer, *currentStyle );
			lastStyle = currentStyle;
		}
	}

	// draw
	if ( currentStyle == nullptr )
	{
		SDL_Point alignedPos = this->getAlignedPos( x, y, align );
		lastPos = alignedPos;
		this->textCache->drawAt( alignedPos );
	}
	else
	{
		SDL_Point alignedPos = this->getAlignedPos( x, y, align );
		SDL_Rect size = { alignedPos.x, alignedPos.y, this->getWidth(), this->getHeight() };
		lastPos = alignedPos;

		drawer.setClipRect( size );

		// draw background
		currentStyle->drawBackground( drawer, size );

		// draw text
		DirSize padding = style->getPadding();
		SDL_Point innerPos = { alignedPos.x + padding.left, alignedPos.y + padding.top };
		int innerWidth = style->getWidth() - padding.left - padding.right;
		drawer.setClipRect( { innerPos.x, innerPos.y, innerWidth, style->getHeight() } );
		innerPos.y += ( style->getHeight() - padding.top - padding.bottom - textCache->getHeight() ) / 2;

		int width = drawer.getTextSize( this->text.substr( 0, this->cursorPosition ),
										style->getFontSize(), style->getFontStyle() ).w + 1;

		int offset = 0;

		if ( width > innerWidth )
		{
			offset = width - innerWidth;
		}

		if ( text != "" )
			this->textCache->drawAt( innerPos.x - offset, innerPos.y );

		if ( active )
		{
			drawer.setDrawingColor( style->getFontColor() );
			drawer.drawLine( { width + innerPos.x - offset - 1, innerPos.y - 2 },
			{ width + innerPos.x - offset - 1, innerPos.y + textCache->getHeight() + 2 } );
		}

		drawer.setClipRect( size );

		// draw border
		SDL_Rect border = size;

		drawer.setDrawingColor( currentStyle->getBorderColor() );
		for ( int i = 0; i < currentStyle->getBorderThickness(); i++ )
		{
			drawer.drawRect( border );
			border.x++;
			border.y++;
			border.w -= 2;
			border.h -= 2;
		}

		drawer.cancelClipRect();
	}
}
开发者ID:Outfl3sh,项目名称:maturitni-projekt,代码行数:92,代码来源:textinputwidget.cpp


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