Thread Tools Display Modes
12-18-11, 05:12 PM   #1
Sniffles
A Black Drake
 
Sniffles's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2010
Posts: 86
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
__________________
Hi!
  Reply With Quote
12-18-11, 06:02 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
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.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
12-19-11, 03:46 AM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,327
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);
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 12-19-11 at 03:50 AM.
  Reply With Quote
12-19-11, 07:07 AM   #4
Sniffles
A Black Drake
 
Sniffles's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2010
Posts: 86
Originally Posted by SDPhantom View Post
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.
__________________
Hi!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Create Frame at the Cursor


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off