Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from AlexRazor1337/master
Browse files Browse the repository at this point in the history
Screen size font adaptation
  • Loading branch information
Andrey Pavlov authored Sep 22, 2019
2 parents 16053f6 + 4433f9b commit cd73aa1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
22 changes: 22 additions & 0 deletions chat2_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ end
function onChatLoaded()
chatInstanceLoaded = true
focusBrowser(chatInstance)
adoptFont()
end

function onChatInputButton(_, _, keyButton, definition)
Expand Down Expand Up @@ -192,6 +193,27 @@ function onClientResourceStop()
showChat(true)
end

function getAspectRatio()
local dxResolution
local dw, dh = guiGetScreenSize()
local aspectRatio = math.round( dw / dh, 2 )
local dxAspectRatio = "16:9"
if aspectRatio == 1.33 then dxAspectRatio = "4:3"
elseif aspectRatio == 1.25 then dxAspectRatio = "5:4"
elseif aspectRatio == 1.77 then dxAspectRatio = "16:9"
end
return dxAspectRatio
end

function adoptFont()
if getAspectRatio() ~= "16:9" then
executeBrowserJavascript(chatInstance,
"let stylesElement = document.createElement('style');" ..
'stylesElement.innerHTML = ".chat__message {font-size: 4vh} .chat__input {font-size: 4vh}";' ..
'document.body.appendChild(stylesElement);')
end
end

addEventHandler("onChat2Loaded", resourceRoot, onChatLoaded)
addEventHandler("onChat2EnterButton", resourceRoot, onChatEnterButton)
addEventHandler("onChat2Output", localPlayer, output)
Expand Down
7 changes: 7 additions & 0 deletions chat2_shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ function RGBToHex(red, green, blue)

return string.format("#%.2X%.2X%.2X", red, green, blue)
end

function math.round(number, decimals, method)
decimals = decimals or 0
local factor = 10 ^ decimals
if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor
else return tonumber(("%."..decimals.."f"):format(number)) end
end

0 comments on commit cd73aa1

Please sign in to comment.