Added MinimapShapes conversion table
(cat) |
(Added MinimapShapes conversion table) |
||
| Line 20: | Line 20: | ||
This is currently used by [http://www.wowace.com/wiki/FuBarPlugin-2.0 FuBarPlugin-2.0] to determine position of minimap buttons.<br> | This is currently used by [http://www.wowace.com/wiki/FuBarPlugin-2.0 FuBarPlugin-2.0] to determine position of minimap buttons.<br> | ||
This is currently used by [http://www.wowace.com/wiki/Cartographer/Notes Cartographer_Notes] to determine edge position of notes on the minimap. | This is currently used by [http://www.wowace.com/wiki/Cartographer/Notes Cartographer_Notes] to determine edge position of notes on the minimap.<br> | ||
This is currently used by [[MobileMinimapButtons]] to determine position of draggable minimap buttons.<br> | |||
This is the code currently used by FuBarPlugin-2.0 to determine position on the edge of a minimap: | This is the code currently used by FuBarPlugin-2.0 to determine position on the edge of a minimap: | ||
| Line 94: | Line 95: | ||
end | end | ||
frame:SetPoint("CENTER", Minimap, "CENTER", x, y) | frame:SetPoint("CENTER", Minimap, "CENTER", x, y) | ||
This is the a conversion table used by [[MobileMinimapButtons]] to shorten the previous code, add radius functionality and make the square corner rounding more flexible: | |||
local MinimapShapes = { | |||
-- quadrant booleans (same order as SetTexCoord) | |||
-- {upper-left, lower-left, upper-right, lower-right} | |||
-- true = rounded, false = squared | |||
["ROUND"] = {true, true, true, true}, | |||
["SQUARE"] = {false, false, false, false}, | |||
["CORNER-TOPLEFT"] = {true, false, false, false}, | |||
["CORNER-TOPRIGHT"] = {false, false, true, false}, | |||
["CORNER-BOTTOMLEFT"] = {false, true, false, false}, | |||
["CORNER-BOTTOMRIGHT"] = {false, false, false, true}, | |||
["SIDE-LEFT"] = {true, true, false, false}, | |||
["SIDE-RIGHT"] = {false, false, true, true}, | |||
["SIDE-TOP"] = {true, false, true, false}, | |||
["SIDE-BOTTOM"] = {false, true, false, true}, | |||
["TRICORNER-TOPLEFT"] = {true, true, true, false}, | |||
["TRICORNER-TOPRIGHT"] = {true, false, true, true}, | |||
["TRICORNER-BOTTOMLEFT"] = {true, true, false, true}, | |||
["TRICORNER-BOTTOMRIGHT"] = {false, true, true, true}, | |||
} | |||
function UpdateButtonPosition(position, radius, rounding) | |||
if not radius then rounding = 80 end | |||
if not rounding then rounding = 10 end | |||
local angle = math.rad(position) -- determine position on your own | |||
local x = math.sin(angle) | |||
local y = math.cos(angle) | |||
local q = 1; | |||
if x < 0 then | |||
q = q + 1; -- lower | |||
end | |||
if y > 0 then | |||
q = q + 2; -- right | |||
end | |||
local minimapShape = GetMinimapShape and GetMinimapShape() or "ROUND" | |||
local quadTable = MinimapShapes[minimapShape]; | |||
if quadTable[q] then | |||
x = x*radius; | |||
y = y*radius; | |||
else | |||
local diagRadius = math.sqrt(2*(radius)^2)-rounding | |||
x = math.max(-radius, math.min(x*diagRadius, radius)) | |||
y = math.max(-radius, math.min(y*diagRadius, radius)) | |||
end | |||
frame:SetPoint("CENTER", Minimap, "CENTER", x, y) | |||
end | |||
[[Category: World of Warcraft API]] | [[Category: World of Warcraft API]] | ||