vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | -- Name: TinyTip |
||
3 | -- Author: Thrae of Maelstrom (aka "Matthew Carras") |
||
4 | -- Release Date: 6-25-06 |
||
5 | -- |
||
6 | -- This file handles the position and anchoring of the |
||
7 | -- tooltip. If you don't care about these options, then |
||
8 | -- this file can safely removed from the TOC. |
||
9 | --]] |
||
10 | |||
11 | local _G = getfenv(0) |
||
12 | local UIParent,GameTooltip = _G.UIParent, _G.GameTooltip |
||
13 | local gtClearPts, gtSetOwner, gtSetPt = GameTooltip.ClearAllPoints, GameTooltip.SetOwner, GameTooltip.SetPoint |
||
14 | local tClearPts, tSetOwner, tSetPt = gtClearPts, gtSetOwner, gtSetPt |
||
15 | local fSetScript, fGetScale, fGetAlpha, fGetCenter, fGetLeft, fGetRight, fGetTop, fGetBottom, fGetWidth, fGetHeight = UIParent.SetScript, UIParent.GetScale, UIParent.GetAlpha, UIParent.GetCenter, UIParent.GetLeft, UIParent.GetRight, UIParent.GetTop, UIParent.GetBottom, UIParent.GetWidth, UIParent.GetHeight |
||
16 | local db,EventFrame |
||
17 | |||
18 | local acehook |
||
19 | |||
20 | local unitMouseover |
||
21 | |||
22 | _G.TinyTipAnchorExists = true |
||
23 | |||
24 | function TinyTipAnchor_ResetReferences(ClearPts, SetPt, SetOwner) |
||
25 | tClearPts, tSetPt, tSetOwner = ClearPts, SetPt, SetOwner |
||
26 | end |
||
27 | |||
28 | -- blatantly stolen from PerfecEventFrame by cladhaire! |
||
29 | -- Used for UAnchor == "STICKY" |
||
30 | local function SmartSetOwner(owner, setX, setY, tooltip) |
||
31 | if (not owner) then owner = UIParent end |
||
32 | if (not tooltip) then tooltip = this end |
||
33 | if (not setX) then setX = 0 end |
||
34 | if (not setY) then setY = 0 end |
||
35 | |||
36 | local x,y = fGetCenter(owner) |
||
37 | local left = fGetLeft(owner) |
||
38 | local right = fGetRight(owner) |
||
39 | local top = fGetTop(owner) |
||
40 | local bottom = fGetBottom(owner) |
||
41 | local screenWidth = _G.GetScreenWidth() |
||
42 | local screenHeight = _G.GetScreenHeight() |
||
43 | local scale = fGetScale(owner) |
||
44 | if (x~=nil and y~=nil and left~=nil and |
||
45 | right~=nil and top~=nil and bottom~=nil |
||
46 | and screenWidth>0 and screenHeight>0) then |
||
47 | setX = setX * scale |
||
48 | setY = setY * scale |
||
49 | x = x * scale |
||
50 | y = y * scale |
||
51 | left = left * scale |
||
52 | right = right * scale |
||
53 | width = right - left |
||
54 | top = top * scale |
||
55 | bottom = bottom * scale |
||
56 | local anchorPoint |
||
57 | |||
58 | if (y <= (screenHeight * (1/2))) then |
||
59 | top = top + setY |
||
60 | anchorPoint = "TOP" |
||
61 | if (top < 0) then |
||
62 | setY = setY - top |
||
63 | end |
||
64 | else |
||
65 | setY = -setY |
||
66 | bottom = bottom + setY |
||
67 | anchorPoint = "BOTTOM" |
||
68 | if (bottom > screenHeight) then |
||
69 | setY = setY + (screenHeight - bottom) |
||
70 | end |
||
71 | end |
||
72 | |||
73 | if (x <= (screenWidth * (1/2))) then |
||
74 | left = left + setX |
||
75 | if (anchorPoint == "BOTTOM") then |
||
76 | anchorPoint = anchorPoint.."RIGHT" |
||
77 | setX = setX - width |
||
78 | if (left < 0) then |
||
79 | setX = setX - left |
||
80 | end |
||
81 | else |
||
82 | anchorPoint = anchorPoint.."LEFT" |
||
83 | if (left < 0) then |
||
84 | setX = setX - left |
||
85 | end |
||
86 | end |
||
87 | else |
||
88 | setX = -setX |
||
89 | right = right + setX |
||
90 | if (anchorPoint == "BOTTOM") then |
||
91 | anchorPoint = anchorPoint.."LEFT" |
||
92 | setX = setX + width |
||
93 | if (right > screenWidth) then |
||
94 | setX = setX - (right - screenWidth) |
||
95 | end |
||
96 | else |
||
97 | anchorPoint = anchorPoint.."RIGHT" |
||
98 | if (right > screenWidth) then |
||
99 | setX = setX + (screenWidth - right) |
||
100 | end |
||
101 | end |
||
102 | end |
||
103 | |||
104 | scale = fGetScale(tooltip) |
||
105 | if (scale) then |
||
106 | setX = setX / scale |
||
107 | setY = setY / scale |
||
108 | end |
||
109 | |||
110 | tClearPts(tooltip) |
||
111 | tSetOwner(tooltip, owner, "ANCHOR_"..anchorPoint, setX, setY) |
||
112 | end |
||
113 | end |
||
114 | |||
115 | -- Used to stick GameTooltip to the cursor with offsets. |
||
116 | local x,y,uiscale, tscale,utooltip |
||
117 | local getcpos = _G.GetCursorPosition |
||
118 | local function OnUpdate() |
||
119 | if unitMouseover and not _G.UnitExists("mouseover") then |
||
120 | if db["Fade"] ~= 1 or fGetAlpha(GameTooltip) < 0.1 then |
||
121 | if this.tooltip == _G.TinyTipExtras_Tooltip then this.tooltip:Hide() end |
||
122 | fSetScript(this, "OnUpdate", nil) |
||
123 | return |
||
124 | end |
||
125 | end |
||
126 | x,y = getcpos() |
||
127 | utooltip = this.tooltip |
||
128 | uiscale,tscale = fGetScale(UIParent), fGetScale(utooltip) |
||
129 | x,y = (x + (utooltip.OffX or 0)) / uiscale / tscale, (y + (utooltip.OffY or 0)) / uiscale / tscale |
||
130 | tClearPts(utooltip) |
||
131 | tSetPt(utooltip, "BOTTOM", UIParent, "BOTTOMLEFT", x, y) |
||
132 | end |
||
133 | |||
134 | function TinyTipAnchor_AlwaysAnchor() |
||
135 | tClearPts(GameTooltip) |
||
136 | tSetPt(GameTooltip, db["FAnchor"] or "BOTTOMRIGHT", UIParent, db["FAnchor"] or "BOTTOMRIGHT", (db["FOffX"] or 0) - ((not db["FAnchor"] and (_G.CONTAINER_OFFSET_X - 13)) or 0), (db["FOffY"] or 0) + ((not db["FAnchor"] and _G.CONTAINER_OFFSET_Y) or 0)) |
||
137 | end |
||
138 | |||
139 | _G.TinyTipAnchor_Original_GameTooltip_SetDefaultAnchor = nil |
||
140 | function TinyTipAnchor_SetDefaultAnchor(tooltip,owner,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10) |
||
141 | tooltip.owner = owner |
||
142 | if _G.TinyTipAnchor_Original_GameTooltip_SetDefaultAnchor and tooltip ~= _G.TinyTipExtras_Tooltip then |
||
143 | _G.TinyTipAnchor_Original_GameTooltip_SetDefaultAnchor(tooltip,owner,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10) |
||
144 | end |
||
145 | if db and EventFrame and (db["AnchorAll"] or (tooltip == GameTooltip or tooltip == _G.TinyTipExtras_Tooltip) ) then |
||
146 | if db["Fade"] == 2 then |
||
147 | fSetScript(EventFrame, "OnUpdate", _G.TinyTip_SlimOnUpdate) |
||
148 | else |
||
149 | fSetScript(EventFrame, "OnUpdate", nil) |
||
150 | end |
||
151 | if tooltip == _G.TinyTipExtras_Tooltip then |
||
152 | if db["ETAnchor"] or db["ETOffX"] or db["ETOffY"] then |
||
153 | gtClearPts(GameTooltip) |
||
154 | gtSetPt(GameTooltip, db["ETAnchor"] or "BOTTOMRIGHT", UIParent, db["ETAnchor"] or "BOTTOMRIGHT", (db["ETOffX"] or 0) - _G.CONTAINER_OFFSET_X - 13, (db["ETOffY"] or 0) + _G.CONTAINER_OFFSET_Y) |
||
155 | end |
||
156 | tClearPts(tooltip) |
||
157 | tSetPt(tooltip, "RIGHT", GameTooltip, "LEFT", -5 / fGetScale(UIParent) , 0 ) |
||
158 | end |
||
159 | if owner ~= UIParent then |
||
160 | if db["FAnchor"] or db["FOffX"] or db["FOffY"] then |
||
161 | if db["FAnchor"] == "CURSOR" then |
||
162 | if db["Fade"] ~= 1 and not db["ExtraTooltip"] then |
||
163 | tSetOwner(tooltip, owner, "ANCHOR_CURSOR") |
||
164 | else |
||
165 | tSetOwner(tooltip, owner, "ANCHOR_NONE") |
||
166 | end |
||
167 | if db["FOffX"] or db["FOffY"] or db["Fade"] == 1 or db["ExtraTooltip"] then |
||
168 | tooltip.OffX, tooltip.OffY,unitMouseover = db["FOffX"] or 0, db["FOffY"] or 0, nil |
||
169 | fSetScript(EventFrame, "OnUpdate", OnUpdate) |
||
170 | end |
||
171 | elseif db["FAnchor"] == "STICKY" then |
||
172 | SmartSetOwner(owner, db["FOffX"], db["FOffY"], tooltip) |
||
173 | else |
||
174 | tSetOwner(tooltip, owner, "ANCHOR_NONE") |
||
175 | tClearPts(tooltip) |
||
176 | tSetPt(tooltip, db["FAnchor"] or "BOTTOMRIGHT", UIParent, db["FAnchor"] or "BOTTOMRIGHT", (db["FOffX"] or 0) - ((not db["FAnchor"] and (_G.CONTAINER_OFFSET_X - 13)) or 0), (db["FOffY"] or 0) + ((not db["FAnchor"] and _G.CONTAINER_OFFSET_Y) or 0)) |
||
177 | end |
||
178 | end |
||
179 | else |
||
180 | if tooltip == GameTooltip and db["ExtraTooltip"] then return end |
||
181 | if db["MAnchor"] ~= "GAMEDEFAULT" or db["MOffX"] or db["MOffY"] then |
||
182 | if not db["MAnchor"] then |
||
183 | if db["Fade"] ~= 1 and not db["ExtraTooltip"] then |
||
184 | tSetOwner(tooltip, owner, "ANCHOR_CURSOR") |
||
185 | else |
||
186 | tSetOwner(tooltip, owner, "ANCHOR_NONE") |
||
187 | end |
||
188 | if db["MOffX"] or db["MOffY"] or db["Fade"] == 1 or db["ExtraTooltip"] then |
||
189 | tooltip.OffX, tooltip.OffY,unitMouseover = db["MOffX"] or 0, db["MOffY"] or 0, true |
||
190 | fSetScript(EventFrame, "OnUpdate", OnUpdate) |
||
191 | end |
||
192 | else |
||
193 | tSetOwner(tooltip, owner, "ANCHOR_NONE") |
||
194 | tClearPts(tooltip) |
||
195 | tSetPt(tooltip, |
||
196 | (db["MAnchor"] ~= "GAMEDEFAULT" and db["MAnchor"]) or "BOTTOMRIGHT", |
||
197 | UIParent, |
||
198 | (db["MAnchor"] ~= "GAMEDEFAULT" and db["MAnchor"]) or "BOTTOMRIGHT", |
||
199 | (db["MOffX"] or 0) - ((db["MAnchor"] == "GAMEDEFAULT" and (_G.CONTAINER_OFFSET_X - 13)) or 0), |
||
200 | (db["MOffY"] or 0) + ((db["MAnchor"] == "GAMEDEFAULT" and _G.CONTAINER_OFFSET_Y) or 0)) |
||
201 | end |
||
202 | end |
||
203 | end |
||
204 | end |
||
205 | end |
||
206 | |||
207 | function TinyTipAnchor_Hook(_acehook) |
||
208 | acehook = _acehook |
||
209 | if acehook and not acehook:IsHooked("GameTooltip_SetDefaultAnchor") then |
||
210 | acehook:Hook("GameTooltip_SetDefaultAnchor", _G.TinyTipAnchor_SetDefaultAnchor) |
||
211 | _G.TinyTipAnchor_Original_GameTooltip_SetDefaultAnchor = acehook.hooks["GameTooltip_SetDefaultAnchor"].orig |
||
212 | end |
||
213 | end |
||
214 | |||
215 | function TinyTipAnchor_SetLocals(_db, _EventFrame,_acehook) |
||
216 | db, EventFrame,acehook = _db,_EventFrame,_acehook |
||
217 | TinyTipAnchor_SetLocals = nil |
||
218 | end |
||
219 |