Jump to content

Font sizes and resolution


aiaf
 Share

Recommended Posts

This is bad , didnt give much thought to resolution that the game need to support.

To simplify i decided to support only 16:9 aspect size resolutions (1920x1080, 1600×900 etc).

 For the hud was simple i changed to have sizes depending on resolution:

context->DrawImage(sentinelModuleLaserTex, context->GetWidth() / 30, context->GetHeight()/2, moduleDrawSize, moduleDrawSize);

 

Text sizes are the problem , I have a complicated text ui , and have to somehow fix up all spaces between and resize fonts depending on resolution.

  mainMenuFont = Leadwerks::Font::Load("Fonts/arial.ttf", 16);
  context->SetFont(mainMenuFont);

Question is theres another way to have text resize automatically depending on resolution ?

 

I made this with Leadwerks/UAK:

Structura Stacky Desktop Edition

Website:

Binary Station

Link to comment
Share on other sites

I solved this by having the idea that everything is an "element" that has a bounding box area. That bounding box area (the size of the element) is the thing that's resized based on resolution so it looks the same between all resolutions. Then I have a label "widget" which is basically an element with just text. I can set the size of the text by setting it to be "x-small, small, medium, large, x-large, Fill". When the game starts it loads a bunch of fonts going up by 2 in size and stores them in a table. It then uses the font width and height functions to find the max font that fills the height and/or width (makes sure the font width/height isn't bigger than the bounding box of the element).

Basically it starts at the biggest font loaded and goes down in size until the width and height fit into the element bounding box area. That's the fill font and all the other fonts are percentages of that. x-large = 80% of fill font, large = 70% etc (might not be exact numbers as I don't recall but you get the point). If the fill font size was 30 then x-large is 80% of 30 or 24. Since I only loaded fonts by multiples of 2 if the math works out to be an odd number (I truncate any decimals) then I subtract 1 to get the even number that is smaller so I know it'll fit. I mark the font as being used and assign that element that font object and any font in the table that isn't used is deleted from memory.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...