本文整理汇总了C++中Style::drawBackground方法的典型用法代码示例。如果您正苦于以下问题:C++ Style::drawBackground方法的具体用法?C++ Style::drawBackground怎么用?C++ Style::drawBackground使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Style
的用法示例。
在下文中一共展示了Style::drawBackground方法的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();
}
}
示例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();
}
}