WoW:API Model SetPosition: Difference between revisions

Fixed scaling issue with example script.
(Fixed scaling issue with example script.)
Line 20: Line 20:
=== Returns ===
=== Returns ===


: unknown, probably nil
: Nothing


==Notes==
==Notes==


The width and height of the Model frame affect the outcome of this function. ie the effect of calling
The bottom left corner of the Model frame will always have coordinates (0,0,0). However, the top right corner's coordinate depends upon the width and height of the Model frame, as well as the screen resolution returned by [[API GetScreenWidth|GetScreenWidth]]/[[API GetScreenHeight|GetScreenHeight]].  The following formula determines the Model-relative coordinate that corresponds to the top-right of the Model frame (''CoordRight'',''CoordTop'',0):
SetPosition( 0.01, 0.01, 1 ) on a Model frame with width 200px and height 200px, will be different
to calling SetPosition( 0.01, 0.01, 1 ) on a Model frame with width 150px and height 150px


Changing the scale of the Model does not seem to change the effect of this function.
local Scale = UIParent:GetEffectiveScale();
local Hypotenuse = ( ( GetScreenWidth() * Scale ) ^ 2 + ( GetScreenHeight() * Scale ) ^ 2 ) ^ 0.5;
local CoordRight = ( ''MyModelFrame'':GetRight() - ''MyModelFrame'':GetLeft() ) / Hypotenuse; -- X
local CoordTop = ( ''MyModelFrame'':GetTop() - ''MyModelFrame'':GetBottom() ) / Hypotenuse; -- Y
Anonymous user