vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | IMBA_Lines={}; |
2 | IMBA_Line_Data={}; |
||
3 | IMBA_LINE_DATA_SX = 1 |
||
4 | IMBA_LINE_DATA_SY = 2 |
||
5 | IMBA_LINE_DATA_EX = 3 |
||
6 | IMBA_LINE_DATA_EY = 4 |
||
7 | IMBA_LINE_DATA_WIDTH = 5 |
||
8 | IMBA_LINE_DATA_COLOR = 6 |
||
9 | |||
10 | --Copied from Blizzard's TaxiFrame code and modifed for IMBA |
||
11 | |||
12 | -- The following function is used with permission from Daniel Stephens <iriel@vigilance-committee.org> |
||
13 | TAXIROUTE_LINEFACTOR = 32/30; -- Multiplying factor for texture coordinates |
||
14 | TAXIROUTE_LINEFACTOR_2 = TAXIROUTE_LINEFACTOR / 2; -- Half o that |
||
15 | |||
16 | -- T - Texture |
||
17 | -- C - Canvas Frame (for anchoring) |
||
18 | -- sx,sy - Coordinate of start of line |
||
19 | -- ex,ey - Coordinate of end of line |
||
20 | -- w - Width of line |
||
21 | -- relPoint - Relative point on canvas to interpret coords (Default BOTTOMLEFT) |
||
22 | --/script IMBA_DrawLine(IMBA_Ouro,0,0,-200,-200,32) |
||
23 | function IMBA_DrawLine(C, sx, sy, ex, ey, w, color) |
||
24 | local T, lineNum, relPoint; |
||
25 | if (not relPoint) then relPoint = "BOTTOMLEFT"; end |
||
26 | |||
27 | if not IMBA_Lines[C:GetName()] then |
||
28 | IMBA_Lines[C:GetName()]={}; |
||
29 | end |
||
30 | |||
31 | if not IMBA_Line_Data[C:GetName()] then |
||
32 | IMBA_Line_Data[C:GetName()]={}; |
||
33 | end |
||
34 | |||
35 | T=nil; |
||
36 | |||
37 | for k,v in IMBA_Lines[C:GetName()] do |
||
38 | if not v:IsShown() and not T then |
||
39 | T=v; |
||
40 | lineNum=k; |
||
41 | T:Show(); |
||
42 | end |
||
43 | end |
||
44 | |||
45 | if not T then |
||
46 | T=C:CreateTexture(C:GetName().."_Line"..(getn(IMBA_Lines[C:GetName()])+1), "ARTWORK"); |
||
47 | --T:SetTexture("Interface\\AddOns\\Whiteboard\\textures\\line"); |
||
48 | T:SetTexture("Interface\\AddOns\\IMBA\\textures\\line"); |
||
49 | tinsert(IMBA_Lines[C:GetName()],T); |
||
50 | tinsert(IMBA_Line_Data[C:GetName()],{sx,sy,ex,ey,w,{color[1],color[2],color[3],color[4]}}); |
||
51 | else |
||
52 | IMBA_Line_Data[C:GetName()][lineNum]={sx,sy,ex,ey,w,{color[1],color[2],color[3],color[4]}}; |
||
53 | end |
||
54 | |||
55 | T:SetVertexColor(color[1],color[2],color[3],color[4]); |
||
56 | -- Determine dimensions and center point of line |
||
57 | local dx,dy = ex - sx, ey - sy; |
||
58 | local cx,cy = (sx + ex) / 2, (sy + ey) / 2; |
||
59 | |||
60 | -- Normalize direction if necessary |
||
61 | if (dx < 0) then |
||
62 | dx,dy = -dx,-dy; |
||
63 | end |
||
64 | |||
65 | -- Calculate actual length of line |
||
66 | local l = sqrt((dx * dx) + (dy * dy)); |
||
67 | |||
68 | -- Quick escape if it's zero length |
||
69 | if (l == 0) then |
||
70 | T:SetTexCoord(0,0,0,0,0,0,0,0); |
||
71 | T:SetPoint("BOTTOMLEFT", C, relPoint, cx,cy); |
||
72 | T:SetPoint("TOPRIGHT", C, relPoint, cx,cy); |
||
73 | return; |
||
74 | end |
||
75 | |||
76 | -- Sin and Cosine of rotation, and combination (for later) |
||
77 | local s,c = -dy / l, dx / l; |
||
78 | local sc = s * c; |
||
79 | |||
80 | -- Calculate bounding box size and texture coordinates |
||
81 | local Bwid, Bhgt, BLx, BLy, TLx, TLy, TRx, TRy, BRx, BRy; |
||
82 | if (dy >= 0) then |
||
83 | Bwid = ((l * c) - (w * s)) * TAXIROUTE_LINEFACTOR_2; |
||
84 | Bhgt = ((w * c) - (l * s)) * TAXIROUTE_LINEFACTOR_2; |
||
85 | if w>64 then |
||
86 | Bwid=Bwid*1.05; |
||
87 | Bhgt=Bhgt*1.05; |
||
88 | end |
||
89 | if w>128 then |
||
90 | Bwid=Bwid*1.05; |
||
91 | Bhgt=Bhgt*1.05; |
||
92 | end |
||
93 | BLx, BLy, BRy = (w / l) * sc, s * s, (l / w) * sc; |
||
94 | BRx, TLx, TLy, TRx = 1 - BLy, BLy, 1 - BRy, 1 - BLx; |
||
95 | TRy = BRx; |
||
96 | else |
||
97 | Bwid = ((l * c) + (w * s)) * TAXIROUTE_LINEFACTOR_2; |
||
98 | Bhgt = ((w * c) + (l * s)) * TAXIROUTE_LINEFACTOR_2; |
||
99 | if w>64 then |
||
100 | Bwid=Bwid*1.05; |
||
101 | Bhgt=Bhgt*1.05; |
||
102 | end |
||
103 | BLx, BLy, BRx = s * s, -(l / w) * sc, 1 + (w / l) * sc; |
||
104 | BRy, TLx, TLy, TRy = BLx, 1 - BRx, 1 - BLx, 1 - BLy; |
||
105 | TRx = TLy; |
||
106 | end |
||
107 | |||
108 | -- Set texture coordinates and anchors |
||
109 | T:ClearAllPoints(); |
||
110 | T:SetTexCoord(TLx, TLy, BLx, BLy, TRx, TRy, BRx, BRy); |
||
111 | T:SetPoint("BOTTOMLEFT", C, relPoint, cx - Bwid, cy - Bhgt); |
||
112 | T:SetPoint("TOPRIGHT", C, relPoint, cx + Bwid, cy + Bhgt); |
||
113 | |||
114 | return T:GetName(); |
||
115 | end |
||
116 | |||
117 | function IMBA_ClearLines(C) |
||
118 | if not IMBA_Lines then |
||
119 | IMBA_Lines={}; |
||
120 | end |
||
121 | if not IMBA_Lines[C:GetName()] then |
||
122 | IMBA_Lines[C:GetName()]={}; |
||
123 | end |
||
124 | for k,v in IMBA_Lines[C:GetName()] do |
||
125 | v:Hide(); |
||
126 | end |
||
127 | |||
128 | end |
||
129 | |||
130 | function IMBA_EraseLines(C,x,y,r) |
||
131 | local Dist, xDiff, yDiff; |
||
132 | r=r*r; |
||
133 | if not IMBA_Lines[C:GetName()] then |
||
134 | IMBA_Lines[C:GetName()]={}; |
||
135 | IMBA_Line_Data[C:GetName()]={}; |
||
136 | end |
||
137 | for k,v in IMBA_Line_Data[C:GetName()] do |
||
138 | if IMBA_Lines[C:GetName()][k]:IsShown() then |
||
139 | xDiff=x-v[1]; |
||
140 | yDiff=y-v[2]; |
||
141 | Dist=xDiff*xDiff+yDiff*yDiff |
||
142 | if Dist<r then |
||
143 | IMBA_Lines[C:GetName()][k]:Hide(); |
||
144 | else |
||
145 | xDiff=x-v[3]; |
||
146 | yDiff=y-v[4]; |
||
147 | Dist=xDiff*xDiff+yDiff*yDiff |
||
148 | if Dist<r then |
||
149 | IMBA_Lines[C:GetName()][k]:Hide(); |
||
150 | end |
||
151 | end |
||
152 | end |
||
153 | end |
||
154 | end |
||
155 | |||
156 | function IMBA_CompareColors(C1,C2) |
||
157 | if getn(C1)~=getn(C2) then |
||
158 | return false |
||
159 | end |
||
160 | for i=1,getn(C1),1 do |
||
161 | if C1[i]~=C2[i] then |
||
162 | return false |
||
163 | end |
||
164 | end |
||
165 | return true |
||
166 | end |
||
167 | |||
168 | function IMBA_CreateSaveImage(C) |
||
169 | local ImageStrokes={}; |
||
170 | if not IMBA_Line_Data then |
||
171 | return nil |
||
172 | end |
||
173 | |||
174 | if not IMBA_Line_Data[C:GetName()] then |
||
175 | return nil; |
||
176 | end |
||
177 | |||
178 | for k,v in IMBA_Line_Data[C:GetName()] do |
||
179 | local AddedLine |
||
180 | AddedLine=false; |
||
181 | if IMBA_Lines[C:GetName()][k]:IsShown() then |
||
182 | for k2, Stroke in ImageStrokes do |
||
183 | if not AddedLine and IMBA_CompareColors(Stroke.Color,v[IMBA_LINE_DATA_COLOR]) and (Stroke.Width==v[IMBA_LINE_DATA_WIDTH]) then |
||
184 | if (v[IMBA_LINE_DATA_SX]==Stroke.x[getn(Stroke.x)]) and (v[IMBA_LINE_DATA_SY]==Stroke.y[getn(Stroke.y)]) and not ((v[IMBA_LINE_DATA_SX]==v[IMBA_LINE_DATA_EX]) and (v[IMBA_LINE_DATA_SY]==v[IMBA_LINE_DATA_EY])) then |
||
185 | |||
186 | tinsert(Stroke.x,v[IMBA_LINE_DATA_EX]) |
||
187 | tinsert(Stroke.y,v[IMBA_LINE_DATA_EY]) |
||
188 | AddedLine=true; |
||
189 | end |
||
190 | end |
||
191 | end |
||
192 | |||
193 | if not AddedLine then |
||
194 | tinsert(ImageStrokes,{Color=v[IMBA_LINE_DATA_COLOR],Width=v[IMBA_LINE_DATA_WIDTH],x={v[IMBA_LINE_DATA_SX],v[IMBA_LINE_DATA_EX]},y={v[IMBA_LINE_DATA_SY],v[IMBA_LINE_DATA_EY]}}); |
||
195 | end |
||
196 | end |
||
197 | end |
||
198 | |||
199 | return ImageStrokes |
||
200 | end |
||
201 | |||
202 | function IMBA_DrawSavedImage(C,Image) |
||
203 | if not Image then |
||
204 | return |
||
205 | end |
||
206 | for k, Stroke in Image do |
||
207 | local lines; |
||
208 | lines=getn(Stroke.x)-1; |
||
209 | for i=1,lines,1 do |
||
210 | IMBA_DrawLine(C, Stroke.x[i], Stroke.y[i], Stroke.x[i+1], Stroke.y[i+1], Stroke.Width, Stroke.Color) |
||
211 | end |
||
212 | end |
||
213 | end |
||
214 | |||
215 | local IMBA_Stroke={} |
||
216 | |||
217 | function IMBA_EndStroke(canvas) |
||
218 | local canvasN=canvas:GetName(); |
||
219 | if IMBA_Stroke[canvasN] then |
||
220 | local Message,num; |
||
221 | num=getn(IMBA_Stroke[canvasN].vert); |
||
222 | |||
223 | Message=string.format("DRAWSTROKE %.2f %.2f %.2f %.2f %.1f %d ",IMBA_Stroke[canvasN].color[1],IMBA_Stroke[canvasN].color[2],IMBA_Stroke[canvasN].color[3],IMBA_Stroke[canvasN].color[4],IMBA_Stroke[canvasN].width,num) |
||
224 | for i=1,num do |
||
225 | Message=Message..string.format("a %.1f %.1f ",IMBA_Stroke[canvasN].vert[i][1],IMBA_Stroke[canvasN].vert[i][2]); |
||
226 | end |
||
227 | if canvas:GetName()=="Whiteboard" then |
||
228 | IMBA_AddMsg("IMBA_LINES_"..canvasN,Message,"GUILD"); |
||
229 | else |
||
230 | if IMBA_IsPlayerALeader() then |
||
231 | if GetNumRaidMembers()>0 then |
||
232 | IMBA_AddMsg("IMBA_LINES_"..canvasN,Message,"RAID"); |
||
233 | else |
||
234 | IMBA_AddMsg("IMBA_LINES_"..canvasN,Message,"PARTY"); |
||
235 | end |
||
236 | end |
||
237 | end |
||
238 | IMBA_Stroke[canvasN]=nil |
||
239 | end |
||
240 | end |
||
241 | |||
242 | function IMBA_AddToStroke(canvas, x,y) |
||
243 | tinsert(IMBA_Stroke[canvas:GetName()].vert,{x,y}) |
||
244 | if getn(IMBA_Stroke[canvas:GetName()].vert)>=10 then |
||
245 | IMBA_EndStroke(canvas) |
||
246 | end |
||
247 | end |
||
248 | |||
249 | function IMBA_StartStroke(canvas,color,width,sx,sy,ex,ey) |
||
250 | local canvasN=canvas:GetName(); |
||
251 | IMBA_Stroke[canvasN]={} |
||
252 | IMBA_Stroke[canvasN].color=color |
||
253 | IMBA_Stroke[canvasN].width=width |
||
254 | IMBA_Stroke[canvasN].vert={}; |
||
255 | tinsert(IMBA_Stroke[canvasN].vert,{sx,sy}) |
||
256 | tinsert(IMBA_Stroke[canvasN].vert,{ex,ey}) |
||
257 | end |
||
258 | |||
259 | function IMBA_StrokeStarted(canvas) |
||
260 | if IMBA_Stroke[canvas:GetName()] then |
||
261 | return true |
||
262 | end |
||
263 | return false |
||
264 | end |
||
265 | |||
266 | function IMBA_SendSavedImage(C,Image) |
||
267 | if IMBA_IsPlayerALeader() or (C:GetName()=="Whiteboard") then |
||
268 | if C:GetName()=="Whiteboard" then |
||
269 | IMBA_AddMsg("IMBA_LINES_"..canvasN,Message,"GUILD"); |
||
270 | else |
||
271 | if GetNumRaidMembers()>0 then |
||
272 | IMBA_AddMsg("IMBA_LINES_"..C:GetName(),"ERASEALL","RAID"); |
||
273 | else |
||
274 | IMBA_AddMsg("IMBA_LINES_"..C:GetName(),"ERASEALL","PARTY"); |
||
275 | end |
||
276 | end |
||
277 | for k, Stroke in Image do |
||
278 | local lines; |
||
279 | lines=getn(Stroke.x)-1; |
||
280 | for i=1,lines,1 do |
||
281 | if IMBA_StrokeStarted(C) then |
||
282 | IMBA_AddToStroke(C,Stroke.x[i+1], Stroke.y[i+1]); |
||
283 | else |
||
284 | IMBA_StartStroke(C,Stroke.Color,Stroke.Width,Stroke.x[i], Stroke.y[i], Stroke.x[i+1], Stroke.y[i+1]) |
||
285 | end |
||
286 | IMBA_EndStroke(C); |
||
287 | end |
||
288 | end |
||
289 | end |
||
290 | end |
||
291 | |||
292 | function IMBA_LineMsgHandler(canvas) |
||
293 | if arg1=="IMBA_LINES_"..canvas:GetName() and arg4~=UnitName("player") then |
||
294 | |||
295 | for sx, sy, ex, ey, r, g, b, a in string.gfind(arg2, "DRAWLINE (%d+.?%d*) (%d+.?%d*) (%d+.?%d*) (%d+.?%d*) (%d+.?%d*) (%d+.?%d*) (%d+.?%d*) (%d+.?%d*)") do |
||
296 | IMBA_DrawLine(canvas,sx,sy,ex,ey,32,{r,g,b,a}) |
||
297 | end |
||
298 | |||
299 | for x,y in string.gfind(arg2, "ERASE (%d+.?%d*) (%d+.?%d*)") do |
||
300 | IMBA_EraseLines(canvas,x,y,12); |
||
301 | end |
||
302 | |||
303 | if string.find(arg2,"DRAWSTROKE") then |
||
304 | local _,_, r, g, b, a, w, n, px, py, rest = string.find(arg2, "DRAWSTROKE (%d+.?%d*) (%d+.?%d*) (%d+.?%d*) (%d+.?%d*) (%d+.?%d*) (%d+) a (%d+.?%d*) (%d+.?%d*) (.*)"); |
||
305 | local x, y |
||
306 | for x, y in string.gfind(rest,"a (%d+.?%d*) (%d+.?%d*)") do |
||
307 | IMBA_DrawLine(canvas,px,py,x,y,tonumber(w),{r,g,b,a}); |
||
308 | px=x; |
||
309 | py=y; |
||
310 | end |
||
311 | end |
||
312 | |||
313 | if string.find(arg2,"ERASEALL") then |
||
314 | IMBA_ClearLines(canvas); |
||
315 | end |
||
316 | end |
||
317 | end |