Skip to content

Commit

Permalink
correct text window height for Draw_Static_Text and cDebugDisplay
Browse files Browse the repository at this point in the history
  • Loading branch information
FluXy committed Apr 5, 2011
1 parent 9d85779 commit 3007f75
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion smc/data/gui/layout/debugtext.layout
Expand Up @@ -9,7 +9,8 @@
<Window Type="TaharezLook/StaticText" Name="text_debugmessage" >
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
<Property Name="UnifiedAreaRect" Value="{{0.35,0},{0.14,0},{0.75,0},{0.19,0}}" />
<Property Name="MousePassThroughEnabled" Value="True" />
<Property Name="MousePassThroughEnabled" Value="True" />
<Property Name="HorzFormatting" Value="WordWrapLeftAligned" />
</Window>
</Window>
</GUILayout>
4 changes: 3 additions & 1 deletion smc/src/gui/generic.cpp
Expand Up @@ -374,8 +374,10 @@ void Draw_Static_Text( const std::string &text, const Color *color_text /* = &wh
text_default->setXPosition( CEGUI::UDim( 0, ( game_res_w * 0.5f - text_width * 0.5f ) * global_upscalex ) );
text_default->moveToFront();

float text_height = font->getLineSpacing();
text_height *= 1 + std::count(text.begin(), text.end(), '\n');
// set window height
text_default->setHeight( CEGUI::UDim( 0, (font->getFontHeight() * 2) + ( 12 * global_upscaley ) ) );
text_default->setHeight( CEGUI::UDim( 0, text_height + ( 12 * global_upscaley ) ) );

while( draw )
{
Expand Down
9 changes: 8 additions & 1 deletion smc/src/gui/hud.cpp
Expand Up @@ -977,13 +977,20 @@ void cDebugDisplay :: Update( void )
// update position
CEGUI::Font *font = &CEGUI::FontManager::getSingleton().get( "bluebold_medium" );
float text_width = font->getTextExtent( gui_text ) * global_downscalex;
float text_height = font->getLineSpacing() * global_downscaley;

// fixme : works only correctly for one too long line
if( text_width > 800.0f )
{
// add wrapped newlines
text_height *= 1 + static_cast<int>(text_width / 800.0f);
text_width = 800.0f;
}

m_text_debug_text->setWidth( CEGUI::UDim( 0, ( text_width + 15 ) * global_upscalex ) );
// add newlines
text_height *= 1 + std::count(m_text.begin(), m_text.end(), '\n');

m_text_debug_text->setSize( CEGUI::UVector2( CEGUI::UDim( 0, ( text_width + 15 ) * global_upscalex ), CEGUI::UDim( 0, ( text_height + 15 ) * global_upscaley ) ) );
m_text_debug_text->setXPosition( CEGUI::UDim( 0, ( ( game_res_w * 0.5f ) - text_width * 0.5f ) * global_upscalex ) );
}
}
Expand Down

0 comments on commit 3007f75

Please sign in to comment.