View Single Post
01-16-13, 06:34 PM   #1
Sieben11
A Deviate Faerie Dragon
Join Date: Jan 2009
Posts: 10
Posting some code for ideas on

Fairly basic container code I made. Posting here if anyone has ideas. Or if I need to add/change something. It just makes a button that enables or hides a attached frame. The code to embed other data is not done. Have not figured how I was going to set that up. So all this provides is just what was mentioned before. It wasn't meant to be complex. So do understand that changes must be reflective of simplicity and/or I made a goof and you know a better way. Posting here because people here seem very helpful and nice.

To tell you the use I will be having for it. Will be for an add-on I am making for druids. It will monitor and watch for druid specific things like spells(dps/heal),forms etc. And the following code will be used as a container for these items. To representing them in fairly visual bars.

---
NAME: Define a unique name for the frames, most likely just addon name. To call the container in another frame use [add-on name] with "_Frame". As in "MyAddon_Frame".

ATTACH: Simple attach to frame.

STATE: Toggle initial state of container.

FWIDTH: Frame width.

FHEIGHT: Frame height.

BWIDTH: Button width.

BHEIGHT: Button height.

POINT: Point.

RELPOINT: Relative Point.
---

---
May extend for textures and child containers. IE a collapse container inside another collapse container.
---

Function:
Code:
function collapse_container(name,attach,state,fwidth,fheight,bwidth,bheight,point,relpoint)

local f = CreateFrame("Frame", name.."_Frame", attach)
f:SetFrameStrata("DIALOG")
f:RegisterForDrag("LeftButton")
f:SetMovable(true)
f:EnableMouse(true)
f:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background", 
     edgeFile = "Interface/Tooltips/UI-Tooltip-Border", 
     tile = true, tileSize = 16, edgeSize = 16, 
     insets = { left = 4, right = 4, top = 4, bottom = 4 }})
f:SetBackdropColor(0,0,0,1)
f:SetClampedToScreen(true)
f:SetPoint(point, attach, relpoint) f:SetSize(fwidth,fheight)

f:SetScript("OnDragStart", f.StartMoving)
f:SetScript("OnDragStop", f.StopMovingOrSizing)

if state == true then f:Show()
else f:Hide()
end

local btn = CreateFrame("Button", name.."_Button", attach)
btn:SetFrameStrata("TOOLTIP")
btn:SetNormalTexture("Interface\\CHATFRAME\\UI-ChatIcon-Minimize-Up.blp")
btn:SetPushedTexture("Interface\\CHATFRAME\\UI-ChatIcon-Minimize-Down.blp")
btn:RegisterForClicks("LeftButtonUp")
btn:SetAlpha(0.2)
btn:SetClampedToScreen(true)
btn:SetPoint("TOPLEFT",f,"TOPLEFT",-25,0) btn:SetSize(bwidth,bheight) -- set to f

btn:SetScript("OnClick", function()
if state == true then
--show f, lock btn to 1 alpha
state = false
f:Hide()
btn:SetAlpha(1)
return
--
elseif state == false then
--hide f, keep showing btn
state = true
f:Show()
end
end)
btn:SetScript("OnEnter", function(self) if state == false then self:SetAlpha(1) end end)
btn:SetScript("OnLeave", function(self) if state == false then self:SetAlpha(0.2) end end)

end
Example:
Code:
collapse_container("My_Addon",UIParent,false,100,100,28,28,"CENTER","CENTER")

Last edited by Sieben11 : 01-16-13 at 11:13 PM.
  Reply With Quote