Skip to content

Commit

Permalink
auto size font for screen resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
MjnMixael committed Sep 8, 2024
1 parent 854b013 commit 5123974
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions code/graphics/software/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,27 @@ namespace
}
}

if (optional_string("+Auto Size:")) {
bool autoSize;
stuff_boolean(&autoSize);

if (autoSize) {
// Lambda to calculate font size based on screen resolution
auto calculateAutoSize = [size]() -> float {
int vmin = std::min(gr_screen.max_w, gr_screen.max_h);

// Base size calculation (similar to ~Npx font at 1080p)
// Use 1080p because that's generally what font sizes have been targeting for years
// And should provide a fairly close out-of-the-box solution
float baseSize = vmin * (size / 1080.0f);
return std::round(baseSize);
};

// Set the font size based on the result of the lambda
size = calculateAutoSize();
}
}

// Build name from existing values if no name is specified
if (!hasName)
{
Expand Down

0 comments on commit 5123974

Please sign in to comment.