View Single Post
05-23-11, 07:04 PM   #4
Lordyfrb
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 71
Anchoring Stuf Frames to/from any point on the screen

Warning: This is an advanced modification to Stuf.

Ok, so we all know that Stuf anchors its UFs to the topleft of the UIParent, but if you want to release your UI out into to the wild, anyone who doesn't have the same screen resolution as you will run into the familiar problem of the UFs been in a different place.
So what if we could get Stuf to anchor our UFs to different points on the screen, say we could anchor our frames to the center of the screen and then position them from there, well now it possible with a few modifications.

This guide involves editing 2 files, the first and most advanced edit is in Stuf_options\options.lua

If you open Stuf with in WoW, and select any UF or element, you'll notice that you can only move that element to the right and down, so this is the first fix we need to make.

So in Stuf_options\options.lua search for the following line:
Code:
x.max, y.min = floor(sw / s), -floor(sh / s)
and replace it with
Code:
x.min, x.max = -(floor(sw / s)), (floor(sw / s))
y.min, y.max = -(floor(sh / s)), (floor(sh / s))
This change allows us to move elements either left or right and up or down.

The next modification lets us tell Stuf which points to anchor them to.

Just below the change you made aboce, you see this line:
Code:
local blank = { name=" ", type="header", order=3, }
Below this add these lines:
Code:
anchorto = { name=L["Anchor To"], type="select",  set=set, get=get, order=3.1, 
	values={
		TOPLEFT = L["TOPLEFT"],	TOP = L["TOP"],	TOPRIGHT = L["TOPRIGHT"], LEFT = L["LEFT"],
		CENTER = L["CENTER"], RIGHT = L["RIGHT"], BOTTOMLEFT = L["BOTTOMLEFT"],
		BOTTOM = L["BOTTOM"], BOTTOMRIGHT = L["BOTTOMRIGHT"],
	},
}
anchorfrom = { name=L["Anchor From"], type="select", set=set, get=get, order=3.2, 
	values={
		TOPLEFT = L["TOPLEFT"],	TOP = L["TOP"],	TOPRIGHT = L["TOPRIGHT"], LEFT = L["LEFT"],
		CENTER = L["CENTER"], RIGHT = L["RIGHT"], BOTTOMLEFT = L["BOTTOMLEFT"],
		BOTTOM = L["BOTTOM"], BOTTOMRIGHT = L["BOTTOMRIGHT"],
	},
}
Now we need to get the options into the actual options frame.

If you Scroll down a bit further you will see:
Code:
local frame = {
and just below that you'll find:
Code:
blank=blank,
x=x, y=y, w=w, h=h, scale=scale, blank3=blank3,
bordercolormethod=bordercolormethod, bordercolor=bordercolor,
vertical=vertical, hflip=hflip, vflip=vflip,
After the line that says blank=blank, add this line:
Code:
anchorto=anchorto, anchorfrom=anchorfrom,
Now scroll down a bit further, till you see this:
Code:
hide=hide, copy=copy, blank=blank,
x=x, y=y,
Now add the same as above to after the blank=blank,

Ok so now we have the options added in, if you load WoW and open Stuf's options, in each of the UFs you will now find some anchoring options, but they wont work yet, Stuf doesn't know what to do with these options.

This is the easy part of this mod.
So now we have to edit our second file for this, now open up Stuf\core.lua in your editor, and search for this line:
Code:
uf:SetPoint("TOPLEFT", UIParent, "TOPLEFT", dbuf.x, dbuf.y)
This line tells Stuf where to anchor our UFs to/from, we need to tell it to use our anchors.
So change it to:
Code:
uf:SetPoint(dbuf.anchorto, UIParent, dbuf.anchorfrom, dbuf.x, dbuf.y)
Now stuf knows where to anchor out UFs to and from.

Now when you start WoW, you may get some errors, these come from us not telling Stuf our anchor point, so you'll have to go into Stuf's config and set all the anchor points for each UF.

Thanks

Lordyfrb
__________________
  Reply With Quote