PageRenderTime 376ms CodeModel.GetById 89ms app.highlight 52ms RepoModel.GetById 62ms app.codeStats 40ms

/Tukui/core/uiscale.lua

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