Quantcast
function SVUIScreenOnLoad(self)
    local macWidth = math.floor(GetScreenWidth() * 100 + .5) / 100;
    self:SetAttribute("MAC_DISPLAY_WIDTH", macWidth);

    local macHeight = math.floor(GetScreenHeight() * 100 + .5) / 100;
    self:SetAttribute("MAC_DISPLAY_HEIGHT", macHeight);

    local effectiveScale = GetScreenHeightScale()
    self:SetAttribute("EFFECTIVE_SCALE", effectiveScale);

    local activeScale
    local autoScale = self:GetAttribute("AUTO_SCALE");
    if(autoScale) then
        activeScale = math.max(0.64, math.min(1.15, GetScreenHeightScale()));
    else
        activeScale = math.max(0.64, math.min(1.15, GetCVar("uiScale") or UIParent:GetScale() or GetScreenHeightScale()));
    end
    self:SetAttribute("ACTIVE_SCALE", activeScale);

    local modScale = effectiveScale / activeScale
    self:SetAttribute("MODIFIED_SCALE", modScale);

    self:RegisterEvent("PLAYER_LOGIN");
    self:RegisterEvent("UI_SCALE_CHANGED");
end

function SVUIScreenOnEvent(self, event)
    local rez = GetCVar("gxResolution")
    local height = rez:match("%d+x(%d+)")
    local width = rez:match("(%d+)x%d+")
    local gxHeight = tonumber(height)
    local gxWidth = tonumber(width)
    local evalwidth;

    local macWidth = math.floor(GetScreenWidth() * 100 + .5) / 100;
    self:SetAttribute("MAC_DISPLAY_WIDTH", macWidth);
    local macHeight = math.floor(GetScreenHeight() * 100 + .5) / 100;
    self:SetAttribute("MAC_DISPLAY_HEIGHT", macHeight);
    local effectiveScale = GetScreenHeightScale()
    self:SetAttribute("EFFECTIVE_SCALE", effectiveScale);

    local activeScale
    local autoScale = self:GetAttribute("AUTO_SCALE");
    if(autoScale) then
        activeScale = math.max(0.64, math.min(1.15, GetScreenHeightScale()));
    else
        activeScale = math.max(0.64, math.min(1.15, GetCVar("uiScale") or UIParent:GetScale() or GetScreenHeightScale()));
    end
    self:SetAttribute("ACTIVE_SCALE", activeScale);

    local modScale = effectiveScale / activeScale
    self:SetAttribute("MODIFIED_SCALE", modScale);

    if(IsMacClient()) then
        macHeight = self:GetAttribute("MAC_DISPLAY_HEIGHT");
        macWidth = self:GetAttribute("MAC_DISPLAY_WIDTH");
        if(gxHeight ~= macHeight or gxWidth ~= macWidth) then
            gxHeight = macHeight
            gxWidth = macWidth
        end
    end

    if(gxWidth < 1600) then
        self.LowRez = true;
    elseif(gxWidth >= 3840) then
        self.LowRez = nil
        if(self:GetAttribute("MULTI_MONITOR")) then
            if(gxWidth < 4080) then
                evalwidth = 1224;
            elseif(gxWidth < 4320) then
                evalwidth = 1360;
            elseif(gxWidth < 4800) then
                evalwidth = 1440;
            elseif(gxWidth < 5760) then
                if(gxHeight == 900) then evalwidth = 1600 else evalwidth = 1680 end
            elseif(gxWidth < 7680) then
                evalwidth = 1920;
            elseif(gxWidth < 9840) then
                evalwidth = 2560;
            elseif(gxWidth > 9839) then
                evalwidth = 3280;
            end
        else
            if(gxWidth < 4080) then
                evalwidth = 3840;
            elseif(gxWidth < 4320) then
                evalwidth = 4080;
            elseif(gxWidth < 4800) then
                evalwidth = 4320;
            elseif(gxWidth < 5040) then
                evalwidth = 4800;
            elseif(gxWidth < 5760) then
                evalwidth = 5040;
            elseif(gxWidth < 7680) then
                evalwidth = 5760;
            elseif(gxWidth < 9840) then
                evalwidth = 7680;
            elseif(gxWidth > 9839) then
                evalwidth = 9840;
            end
        end
    end

    self:ClearAllPoints();

    if evalwidth then
        local width = evalwidth
        local height = gxHeight;
        if(not autoScale or height > 1200) then
            height = UIParent:GetHeight();
            local ratio = gxHeight / height;
            width = evalwidth / ratio;
        end
        self:SetSize(width, height);
        self:SetPoint("CENTER");
    else
        self:SetAllPoints(UIParent);
    end
end