er edit: oops, misread from what angle. 99.9% use a slider in options. I personally prefer dragging the button itself.
This is a way to make the icon draggable:
1. Add a small frame that exists to start/stop OnUpdates when dragging:
<Frame name="MyModIconDraggingFrame" hidden="true">
<Scripts>
<OnUpdate>
MyMod_DragMinimapIcon()
</OnUpdate>
</Scripts>
</Frame>
2. Add these to the <Scripts> of the minimap icon's frame (this=MyModIconFrame for example):
<OnLoad>
this:RegisterForDrag("LeftButton")
</OnLoad>
<OnDragStart>
this:LockHighlight()
this:StartMoving() -- only to register in layout-cache.txt
this:StopMovingOrSizing()
MyModIconDraggingFrame:Show()
</OnDragStart>
<OnDragStop>
MyModIconDraggingFrame:Hide()
this:UnlockHighlight()
</OnDragStop>
3. Add the OnUpdate function in the lua:
function MyMod_DragMinimapIcon()
local xpos,ypos = GetCursorPosition()
local xmin,ymin = Minimap:GetLeft(), Minimap:GetBottom()
xpos = xmin-xpos/UIParent:GetScale()+70
ypos = ypos/UIParent:GetScale()-ymin-70
local angle = math.deg(math.atan2(ypos,xpos))
MyModIconFrame:SetPoint("TOPLEFT","Minimap","TOPLEFT",52-(80*cos(angle)),(80*sin(angle))-52)
end
--
For the mod makers: No slider to initialize, and nothing to SavedVariable since we let layout-cache.txt keep its place for us.
For the user: no poking around in options. They just grab the button and drag.
|