WoW:USERAPI GetMinimapShape: Difference between revisions
(Add {{userapi}}) |
m (Move page script moved page USERAPI GetMinimapShape to USERAPI GetMinimapShape without leaving a redirect) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{userapi}} | {{userapi}} | ||
GetMinimapShape is a function that is declared by the currently running minimap addon to provide information about what shape it is, in case other addons need to deal with the minimap's borders. | GetMinimapShape is a function that is declared by the currently running minimap addon to provide information about what shape it is, in case other addons need to deal with the minimap's borders. | ||
It takes no arguments and returns one of the following strings: | It takes no arguments and returns one of the following strings: | ||
; "ROUND" : standard shape, round. This is to be assumed if an unknown string is returned or if no string is returned or if GetMinimapShape does not exist. | ; "ROUND" | ||
; "SQUARE" : square shape. | : standard shape, round. This is to be assumed if an unknown string is returned or if no string is returned or if GetMinimapShape does not exist. | ||
; "CORNER-TOPLEFT" : square, but with the top-left corner being round. This would normally be put at the bottom-right of the screen. | ; "SQUARE" | ||
; "CORNER-TOPRIGHT" : square, but with the top-right corner being round. This would normally be put at the bottom-left of the screen. | : square shape. | ||
; "CORNER-BOTTOMLEFT" : square, but with the bottom-left corner being round. This would normally be put at the top-right of the screen. | ; "CORNER-TOPLEFT" | ||
; "CORNER-BOTTOMRIGHT" : square, but with the bottom-right corner being round. This would normally be put at the top-left of the screen. | : square, but with the top-left corner being round. This would normally be put at the bottom-right of the screen. | ||
; "SIDE-LEFT" : square on the right side, rounded on the left side. This would normally be put at the right of the screen. | ; "CORNER-TOPRIGHT" | ||
; "SIDE-RIGHT" : square on the left side, rounded on the right side. This would normally be put at the left of the screen. | : square, but with the top-right corner being round. This would normally be put at the bottom-left of the screen. | ||
; "SIDE-TOP" : square on the bottom side, rounded on the top side. This would normally be put at the bottom of the screen. | ; "CORNER-BOTTOMLEFT" | ||
; "SIDE-BOTTOM" : square on the top side, rounded on the bottom side. This would normally be put at the top of the screen. | : square, but with the bottom-left corner being round. This would normally be put at the top-right of the screen. | ||
; "TRICORNER-TOPLEFT" : round, but with the bottom-right corner being square. This would normally be put at the bottom-right of the screen. | ; "CORNER-BOTTOMRIGHT" | ||
; "TRICORNER-TOPRIGHT" : round, but with the bottom-left corner being square. This would normally be put at the bottom-left of the screen. | : square, but with the bottom-right corner being round. This would normally be put at the top-left of the screen. | ||
; "TRICORNER-BOTTOMLEFT" : round, but with the top-right corner being square. This would normally be put at the top-right of the screen. | ; "SIDE-LEFT" | ||
; "TRICORNER-BOTTOMRIGHT" : round, but with the top-left corner being square. This would normally be put at the top-left of the screen. | : square on the right side, rounded on the left side. This would normally be put at the right of the screen. | ||
; "SIDE-RIGHT" | |||
: square on the left side, rounded on the right side. This would normally be put at the left of the screen. | |||
; "SIDE-TOP" | |||
: square on the bottom side, rounded on the top side. This would normally be put at the bottom of the screen. | |||
; "SIDE-BOTTOM" | |||
: square on the top side, rounded on the bottom side. This would normally be put at the top of the screen. | |||
; "TRICORNER-TOPLEFT" | |||
: round, but with the bottom-right corner being square. This would normally be put at the bottom-right of the screen. | |||
; "TRICORNER-TOPRIGHT" | |||
: round, but with the bottom-left corner being square. This would normally be put at the bottom-left of the screen. | |||
; "TRICORNER-BOTTOMLEFT" | |||
: round, but with the top-right corner being square. This would normally be put at the top-right of the screen. | |||
; "TRICORNER-BOTTOMRIGHT" | |||
: round, but with the top-left corner being square. This would normally be put at the top-left of the screen. | |||
It is possible this function will be called once a frame, so it is recommended not to do anything CPU-intensive in calculating the shape. | It is possible this function will be called once a frame, so it is recommended not to do anything CPU-intensive in calculating the shape. | ||
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.<br> | 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 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 101: | Line 114: | ||
local MinimapShapes = { | local MinimapShapes = { | ||
-- quadrant booleans (same order as SetTexCoord) | -- quadrant booleans (same order as SetTexCoord) | ||
-- { | -- {bottom-right, bottom-left, top-right, top-left} | ||
-- true = rounded, false = squared | -- true = rounded, false = squared | ||
["ROUND"] = {true, true, true, true}, | ["ROUND"] = {true, true, true, true }, | ||
["SQUARE"] = {false, false, false, false}, | ["SQUARE"] = {false, false, false, false}, | ||
["CORNER-TOPLEFT"] = { | ["CORNER-TOPLEFT"] = {false, false, false, true }, | ||
["CORNER-TOPRIGHT"] = {false, false, true, false}, | ["CORNER-TOPRIGHT"] = {false, false, true, false}, | ||
["CORNER-BOTTOMLEFT"] = {false, true, false, false}, | ["CORNER-BOTTOMLEFT"] = {false, true, false, false}, | ||
["CORNER-BOTTOMRIGHT"] = {false, false, false | ["CORNER-BOTTOMRIGHT"] = {true, false, false, false}, | ||
["SIDE-LEFT"] = { | ["SIDE-LEFT"] = {false, true, false, true }, | ||
["SIDE-RIGHT"] = { | ["SIDE-RIGHT"] = {true, false, true, false}, | ||
["SIDE-TOP"] = { | ["SIDE-TOP"] = {false, false, true, true }, | ||
["SIDE-BOTTOM"] = { | ["SIDE-BOTTOM"] = {true, true, false, false}, | ||
["TRICORNER-TOPLEFT"] = {true, true, true | ["TRICORNER-TOPLEFT"] = {false, true, true, true }, | ||
["TRICORNER-TOPRIGHT"] = {true, false, true, true}, | ["TRICORNER-TOPRIGHT"] = {true, false, true, true }, | ||
["TRICORNER-BOTTOMLEFT"] = {true, true, false, true}, | ["TRICORNER-BOTTOMLEFT"] = {true, true, false, true }, | ||
["TRICORNER-BOTTOMRIGHT"] = { | ["TRICORNER-BOTTOMRIGHT"] = {true, true, true, false}, | ||
} | } | ||
function UpdateButtonPosition(position, radius, rounding) | function UpdateButtonPosition(position, radius, rounding) | ||
if not radius then | if not radius then radius = 80 end | ||
if not rounding then rounding = 10 end | if not rounding then rounding = 10 end | ||
local angle = math.rad(position) -- determine position on your own | local angle = math.rad(position) -- determine position on your own | ||
local x = math. | local x, y | ||
local | local cos = math.cos(angle) | ||
local sin = math.sin(angle) | |||
local q = 1; | local q = 1; | ||
if | if cos < 0 then | ||
q = q + 1; -- lower | q = q + 1; -- lower | ||
end | end | ||
if | if sin > 0 then | ||
q = q + 2; -- right | q = q + 2; -- right | ||
end | end | ||
Line 135: | Line 149: | ||
local quadTable = MinimapShapes[minimapShape]; | local quadTable = MinimapShapes[minimapShape]; | ||
if quadTable[q] then | if quadTable[q] then | ||
x = | x = cos*radius; | ||
y = | y = sin*radius; | ||
else | else | ||
local diagRadius = math.sqrt(2*(radius)^2)-rounding | local diagRadius = math.sqrt(2*(radius)^2)-rounding | ||
x = math.max(-radius, math.min( | x = math.max(-radius, math.min(cos*diagRadius, radius)) | ||
y = math.max(-radius, math.min( | y = math.max(-radius, math.min(sin*diagRadius, radius)) | ||
end | end | ||
frame:SetPoint("CENTER", Minimap, "CENTER", x, y) | frame:SetPoint("CENTER", Minimap, "CENTER", x, y) | ||
end | end |
Latest revision as of 04:49, 15 August 2023
← AddOn defined functions < GetMinimapShape
GetMinimapShape is a function that is declared by the currently running minimap addon to provide information about what shape it is, in case other addons need to deal with the minimap's borders.
It takes no arguments and returns one of the following strings:
- "ROUND"
- standard shape, round. This is to be assumed if an unknown string is returned or if no string is returned or if GetMinimapShape does not exist.
- "SQUARE"
- square shape.
- "CORNER-TOPLEFT"
- square, but with the top-left corner being round. This would normally be put at the bottom-right of the screen.
- "CORNER-TOPRIGHT"
- square, but with the top-right corner being round. This would normally be put at the bottom-left of the screen.
- "CORNER-BOTTOMLEFT"
- square, but with the bottom-left corner being round. This would normally be put at the top-right of the screen.
- "CORNER-BOTTOMRIGHT"
- square, but with the bottom-right corner being round. This would normally be put at the top-left of the screen.
- "SIDE-LEFT"
- square on the right side, rounded on the left side. This would normally be put at the right of the screen.
- "SIDE-RIGHT"
- square on the left side, rounded on the right side. This would normally be put at the left of the screen.
- "SIDE-TOP"
- square on the bottom side, rounded on the top side. This would normally be put at the bottom of the screen.
- "SIDE-BOTTOM"
- square on the top side, rounded on the bottom side. This would normally be put at the top of the screen.
- "TRICORNER-TOPLEFT"
- round, but with the bottom-right corner being square. This would normally be put at the bottom-right of the screen.
- "TRICORNER-TOPRIGHT"
- round, but with the bottom-left corner being square. This would normally be put at the bottom-left of the screen.
- "TRICORNER-BOTTOMLEFT"
- round, but with the top-right corner being square. This would normally be put at the top-right of the screen.
- "TRICORNER-BOTTOMRIGHT"
- round, but with the top-left corner being square. This would normally be put at the top-left of the screen.
It is possible this function will be called once a frame, so it is recommended not to do anything CPU-intensive in calculating the shape.
This is currently used by FuBarPlugin-2.0 to determine position of minimap buttons.
This is currently used by Cartographer_Notes to determine edge position of notes on the minimap.
This is currently used by MobileMinimapButtons to determine position of draggable minimap buttons.
This is the code currently used by FuBarPlugin-2.0 to determine position on the edge of a minimap:
local angle = math.rad(position) -- determine position on your own local minimapShape = GetMinimapShape and GetMinimapShape() or "ROUND" local cos = math.cos(angle) local sin = math.sin(angle) local round = true if minimapShape == "ROUND" then -- do nothing elseif minimapShape == "SQUARE" then round = false elseif minimapShape == "CORNER-TOPRIGHT" then if cos < 0 or sin < 0 then round = false end elseif minimapShape == "CORNER-TOPLEFT" then if cos > 0 or sin < 0 then round = false end elseif minimapShape == "CORNER-BOTTOMRIGHT" then if cos < 0 or sin > 0 then round = false end elseif minimapShape == "CORNER-BOTTOMLEFT" then if cos > 0 or sin > 0 then round = false end elseif minimapShape == "SIDE-LEFT" then if cos > 0 then round = false end elseif minimapShape == "SIDE-RIGHT" then if cos < 0 then round = false end elseif minimapShape == "SIDE-TOP" then if sin > 0 then round = false end elseif minimapShape == "SIDE-BOTTOM" then if sin < 0 then round = false end elseif minimapShape == "TRICORNER-TOPRIGHT" then if cos < 0 and sin > 0 then round = false end elseif minimapShape == "TRICORNER-TOPLEFT" then if cos > 0 and sin > 0 then round = false end elseif minimapShape == "TRICORNER-BOTTOMRIGHT" then if cos < 0 and sin < 0 then round = false end elseif minimapShape == "TRICORNER-BOTTOMLEFT" then if cos > 0 and sin < 0 then round = false end end local x,y if round then x = cos * 80 y = sin * 80 else x = 110 * cos y = 110 * sin x = math.max(-82, math.min(x, 84)) y = math.max(-86, math.min(y, 82)) end 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) -- {bottom-right, bottom-left, top-right, top-left} -- true = rounded, false = squared ["ROUND"] = {true, true, true, true }, ["SQUARE"] = {false, false, false, false}, ["CORNER-TOPLEFT"] = {false, false, false, true }, ["CORNER-TOPRIGHT"] = {false, false, true, false}, ["CORNER-BOTTOMLEFT"] = {false, true, false, false}, ["CORNER-BOTTOMRIGHT"] = {true, false, false, false}, ["SIDE-LEFT"] = {false, true, false, true }, ["SIDE-RIGHT"] = {true, false, true, false}, ["SIDE-TOP"] = {false, false, true, true }, ["SIDE-BOTTOM"] = {true, true, false, false}, ["TRICORNER-TOPLEFT"] = {false, true, true, true }, ["TRICORNER-TOPRIGHT"] = {true, false, true, true }, ["TRICORNER-BOTTOMLEFT"] = {true, true, false, true }, ["TRICORNER-BOTTOMRIGHT"] = {true, true, true, false}, } function UpdateButtonPosition(position, radius, rounding) if not radius then radius = 80 end if not rounding then rounding = 10 end local angle = math.rad(position) -- determine position on your own local x, y local cos = math.cos(angle) local sin = math.sin(angle) local q = 1; if cos < 0 then q = q + 1; -- lower end if sin > 0 then q = q + 2; -- right end local minimapShape = GetMinimapShape and GetMinimapShape() or "ROUND" local quadTable = MinimapShapes[minimapShape]; if quadTable[q] then x = cos*radius; y = sin*radius; else local diagRadius = math.sqrt(2*(radius)^2)-rounding x = math.max(-radius, math.min(cos*diagRadius, radius)) y = math.max(-radius, math.min(sin*diagRadius, radius)) end frame:SetPoint("CENTER", Minimap, "CENTER", x, y) end