Jump to content

Font sizes


Rick
 Share

Recommended Posts

I'm sizing my HUD images based on fractions of screen width then use the image ratio to calc it's height to scale the images on any screen resolution. However, I'm not really sure how to get proper font sizes now in a similar way to match that scaling. Any ideas on how to get correct font sizes when scaling things?

Link to comment
Share on other sites

I used something like this in Cuber. Hopefully it will help smile.png Really wish the forum wouldn't mess up the code.

 

edit: the site changes window.Titlebar and window.Fullscreen. The w should be uppercase. :/

 

Main.lua

--Gfx modes
count = System:CountGraphicsModes()
rez=count-1
FPSTable = {}
resolutions = {}
for i = 0, count-1 do resolutions[i] = System:GetGraphicsMode(i) end
--scaling
optimalWidth = 1920
optimalHeight = 1080
local windowstyle = window.Titlebar
windowstyle=windowstyle+window.FullScreen
window=Window:Create(title,0,0,System:GetProperty("screenwidth","800"),System:GetProperty("screenheight","600"),windowstyle)
--set to highest available resolution
window:SetLayout(0,0,resolutions[count-1].x,resolutions[count-1].y)
--window:HideMouse()
--Create the graphics context
context=Context:Create(window,0)
if context==nil then return end
--Create a world
world=World:Create()
world:SetLightQuality((System:GetProperty("lightquality","1")))
--Create a camera
camera = Camera:Create()
camera:Move(5,13,-2)
--load fonts
fontArial12 = Font:Load("Fonts/arial.ttf",12)
fontArial24 = Font:Load("Fonts/arial.ttf",24)
fontArial48 = Font:Load("Fonts/arial.ttf",48)
--screen ratios
res1 = resolutions[rez].x/optimalWidth
res2 = resolutions[rez].y/optimalHeight
while window:KeyDown(Key.Escape)==false do
--change resolution
if window:KeyHit(Key.Down) then
rez=rez-1
if rez<1 then rez=0 end
res1 = resolutions[rez].x/optimalWidth
res2 = resolutions[rez].y/optimalHeight
window:SetLayout(0,0,resolutions[rez].x,resolutions[rez].y)
elseif window:KeyHit(Key.Up) then
rez=rez+1
if rez>count-1 then rez=count-1 end
res1 = resolutions[rez].x/optimalWidth
res2 = resolutions[rez].y/optimalHeight
window:SetLayout(0,0,resolutions[rez].x,resolutions[rez].y)
end

--If window has been closed, end the program
if window:Closed() then break end
--Update the app timing
Time:Update()

--Update the world
world:Update()

--Render the world
world:Render()
context:SetBlendMode(Blend.Alpha)
screenX = window:GetWidth()/2
screenY = window:GetHeight()/2
--draw rect around screen
context:DrawRect(0, 0, resolutions[rez].x, resolutions[rez].y,1)
--draw gui panel to scale
context:SetColor(.2,.2,.2,.7)
context:DrawRect(screenX-150*res1, screenY-160*res2, screenX-670*res1, screenY-360*res2)
--draw fonts to scale
context:SetScale(res1, res2)
context:SetFont(fontArial24)
context:SetColor(.2,1,.2,.9)
context:DrawText("up/down-resolution", screenX-140*res1, screenY-150*res2)
context:SetColor(.2,1,.2,.9)
context:DrawText(tostring(resolutions[rez].x).." x "..tostring(resolutions[rez].y), screenX-90*res1, screenY-120*res2)
context:SetFont(fontArial12)
context:SetColor(.4,.6,.9,.9)
context:DrawText("Arial 12", screenX-35*res1, screenY-85*res2)
context:SetFont(fontArial24)
context:DrawText("Arial 24", screenX-60*res1, screenY-60*res2)
context:SetFont(fontArial48)
context:DrawText("Arial 48", screenX-110*res1, screenY-30*res2)
--reset scale when done
context:SetScale(1, 1)
context:SetBlendMode(Blend.Solid)
--Refresh the screen
context:Sync(true)
end

  • Upvote 3

---

Scott

 

Using Windows 7 Ultimate 64 bit/Core I7-2700K @ 4312mhz/24G RAM/Nvidia GTX 1060

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...