WoW:USERAPI GetCursorScaledPosition: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
m (New page: {{userfunc}} <!-- Leave this line in! --> <center>'''{{PAGENAME}}''' ''- by Egingell -''</center> Returns the scaled position of the cursor. x, y = {{PAGENAME}}() == ...)
 
Line 1: Line 1:
{{userfunc}} <!-- Leave this line in! -->
{{userfunc}} <!-- Leave this line in! -->
<center>'''{{PAGENAME}}''' ''- by [[User:Egingell|Egingell]] -''</center>
<center>'''{{PAGENAME}}''' ''- by [[User:Egingell|Egingell]] -''</center>


Returns the scaled position of the cursor.
Returns the scaled position of the cursor.
  x, y = {{PAGENAME}}()
  local x, y = {{PAGENAME}}()


== Function Parameters ==
== Function Parameters ==
=== Arguments ===
:nil
=== Returns ===
=== Returns ===
:;x
;x
:The scaled x position of the cursor
:The scaled x position of the cursor
:;y
;y
:The scaled y position of the cursor
:The scaled y position of the cursor


Line 24: Line 20:


==Code==
==Code==
<!-- Paste your function(s) here. Make sure to prefix each line with at least one space. You may want to replace some troublesome characters with HTML entities when necessary, e.g. "<" becomes &lt;, etc.. -->
  local function {{PAGENAME}}()
 
local scale, x, y = UIParent:GetScale(), GetCursorPosition()
  function {{PAGENAME}}()
return x / scale, y / scale
    local scale = UIParent:GetScale()
    local x, y = GetCursorPosition()
    if scale == 0 then -- very little to no chance of this happening, but you never know.
        return
    else
        return x / scale, y / scale
    end
  end
  end


__NOTOC__
__NOTOC__
[[Category:User Defined Functions]]
[[Category:User Defined Functions]]

Revision as of 11:08, 24 November 2007

This page documents a user-defined function that you can copy and paste into your addon. Replace PREFIX with your addon or lib prefix to avoid conflicts between different versions of these functions.

User defined functions

USERAPI GetCursorScaledPosition - by Egingell -

Returns the scaled position of the cursor.

local x, y = USERAPI GetCursorScaledPosition()

Function Parameters

Returns

x
The scaled x position of the cursor
y
The scaled y position of the cursor

Example

local x, y = USERAPI GetCursorScaledPosition();
message('('..x..', '..y..')');

Result

(25.45218785412654, 375.45610597856123)

Code

local function USERAPI GetCursorScaledPosition()
	local scale, x, y = UIParent:GetScale(), GetCursorPosition()
	return x / scale, y / scale
end