Mercurial > wow > reaction
view Bar.lua @ 28:21bcaf8215ff
- converted to Ace3
- rearranged file layout
- configGUI menus not working right now
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Mon, 17 Mar 2008 18:24:53 +0000 |
parents | ReAction_Bar.lua@f1e838841ce1 |
children | 0d95ce7a9ec2 |
line wrap: on
line source
local ReAction = ReAction local L = ReAction.L local _G = _G local CreateFrame = CreateFrame -- update ReAction revision if this file is newer local revision = tonumber(("$Revision: 1 $"):match("%d+")) if revision > ReAction.revision then Reaction.revision = revision end ------ BAR CLASS ------ local Bar = { _classID = {} } local function Constructor( self, name, config ) self.name, self.config = name, config if type(config) ~= "table" then error("ReAction.Bar: config table required") end local f = CreateFrame("Frame",nil,config.parent or UIParent,"SecureStateDriverTemplate") f:SetFrameStrata("MEDIUM") config.width = config.width or 400 config.height = config.height or 80 f:SetWidth(config.width) f:SetWidth(config.height) self.frame = f self:RefreshLayout() self:ApplyAnchor() f:Show() end function Bar:Destroy() local f = self.frame f:UnregisterAllEvents() f:Hide() f:SetParent(UIParent) f:ClearAllPoints() self.labelString = nil self.controlFrame = nil self.frame = nil self.config = nil end function Bar:RefreshLayout() ReAction:CallMethodOnAllModules("RefreshBar", self) end function Bar:ApplyAnchor() local f, config = self.frame, self.config f:SetWidth(config.width) f:SetHeight(config.height) local anchor = config.anchor if anchor then local anchorTo if config.anchorTo then anchorTo = ReAction:GetBar(config.anchorTo) or _G[config.anchorTo] end f:SetPoint(anchor, anchorTo, config.relativePoint, config.x or 0, config.y or 0) else f:SetPoint("CENTER") end end function Bar:GetFrame() return self.frame end function Bar:GetSize() return self.frame:GetWidth() or 200, self.frame:GetHeight() or 200 end function Bar:SetSize(w,h) self.config.width = w self.config.height = h end function Bar:GetButtonSize() local w = self.config.btnWidth or 32 local h = self.config.btnHeight or 32 -- TODO: get from modules? return w,h end function Bar:SetButtonSize(w,h) if w > 0 and h > 0 then self.config.btnWidth = w self.config.btnHeight = h end end function Bar:GetButtonGrid() local cfg = self.config local r = cfg.btnRows or 1 local c = cfg.btnColumns or 1 local s = cfg.spacing or 4 return r,c,s end function Bar:SetButtonGrid(r,c,s) if r > 0 and c > 0 and s > 0 then local cfg = self.config cfg.btnRows = r cfg.btnColumns = c cfg.spacing = s end end function Bar:GetName() return self.name end function Bar:PlaceButton(f, idx, baseW, baseH) local r, c, s = self:GetButtonGrid() local bh, bw = self:GetButtonSize() local row, col = floor((idx-1)/c), mod((idx-1),c) -- zero-based local x, y = col*bw + (col+0.5)*s, row*bh + (row+0.5)*s local scale = bw/baseW f:ClearAllPoints() f:SetPoint("TOPLEFT",x/scale,-y/scale) f:SetScale(scale) -- f:Show() end ------ Export as a class-factory ------ ReAction.Bar = { prototype = Bar, IsInstance = function(self, x) return type(x) == "table" and x._classID == Bar._classID end, new = function(self, ...) local x = { } for k,v in pairs(Bar) do x[k] = v end Constructor(x, ...) return x end }