本文整理汇总了C++中WideString::format方法的典型用法代码示例。如果您正苦于以下问题:C++ WideString::format方法的具体用法?C++ WideString::format怎么用?C++ WideString::format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WideString
的用法示例。
在下文中一共展示了WideString::format方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onRender
void ButtonBuildStructure::onRender( RenderContext & context, const RectInt & window )
{
WindowButton::onRender( context, window );
if ( enabled() && m_Build.valid() )
{
DisplayDevice * pDisplay = context.display();
ASSERT( pDisplay );
// draw the eta to build this structure
Font * pFont = windowStyle()->font();
if ( pFont != NULL )
{
WideString eta;
GameDocument * pDoc = (GameDocument *)document();
if ( pDoc != NULL )
{
NounShip::Ref pShip = pDoc->ship();
if ( pShip.valid() )
{
int buildTime = m_Build->buildTime()* pShip->calculateModifier(MT_BUILD_SPEED,true);
eta.format( "%d:%2.2d", buildTime / 60, buildTime % 60);
SizeInt etaSize( pFont->size( eta ) );
PointInt etaPos( window.right - etaSize.width, window.bottom - etaSize.height );
Font::push( context.display(), pFont, etaPos, eta, WHITE );
}
}
}
}
}
示例2: onRender
void ButtonUnit::onRender( RenderContext & context, const RectInt & window )
{
WindowButton::onRender( context, window );
if ( enabled() && m_Unit.valid() )
{
GameDocument * pDoc = (GameDocument *)document();
ASSERT( pDoc );
NounShip * pShip = pDoc->ship();
if (! pShip )
return;
DisplayDevice * pDisplay = context.display();
ASSERT( pDisplay );
// draw the gadget icon
if ( m_Icon.valid() )
{
RectInt iconBox( PointInt( window.left, window.top ), SizeInt( 32, 16 ) );
RectFloat iconUV(0,0,1,1);
Material::push( context, m_Icon );
PrimitiveWindow::push( pDisplay, iconBox, iconUV,
pShip->isFriend( m_Unit ) ? GREEN : pShip->isEnemy( m_Unit ) ? RED : YELLOW );
}
// draw the unit health on the button
Font * pFont = windowStyle()->font();
ASSERT( pFont );
WideString sHealth;
sHealth.format( STR("%d%%"), 100 - ((m_Unit->damage() * 100) / m_Unit->maxDamage()) );
SizeInt szHealth( pFont->size( sHealth ) );
PointInt ptHealth( window.right - szHealth.width, window.bottom - szHealth.height );
Font::push( context.display(), pFont, ptHealth, sHealth, WHITE );
// display damage bar
if ( m_Unit->damage() > 0 )
{
float damage = 1.0f - (m_Unit->damage() / m_Unit->maxDamage());
RectInt bar( window.m_Left, window.m_Bottom + 1,
window.m_Right - (window.width() * (1.0f - damage)), window.m_Bottom + 3 );
RectFloat barUV(0,0,1,1);
Color barColor( 255 * (1.0f - damage), 255 * damage,0,255 );
PrimitiveMaterial::push( pDisplay, PrimitiveMaterial::NONE );
PrimitiveWindow::push( pDisplay, bar, barUV, barColor );
}
// display blinking border if this unit is the current target
if ( pDoc->target() == m_Unit && (pDoc->tick() % 10) < 6)
renderGlow( context );
}
}
示例3: onRender
void ButtonCargo::onRender( RenderContext & context, const RectInt & window )
{
WindowButton::onRender( context, window );
if ( enabled() )
{
Noun * pCargo = m_Cargo;
ASSERT( pCargo );
// display white box around cargo if current target
GameDocument * pDoc = (GameDocument *)document();
ASSERT( pDoc );
if ( pDoc->target() == pCargo && (pDoc->tick() % 10) < 6 )
renderGlow( context );
if ( WidgetCast<CargoEnhancement>( pCargo ) )
{
// show the durability if an enhancement..
CargoEnhancement * pCargoEnh = (CargoEnhancement *)pCargo;
Font * pFont = windowStyle()->font();
ASSERT( pFont );
NounEnhancement * pEnhancement = pCargoEnh->enhancement();
if ( pEnhancement != NULL )
{
int nMaxDamage = pEnhancement->maxDamage();
if ( nMaxDamage > 0 )
{
WideString sQuantity;
sQuantity.format( "%d/%d", nMaxDamage - pCargoEnh->damage(), nMaxDamage );
SizeInt stringSize( pFont->size( sQuantity ) );
PointInt stringPos( window.m_Right - stringSize.width, window.top );
Font::push( context.display(), pFont, stringPos, sQuantity, WHITE );
}
}
if ( ((CargoEnhancement *)pCargo)->quantity() <= 0 )
destroy();
}
else if ( WidgetCast<NounCargo>( pCargo ) )
{
// draw the quantity if cargo
Font * pFont = windowStyle()->font();
ASSERT( pFont );
WideString sQuantity;
sQuantity.format( "%d", ((NounCargo *)pCargo)->quantity() );
SizeInt stringSize( pFont->size( sQuantity ) );
PointInt stringPos( window.m_Right - stringSize.width, window.top );
Font::push( context.display(), pFont, stringPos, sQuantity, WHITE );
if ( ((NounCargo *)pCargo)->quantity() <= 0 )
destroy();
}
else if ( WidgetCast<NounUnit>( pCargo ) )
{
NounUnit * pUnit = (NounUnit *)pCargo;
// draw the unit health on the button
Font * pFont = windowStyle()->font();
ASSERT( pFont );
WideString sHealth;
sHealth.format( "%d%%", 100 - ((pUnit->damage() * 100) / pUnit->maxDamage()) );
PointInt ptHealth( window.right - pFont->size( sHealth ).width, window.top );
Font::push( context.display(), pFont, ptHealth, sHealth, WHITE );
// display damage bar
if ( pUnit->damage() > 0 )
{
float damage = 1.0f - (pUnit->damage() / pUnit->maxDamage());
RectInt bar( window.m_Left, window.m_Bottom + 1,
window.m_Right - (window.width() * (1.0f - damage)), window.m_Bottom + 3 );
RectFloat barUV(0,0,1,1);
Color barColor( 255 * (1.0f - damage), 255 * damage,0,255 );
PrimitiveMaterial::push( context.display(), PrimitiveMaterial::NONE );
PrimitiveWindow::push( context.display(), bar, barUV, barColor );
}
}
}
}