WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Create Frame at the Cursor (https://www.wowinterface.com/forums/showthread.php?t=42167)

Sniffles 12-18-11 05:12 PM

Create Frame at the Cursor
 
Hello,

I'm working atm. on an AddOn and I want to create Frames at the cursor. Does someone know, how could I do it?

I already tried:

Code:

function ns.round(float)
        return floor(float+0.5)
end

function ns.shwcrd(num)
        return ns.round(num * 100)
end

function ns:CreateButton(point ,offx, yoff)
        local button = CreateFrame("Button", nil, WorldMapButton)
        button:SetSize(15, 15)
        button:SetBackdrop(backdrop)
        button:SetBackdropColor(.0, .0, .0)
        button:SetBackdropBorderColor(.125, .125, .125)
        button:SetPoint(point, offx, yoff)
       
        button:SetScript("OnEnter", ns.OnEnter)
        button:SetScript("OnLeave", ns.OnLeave)
       
        return button
end


local scale = WorldMapDetailFrame:GetEffectiveScale()
local width = WorldMapDetailFrame:GetWidth()
local height = WorldMapDetailFrame:GetHeight()
local centerX, centerY = WorldMapDetailFrame:GetCenter()
local x, y = GetCursorPosition()
       
local point, relativeTo, relativePoint, xOfs, yOfs = GetMouseFocus():GetPoint()

local adjX = (x / scale - (centerX - (width/2))) / width
local adjY = (centerY + (height/2) - y / scale) / height

ns:CreateButton(point, ns.shwcrd(x), ns.shwcrd(y))
notice.text:SetText(ns.shwcrd(x).." / "..ns.shwcrd(y))

But it doesn't work at all. :S

Seerah 12-18-11 06:02 PM

How doesn't it work?

I would think just setting the frame at the coordinates returned by GetCursorPosition() would be sufficient.

What exactly are you trying to accomplish?


/edit: wait a second, you're only checking the cursor location once.

SDPhantom 12-19-11 03:46 AM

You need your RelPoint to the be "BOTTOMLEFT" of nil, which is the screen itself, otherwise your buttons are likely to draw offscreen. Also, the offsets seem to be multiplied by 100 which would throw the buttons offscreen too.


Here's a snip of a cursor-target feature of a HUD addon I was working on that managed the position of the targeting reticule.
Code:

local scale,x,y=frame:GetEffectiveScale(),GetCursorPosition();
frame:SetPoint("CENTER",nil,"BOTTOMLEFT",x/scale,y/scale);


Sniffles 12-19-11 07:07 AM

Quote:

Originally Posted by SDPhantom (Post 249793)
You need your RelPoint to the be "BOTTOMLEFT" of nil, which is the screen itself, otherwise your buttons are likely to draw offscreen. Also, the offsets seem to be multiplied by 100 which would throw the buttons offscreen too.


Here's a snip of a cursor-target feature of a HUD addon I was working on that managed the position of the targeting reticule.
Code:

local scale,x,y=frame:GetEffectiveScale(),GetCursorPosition();
frame:SetPoint("CENTER",nil,"BOTTOMLEFT",x/scale,y/scale);


Works perfect!!
Thank you very much SDPhantom. :)


All times are GMT -6. The time now is 09:34 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI