Skip to content

Commit

Permalink
Merge pull request #1106 from illwieckz/responsive
Browse files Browse the repository at this point in the history
responsive: compute font size from screen size
  • Loading branch information
illwieckz committed Mar 3, 2019
2 parents 87c2104 + 81ef853 commit f29e78d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/cgame/cg_rocket.cpp
Expand Up @@ -105,6 +105,10 @@ void CG_Rocket_Init( glconfig_t gl )
// Register elements
CG_Rocket_RegisterElements();

// This gets 12px on 1920×1080 screen, which is libRocket default for 1em
int fontSize = std::min(cgs.glconfig.vidWidth, cgs.glconfig.vidHeight) / 90;
Rocket_RegisterProperty( "font-size", std::to_string(fontSize).c_str(), true, true, "number" );

Rocket_RegisterProperty( "cell-color", "white", false, false, "color" );
Rocket_RegisterProperty( "border-width", "0.5", false, false, "number" );
Rocket_RegisterProperty( "unlocked-marker-color", "green", false, false, "color" );
Expand Down
7 changes: 5 additions & 2 deletions src/cgame/rocket/rocketCircleMenu.h
Expand Up @@ -370,9 +370,12 @@ class RocketCircleMenu : public Rocket::Core::Element, public Rocket::Controls::
float y = sin( angle * ( i - 1 ) * ( M_PI / 180.0f ) ) * radius;
float x = cos( angle * ( i - 1 ) * ( M_PI / 180.0f ) ) * radius;

// This gets 12px on 1920×1080 screen, which is libRocket default for 1em
int fontSize = std::min(cgs.glconfig.vidWidth, cgs.glconfig.vidHeight) / 90;

child->SetProperty( "position", "absolute" );
child->SetProperty( "left", va( "%fpx", ( dimensions.x / 2 ) - ( width / 2 ) + offset.x + x ) );
child->SetProperty( "top", va( "%fpx", ( dimensions.y / 2 ) - ( height / 2 ) + offset.y + y ) );
child->SetProperty( "left", va( "%fpx", ( dimensions.x / 2 ) - ( width / 2 ) + offset.x + x * fontSize ) );
child->SetProperty( "top", va( "%fpx", ( dimensions.y / 2 ) - ( height / 2 ) + offset.y + y * fontSize ) );
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/cgame/rocket/rocket_documents.cpp
Expand Up @@ -60,8 +60,16 @@ void Rocket_LoadDocument( const char *path )
void Rocket_LoadCursor( const char *path )
{
Rocket::Core::ElementDocument* document = menuContext->LoadMouseCursor( path );

if( document )
{
// This gets 12px on 1920×1080 screen, which is libRocket default for 1em
int fontSize = std::min(cgs.glconfig.vidWidth, cgs.glconfig.vidHeight) / 90;

// 1.6×2.3em ≈ 20×28px on 1920×1080 screen
document->SetProperty( "width", va( "%fpx", 1.6 * fontSize ) );
document->SetProperty( "height", va( "%fpx", 2.3 * fontSize ) );

document->RemoveReference();
}
}
Expand Down

0 comments on commit f29e78d

Please sign in to comment.