/Tukui/core/uiscale.lua

http://github.com/Asphyxia/Tukui · Lua · 132 lines · 78 code · 25 blank · 29 comment · 44 complexity · bc0caa4b9b986a05e122229c8b0e2b95 MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. --------------------------------------------------------
  3. -- detect if high, low or eyefinity version
  4. --------------------------------------------------------
  5. if T.getscreenwidth < 1600 then
  6. if C.general.overridelowtohigh == true then
  7. C["general"].autoscale = false
  8. T.lowversion = false
  9. else
  10. T.lowversion = true
  11. end
  12. elseif (T.getscreenwidth >= 3840) or (UIParent:GetWidth() + 1 > T.getscreenwidth) then
  13. local width = T.getscreenwidth
  14. local height = T.getscreenheight
  15. -- because some user enable bezel compensation, we need to find the real width of a single monitor.
  16. -- I don't know how it really work, but i'm assuming they add pixel to width to compensate the bezel. :P
  17. -- HQ resolution
  18. if width >= 9840 then width = 3280 end -- WQSXGA
  19. if width >= 7680 and width < 9840 then width = 2560 end -- WQXGA
  20. if width >= 5760 and width < 7680 then width = 1920 end -- WUXGA & HDTV
  21. if width >= 5040 and width < 5760 then width = 1680 end -- WSXGA+
  22. -- adding height condition here to be sure it work with bezel compensation because WSXGA+ and UXGA/HD+ got approx same width
  23. if width >= 4800 and width < 5760 and height == 900 then width = 1600 end -- UXGA & HD+
  24. -- low resolution screen
  25. if width >= 4320 and width < 4800 then width = 1440 end -- WSXGA
  26. if width >= 4080 and width < 4320 then width = 1360 end -- WXGA
  27. if width >= 3840 and width < 4080 then width = 1224 end -- SXGA & SXGA (UVGA) & WXGA & HDTV
  28. -- yep, now set Tukui to lower reso if screen #1 width < 1600
  29. if width < 1600 and not C.general.overridelowtohigh then
  30. T.lowversion = true
  31. end
  32. -- register a constant, we will need it later for launch.lua
  33. T.eyefinity = width
  34. end
  35. -- raid scale according to which version we use
  36. if T.lowversion then
  37. T.raidscale = 0.8
  38. else
  39. T.raidscale = 1
  40. end
  41. --------------------------------------------------------
  42. -- Auto Scale UI (Overwrite Settings and Blizzard)
  43. --------------------------------------------------------
  44. -- autoscale
  45. if C["general"].autoscale == true then
  46. C["general"].uiscale = min(2, max(.64, 768/string.match(T.resolution, "%d+x(%d+)")))
  47. end
  48. --------------------------------------------------------
  49. -- Graphics Settings
  50. --------------------------------------------------------
  51. -- the ui doesn't reload if ratio stay the same, we need to force reload if it happen.
  52. local function NeedReloadUI()
  53. local resolution = Graphics_ResolutionDropDown
  54. local x, y = resolution:getValues()
  55. local oldratio = T.getscreenwidth / T.getscreenheight
  56. local newratio = x / y
  57. local oldreso = T.resolution
  58. local newreso = x.."x"..y
  59. if (oldratio == newratio) and (oldreso ~= newreso) then
  60. ReloadUI()
  61. end
  62. end
  63. local Graphic = CreateFrame("Frame")
  64. Graphic:RegisterEvent("PLAYER_ENTERING_WORLD")
  65. Graphic:SetScript("OnEvent", function(self, event)
  66. -- always enable uiscale for Tukui (needed)
  67. local useUiScale = GetCVar("useUiScale")
  68. if useUiScale ~= "1" then
  69. SetCVar("useUiScale", 1)
  70. end
  71. -- Multisample need to be at 1 for pixel perfectness
  72. local gxMultisample = GetCVar("gxMultisample")
  73. if C["general"].multisampleprotect == true and gxMultisample ~= "1" then
  74. SetMultisampleFormat(1)
  75. end
  76. -- uiscale security
  77. if C["general"].uiscale > 1 then C["general"].uiscale = 1 end
  78. if C["general"].uiscale < 0.64 then C["general"].uiscale = 0.64 end
  79. -- set our new uiscale now if it doesn't match Blizzard saved uiScale.
  80. if format("%.2f", GetCVar("uiScale")) ~= format("%.2f", C["general"].uiscale) then
  81. -- if we set an uiscale, it broke quest when opening full size map in combat
  82. T.FullMapQuestTaintFix = true
  83. -- set new ui scale
  84. SetCVar("uiScale", C["general"].uiscale)
  85. end
  86. -- we adjust UIParent to screen #1 if Eyefinity is found
  87. if T.eyefinity then
  88. local width = T.eyefinity
  89. local height = T.getscreenheight
  90. -- if autoscale is off, find a new width value of UIParent for screen #1.
  91. if not C.general.autoscale or height > 1200 then
  92. local h = UIParent:GetHeight()
  93. local ratio = T.getscreenheight / h
  94. local w = T.eyefinity / ratio
  95. width = w
  96. height = h
  97. end
  98. UIParent:SetSize(width, height)
  99. UIParent:ClearAllPoints()
  100. UIParent:SetPoint("CENTER")
  101. end
  102. -- require a reload when graphics option changes, even if Standard Blizzard UI doesn't really need it.
  103. VideoOptionsFrameOkay:HookScript("OnClick", NeedReloadUI)
  104. VideoOptionsFrameApply:HookScript("OnClick", NeedReloadUI)
  105. -- unload
  106. self:UnregisterEvent("PLAYER_ENTERING_WORLD")
  107. end)