vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 CT_Viewport = {
2 ["initialValues"] = {
3 [1] = 563,
4 [2] = 937,
5 [3] = 736,
6 [4] = 455,
7 [5] = 375,
8 [6] = 281
9 },
10 ["currOffset"] = {
11 0, 0, 0, 0
12 }
13 };
14 CT_Viewport_Saved = { 0, 0, 0, 0, 0, 0, 0 };
15  
16 -- Not going to bother adding a localization file :)
17 CT_VIEWPORT_INFO = "Note: |c00FFFFFFLeft click and drag a yellow bar to move the viewport screen. To enter a custom value, type in the number and hit enter to set it, then click apply to see your changes.|r";
18 if ( GetLocale() == "deDE" ) then
19 CT_VIEWPORT_INFO = "Note: |c00FFFFFFLeft click and drag a yellow bar to move the viewport screen. To enter a custom value, type in the number and hit enter to set it, then click apply to see your changes.|r";
20 elseif ( GetLocale() == "frFR" ) then
21 CT_VIEWPORT_INFO = "Note: |c00FFFFFFLeft click and drag a yellow bar to move the viewport screen. To enter a custom value, type in the number and hit enter to set it, then click apply to see your changes.|r";
22 end
23  
24 function CT_Viewport_GetQuotient(number)
25 number = format("%.2f", number);
26  
27 for a = 1, 100, 1 do
28 for b = 1, 100, 1 do
29 if ( format("%.2f", b/a) == number ) then
30 return format("%.2f |r(|c00FFFFFF%d/%d|r)", number, b, a);
31 elseif ( format("%.2f", a/b) == number ) then
32 return format("%.2f r(|c00FFFFFF%d/%d|r)", number, a, b);
33 end
34 end
35 end
36 return number;
37 end
38  
39 -- Add to special frames table
40 tinsert(UISpecialFrames, "CT_ViewportFrame");
41  
42 -- Slash command to display the frame
43 SlashCmdList["VIEWPORT"] = function(msg)
44 local iStart, iEnd, left, right, top, bottom = string.find(msg, "^(%d+) (%d+) (%d+) (%d+)$");
45 if ( left and right and top and bottom ) then
46 CT_Viewport_ApplyViewport(tonumber(left), tonumber(right), tonumber(top), tonumber(bottom));
47 else
48 ShowUIPanel(CT_ViewportFrame);
49 end
50 end
51 SLASH_VIEWPORT1 = "/viewport";
52  
53 -- Resizing functions
54 function CT_Viewport_Resize(anchorPoint, button)
55 if ( not button ) then
56 button = this;
57 end
58 button:GetParent():StartSizing(anchorPoint);
59 CT_Viewport.isResizing = anchorPoint;
60  
61 -- A bit hackish, but meh, it works
62 if ( anchorPoint == "LEFT" ) then
63 button:GetParent():SetMaxResize(CT_Viewport.initialValues[5]-(CT_Viewport.initialValues[2]-CT_ViewportFrameInnerFrame:GetRight()), CT_Viewport.initialValues[6]);
64 elseif ( anchorPoint == "RIGHT" ) then
65 button:GetParent():SetMaxResize(CT_Viewport.initialValues[5]-(CT_ViewportFrameInnerFrame:GetLeft()-CT_Viewport.initialValues[1]), CT_Viewport.initialValues[6]);
66 elseif ( anchorPoint == "TOP" ) then
67 button:GetParent():SetMaxResize(CT_Viewport.initialValues[5], CT_Viewport.initialValues[6]-(CT_ViewportFrameInnerFrame:GetBottom()-CT_Viewport.initialValues[4]));
68 elseif ( anchorPoint == "BOTTOM" ) then
69 button:GetParent():SetMaxResize(CT_Viewport.initialValues[5], CT_Viewport.initialValues[6]-(CT_Viewport.initialValues[3]-CT_ViewportFrameInnerFrame:GetTop()));
70 elseif ( anchorPoint == "TOPLEFT" ) then
71 button:GetParent():SetMaxResize(CT_Viewport.initialValues[5]-(CT_Viewport.initialValues[2]-CT_ViewportFrameInnerFrame:GetRight()), CT_Viewport.initialValues[6]-(CT_ViewportFrameInnerFrame:GetBottom()-CT_Viewport.initialValues[4]));
72 elseif ( anchorPoint == "TOPRIGHT" ) then
73 button:GetParent():SetMaxResize(CT_Viewport.initialValues[5]-(CT_ViewportFrameInnerFrame:GetLeft()-CT_Viewport.initialValues[1]), CT_Viewport.initialValues[6]-(CT_ViewportFrameInnerFrame:GetBottom()-CT_Viewport.initialValues[4]));
74 elseif ( anchorPoint == "BOTTOMLEFT" ) then
75 button:GetParent():SetMaxResize(CT_Viewport.initialValues[5]-(CT_Viewport.initialValues[2]-CT_ViewportFrameInnerFrame:GetRight()), CT_Viewport.initialValues[6]-(CT_Viewport.initialValues[3]-CT_ViewportFrameInnerFrame:GetTop()));
76 elseif ( anchorPoint == "BOTTOMRIGHT" ) then
77 button:GetParent():SetMaxResize(CT_Viewport.initialValues[5]-(CT_ViewportFrameInnerFrame:GetLeft()-CT_Viewport.initialValues[1]), CT_Viewport.initialValues[6]-(CT_Viewport.initialValues[3]-CT_ViewportFrameInnerFrame:GetTop()));
78 end
79 end
80  
81 function CT_Viewport_StopResize(button)
82 if ( not button ) then
83 button = this;
84 end
85 button:GetParent():StopMovingOrSizing();
86 CT_Viewport.isResizing = nil;
87 CT_ViewportFrameAspectRatioNewText:SetText("Aspect Ratio (Current): |c00FFFFFF" .. CT_Viewport_GetQuotient((CT_Viewport.screenRes[1]-CT_Viewport.currOffset[1]-CT_Viewport.currOffset[2])/(CT_Viewport.screenRes[2]-CT_Viewport.currOffset[3]-CT_Viewport.currOffset[4])));
88 CT_ViewportFrameAspectRatioDefaultText:SetText("Aspect Ratio (Default): |c00FFFFFF" .. CT_Viewport_GetQuotient(CT_Viewport.screenRes[1]/CT_Viewport.screenRes[2]));
89 end
90  
91 -- Get initial size values
92 function CT_Viewport_GetInitialValues()
93 CT_Viewport.initialValues = {
94 CT_ViewportFrameInnerFrame:GetLeft(),
95 CT_ViewportFrameInnerFrame:GetRight(),
96 CT_ViewportFrameInnerFrame:GetTop(),
97 CT_ViewportFrameInnerFrame:GetBottom(),
98 CT_ViewportFrameInnerFrame:GetRight()-CT_ViewportFrameInnerFrame:GetLeft(),
99 CT_ViewportFrameInnerFrame:GetTop()-CT_ViewportFrameInnerFrame:GetBottom()
100 };
101 end
102  
103 -- Get current resolution in x and y
104 function CT_Viewport_GetCurrentResolution(...)
105 local currRes = arg[GetCurrentResolution()];
106 if ( currRes ) then
107 local useless, useless, x, y = string.find(currRes, "(%d+)x(%d+)");
108 if ( x and y ) then
109 return tonumber(x), tonumber(y);
110 end
111 end
112 return nil;
113 end
114  
115 -- Apply the viewport settings
116 function CT_Viewport_ApplyViewport(left, right, top, bottom, r, g, b)
117 if ( not left ) then
118 right = ((CT_Viewport.initialValues[2]-CT_ViewportFrameInnerFrame:GetRight())/CT_Viewport.initialValues[5])*CT_Viewport.screenRes[1];
119 left = ((CT_ViewportFrameInnerFrame:GetLeft()-CT_Viewport.initialValues[1])/CT_Viewport.initialValues[5])*CT_Viewport.screenRes[1];
120 top = ((CT_Viewport.initialValues[3]-CT_ViewportFrameInnerFrame:GetTop())/CT_Viewport.initialValues[6])*CT_Viewport.screenRes[2];
121 bottom = ((CT_ViewportFrameInnerFrame:GetBottom()-CT_Viewport.initialValues[4])/CT_Viewport.initialValues[6])*CT_Viewport.screenRes[2];
122 end
123 if ( right < 0 ) then
124 right = 0;
125 end
126 if ( left < 0 ) then
127 left = 0;
128 end
129 if ( top < 0 ) then
130 top = 0;
131 end
132 if ( bottom < 0 ) then
133 bottom = 0;
134 end
135  
136 r = ( r or 0 );
137 g = ( g or 0 );
138 b = ( b or 0 );
139  
140 CT_Viewport_Saved = { left, right, top, bottom, r, g, b }; -- Need to reverse top and bottom because of how it works
141 WorldFrame:ClearAllPoints();
142 WorldFrame:SetPoint("TOPLEFT", (UIParent:GetWidth()/CT_Viewport.screenRes[1])*left, -(UIParent:GetHeight()/CT_Viewport.screenRes[2])*top);
143 WorldFrame:SetPoint("BOTTOMRIGHT", -(UIParent:GetWidth()/CT_Viewport.screenRes[1])*right, (UIParent:GetHeight()/CT_Viewport.screenRes[2])*bottom);
144 CT_ViewportOverlay:SetVertexColor(r, g, b, 1);
145 end
146  
147 -- Apply saved settings to the inner viewport
148 function CT_Viewport_ApplyInnerViewport(left, right, top, bottom, r, g, b)
149 CT_ViewportFrameLeftEB:SetText(floor(left+0.5));
150 CT_ViewportFrameRightEB:SetText(floor(right+0.5));
151 CT_ViewportFrameTopEB:SetText(floor(top+0.5));
152 CT_ViewportFrameBottomEB:SetText(floor(bottom+0.5));
153 CT_Viewport.currOffset = {
154 floor(left+0.5), floor(right+0.5), floor(top+0.5), floor(bottom+0.5)
155 };
156 CT_ViewportFrameAspectRatioNewText:SetText("Aspect Ratio (Current): |c00FFFFFF" .. CT_Viewport_GetQuotient((CT_Viewport.screenRes[1]-left-right)/(CT_Viewport.screenRes[2]-top-bottom)));
157 CT_ViewportFrameAspectRatioDefaultText:SetText("Aspect Ratio (Default): |c00FFFFFF" .. CT_Viewport_GetQuotient(CT_Viewport.screenRes[1]/CT_Viewport.screenRes[2]));
158 left = left*(CT_Viewport.initialValues[5]/CT_Viewport.screenRes[1]);
159 right = right*(CT_Viewport.initialValues[5]/CT_Viewport.screenRes[1]);
160 top = top*(CT_Viewport.initialValues[6]/CT_Viewport.screenRes[2]);
161 bottom = bottom*(CT_Viewport.initialValues[6]/CT_Viewport.screenRes[2]);
162 CT_ViewportFrameInnerFrame:ClearAllPoints();
163 CT_ViewportFrameInnerFrame:SetPoint("TOPLEFT", "CT_ViewportFrameBorderFrame", "TOPLEFT", left+4, -(top+4));
164 CT_ViewportFrameInnerFrame:SetPoint("BOTTOMRIGHT", "CT_ViewportFrameBorderFrame", "BOTTOMRIGHT", -(right+4), bottom+4);
165 local frameTop, frameBottom, frameLeft, frameRight = CT_ViewportFrameInnerFrame:GetTop(), CT_ViewportFrameInnerFrame:GetBottom(), CT_ViewportFrameInnerFrame:GetLeft(), CT_ViewportFrameInnerFrame:GetRight();
166 if ( frameTop and frameBottom and frameLeft and frameRight ) then
167 CT_ViewportFrameInnerFrame:SetHeight(frameTop-frameBottom);
168 CT_ViewportFrameInnerFrame:SetWidth(frameRight-frameLeft);
169 else
170 CT_ViewportFrame.awaitingValues = 1;
171 end
172 end
173  
174 -- Change a side of the viewport
175 function CT_Viewport_ChangeViewportSide()
176 local value = tonumber(this:GetText());
177 if ( not value ) then
178 return;
179 end
180 value = abs(value);
181 local id = this:GetID();
182 local left, right, top, bottom, width, height = CT_Viewport.currOffset[1], CT_Viewport.currOffset[2], CT_Viewport.currOffset[3], CT_Viewport.currOffset[4];
183 if ( id == 1 ) then
184 -- Left
185 CT_Viewport_ApplyInnerViewport(value, right, top, bottom);
186 elseif ( id == 2 ) then
187 -- Right
188 CT_Viewport_ApplyInnerViewport(left, value, top, bottom);
189 elseif ( id == 3 ) then
190 -- Top
191 CT_Viewport_ApplyInnerViewport(left, right, value, bottom);
192 elseif ( id == 4 ) then
193 -- Bottom
194 CT_Viewport_ApplyInnerViewport(left, right, top, value);
195 end
196 end
197  
198 -- Handlers
199 -- OnLoad
200 function CT_ViewportFrame_OnLoad()
201 local x, y = CT_Viewport_GetCurrentResolution(GetScreenResolutions());
202 if ( x and y ) then
203 local modifier = x/y;
204 if ( modifier ~= (4/3) ) then
205 local newViewportHeight = CT_Viewport.initialValues[6]/(x/y);
206 CT_ViewportFrameInnerFrame:SetHeight(newViewportHeight);
207 CT_ViewportFrameBorderFrame:SetHeight(newViewportHeight+8);
208 end
209 CT_Viewport.screenRes = { x, y };
210 CT_ViewportFrame:SetHeight(210+CT_ViewportFrameBorderFrame:GetHeight());
211 CT_Viewport.awaitingValues = 1;
212 end
213 CT_ViewportFrameInnerFrame:SetBackdropBorderColor(1, 1, 0, 1);
214 CT_ViewportFrameBorderFrame:SetBackdropBorderColor(1, 0, 0, 1);
215 CT_ViewportFrameInnerFrameBackground:SetVertexColor(1, 1, 0, 0.1);
216  
217 CT_ViewportOverlay = WorldFrame:CreateTexture("CT_ViewportOverlay", "BACKGROUND");
218 CT_ViewportOverlay:SetTexture(1, 1, 1, 1);
219 CT_ViewportOverlay:SetPoint("TOPLEFT", "UIParent", "TOPLEFT", -1, 1);
220 CT_ViewportOverlay:SetPoint("BOTTOMRIGHT", "UIParent", "BOTTOMRIGHT", 1, -1);
221 this:RegisterEvent("VARIABLES_LOADED");
222 end
223  
224 -- OnUpdate
225 function CT_ViewportFrame_OnUpdate(elapsed)
226 if ( not this.hasAppliedViewport ) then
227 this.hasAppliedViewport = 1;
228 CT_ViewportFrameInnerFrame:ClearAllPoints();
229 CT_ViewportFrameInnerFrame:SetPoint("TOPLEFT", "CT_ViewportFrameBorderFrame", "TOPLEFT", 4, -4);
230 CT_ViewportFrameInnerFrame:SetPoint("BOTTOMRIGHT", "CT_ViewportFrameBorderFrame", "BOTTOMRIGHT", -4, 4);
231 elseif ( this.hasAppliedViewport == 1 ) then
232 this.hasAppliedViewport = 2;
233 if ( CT_Viewport.awaitingValues ) then
234 CT_Viewport_GetInitialValues();
235 CT_Viewport.awaitingValues = nil;
236 CT_ViewportFrameInnerFrame:SetMinResize(CT_Viewport.initialValues[5]/2, CT_Viewport.initialValues[6]/2);
237 CT_ViewportFrameLeftEB.limitation = CT_Viewport.screenRes[1]/2;
238 CT_ViewportFrameRightEB.limitation = CT_Viewport.screenRes[1]/2;
239 CT_ViewportFrameTopEB.limitation = CT_Viewport.screenRes[2]/2;
240 CT_ViewportFrameBottomEB.limitation = CT_Viewport.screenRes[2]/2;
241 end
242 CT_ViewportFrame_OnShow();
243 end
244 if ( CT_Viewport.isResizing ) then
245 local right = ((CT_Viewport.initialValues[2]-CT_ViewportFrameInnerFrame:GetRight())/CT_Viewport.initialValues[5])*CT_Viewport.screenRes[1];
246 local left = ((CT_ViewportFrameInnerFrame:GetLeft()-CT_Viewport.initialValues[1])/CT_Viewport.initialValues[5])*CT_Viewport.screenRes[1];
247 local top = ((CT_Viewport.initialValues[3]-CT_ViewportFrameInnerFrame:GetTop())/CT_Viewport.initialValues[6])*CT_Viewport.screenRes[2];
248 local bottom = ((CT_ViewportFrameInnerFrame:GetBottom()-CT_Viewport.initialValues[4])/CT_Viewport.initialValues[6])*CT_Viewport.screenRes[2];
249 if ( right < 0 ) then
250 right = 0;
251 end
252 if ( left < 0 ) then
253 left = 0;
254 end
255 if ( top < 0 ) then
256 top = 0;
257 end
258 if ( bottom < 0 ) then
259 bottom = 0;
260 end
261 CT_ViewportFrameLeftEB:SetText(floor(left+0.5));
262 CT_ViewportFrameRightEB:SetText(floor(right+0.5));
263 CT_ViewportFrameTopEB:SetText(floor(top+0.5));
264 CT_ViewportFrameBottomEB:SetText(floor(bottom+0.5));
265 CT_Viewport.currOffset = {
266 floor(left+0.5), floor(right+0.5), floor(top+0.5), floor(bottom+0.5)
267 };
268 if ( not this.update ) then
269 this.update = 0;
270 else
271 this.update = this.update - elapsed;
272 end
273 if ( this.update <= 0 ) then
274 CT_ViewportFrameAspectRatioNewText:SetText("Aspect Ratio (Current): |c00FFFFFF" .. CT_Viewport_GetQuotient((CT_Viewport.screenRes[1]-left-right)/(CT_Viewport.screenRes[2]-top-bottom)));
275 CT_ViewportFrameAspectRatioDefaultText:SetText("Aspect Ratio (Default): |c00FFFFFF" .. CT_Viewport_GetQuotient(CT_Viewport.screenRes[1]/CT_Viewport.screenRes[2]));
276 this.update = 0.1;
277 end
278 else
279 this.update = nil;
280 end
281 end
282  
283 -- OnShow
284 function CT_ViewportFrame_OnShow()
285 if ( CT_ViewportFrameInnerFrame:GetLeft() ) then
286 local left, right, top, bottom, width, height, r, g, b = CT_Viewport_Saved[1], CT_Viewport_Saved[2], CT_Viewport_Saved[3], CT_Viewport_Saved[4], CT_Viewport_Saved[5], CT_Viewport_Saved[6], CT_Viewport_Saved[7];
287 CT_Viewport_ApplyInnerViewport(left, right, top, bottom, r, g, b);
288 end
289 end
290  
291 -- OnEvent
292 function CT_ViewportFrame_OnEvent(event)
293 if ( event == "VARIABLES_LOADED" ) then
294 CT_Viewport_ApplyViewport(CT_Viewport_Saved[1], CT_Viewport_Saved[2], CT_Viewport_Saved[3], CT_Viewport_Saved[4], CT_Viewport_Saved[5], CT_Viewport_Saved[6], CT_Viewport_Saved[7]);
295 end
296 end
297  
298 -- Hook SetScreenResolution to update
299 CT_Viewport_oldSetScreenResolution = SetScreenResolution;
300 function CT_Viewport_newSetScreenResolution(newResolution)
301 CT_Viewport_oldSetScreenResolution(newResolution);
302 CT_ViewportFrame_OnLoad();
303 CT_ViewportFrame.hasAppliedViewport = nil;
304 end
305 SetScreenResolution = CT_Viewport_newSetScreenResolution;
306  
307 -- Add to CT Control panel if available
308 if ( CT_RegisterMod ) then
309 CT_RegisterMod("Viewport", "Modify Viewport", 5, "Interface\\Icons\\Spell_Arcane_TeleportStormWind", "Shows the Viewport dialog, where you can modify the game viewport.", "switch", nil, function() if ( CT_ViewportFrame:IsVisible() ) then HideUIPanel(CT_ViewportFrame) else ShowUIPanel(CT_ViewportFrame) end end);
310 end