From 687d75f8a0acf5a1fe3087fbba9d7c14b5656343 Mon Sep 17 00:00:00 2001 From: shagu Date: Fri, 13 Dec 2019 20:59:57 +0100 Subject: [PATCH] api: add function that calculates a real pixel --- api/api.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/api/api.lua b/api/api.lua index 15ef49f4..bcf39e1f 100644 --- a/api/api.lua +++ b/api/api.lua @@ -795,6 +795,21 @@ function pfUI.api.rgbhex(r, g, b, a) return hexcolor_cache[key] or "" end +-- [ GetPerfectPixel ] +-- Returns a number that equals a real pixel on regular scaled frames. +-- Respects the current UI-scale and calculates a real pixel based on +-- the screen resolution and the 768px sized drawlayer. +local ppixel +function pfUI.api.GetPerfectPixel() + if ppixel then return ppixel end + + local scale = GetCVar("uiScale") + local resolution = GetCVar("gxResolution") + local _, _, screenwidth, screenheight = strfind(resolution, "(.+)x(.+)") + ppixel = 768 / screenheight / scale + return ppixel +end + -- [ Create Backdrop ] -- Creates a pfUI compatible frame as backdrop element -- 'f' [frame] the frame which should get a backdrop.