Thread Tools Display Modes
12-03-10, 09:23 AM   #1
gorillaz09
A Murloc Raider
Join Date: Nov 2010
Posts: 8
How to get Edge of screen

I'm making an addon and I need to know how close my frames are to the edge of the screen. I can easily get it from frame:GetBottom() and frame:GetLeft() but GetTop and GetRight returns the max height and width of my resolution. How can I make a general function to check if I'm close to the top or the right side of my screen?

Code:
if frame:GetLeft() < 10 then
   print("close to left")
elseif frame:GetBottom() < 10 then
   print("close to bottom")

elseif frame:GetTop() -- ??
  Reply With Quote
12-03-10, 10:36 AM   #2
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
I'm using this in some of my addons to find which side is closer.
I can easily be adapted for finding if top or bottom is closer.

Note that it tells you which side is closer without trying to qualify what is "close",
just that "my frame is positioned closer to left side of screen than to right side of screen"
Code:
local function findSide(frame)
	local side = "left";
	local rightDist = 0;
	local leftPos = frame:GetLeft();
	local rightPos = frame:GetRight();
	if ( not rightPos ) then
		rightPos = 0;
	end
	if ( not leftPos ) then
		leftPos = 0;
	end
	rightDist = GetScreenWidth() - rightPos;
	if (leftPos and (rightDist < leftPos)) then
		side = "left";
	else
		side = "right";
	end
	return side
end
Also note that because I use it to decide an anchor point the returns might be a little confusing at first.
I.e if it finds that my frame is closer to the right side it returns "left" as in:
"we're closer to right = have more space on the left, anchor things there".
  Reply With Quote
12-03-10, 10:38 AM   #3
gorillaz09
A Murloc Raider
Join Date: Nov 2010
Posts: 8
thanks! that's more or less what I was looking for
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How to get Edge of screen


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