annotate 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
rev   line source
flickerstreak@25 1 local ReAction = ReAction
flickerstreak@25 2 local L = ReAction.L
flickerstreak@25 3 local _G = _G
flickerstreak@25 4 local CreateFrame = CreateFrame
flickerstreak@25 5
flickerstreak@25 6 -- update ReAction revision if this file is newer
flickerstreak@25 7 local revision = tonumber(("$Revision: 1 $"):match("%d+"))
flickerstreak@25 8 if revision > ReAction.revision then
flickerstreak@25 9 Reaction.revision = revision
flickerstreak@25 10 end
flickerstreak@25 11
flickerstreak@28 12 ------ BAR CLASS ------
flickerstreak@28 13 local Bar = { _classID = {} }
flickerstreak@25 14
flickerstreak@28 15 local function Constructor( self, name, config )
flickerstreak@25 16 self.name, self.config = name, config
flickerstreak@25 17
flickerstreak@25 18 if type(config) ~= "table" then
flickerstreak@28 19 error("ReAction.Bar: config table required")
flickerstreak@25 20 end
flickerstreak@25 21
flickerstreak@25 22 local f = CreateFrame("Frame",nil,config.parent or UIParent,"SecureStateDriverTemplate")
flickerstreak@25 23 f:SetFrameStrata("MEDIUM")
flickerstreak@25 24 config.width = config.width or 400
flickerstreak@25 25 config.height = config.height or 80
flickerstreak@25 26 f:SetWidth(config.width)
flickerstreak@25 27 f:SetWidth(config.height)
flickerstreak@25 28
flickerstreak@25 29 self.frame = f
flickerstreak@25 30 self:RefreshLayout()
flickerstreak@25 31 self:ApplyAnchor()
flickerstreak@25 32 f:Show()
flickerstreak@25 33 end
flickerstreak@25 34
flickerstreak@25 35 function Bar:Destroy()
flickerstreak@25 36 local f = self.frame
flickerstreak@25 37 f:UnregisterAllEvents()
flickerstreak@25 38 f:Hide()
flickerstreak@25 39 f:SetParent(UIParent)
flickerstreak@25 40 f:ClearAllPoints()
flickerstreak@25 41 self.labelString = nil
flickerstreak@25 42 self.controlFrame = nil
flickerstreak@25 43 self.frame = nil
flickerstreak@25 44 self.config = nil
flickerstreak@25 45 end
flickerstreak@25 46
flickerstreak@25 47 function Bar:RefreshLayout()
flickerstreak@25 48 ReAction:CallMethodOnAllModules("RefreshBar", self)
flickerstreak@25 49 end
flickerstreak@25 50
flickerstreak@25 51 function Bar:ApplyAnchor()
flickerstreak@25 52 local f, config = self.frame, self.config
flickerstreak@25 53 f:SetWidth(config.width)
flickerstreak@25 54 f:SetHeight(config.height)
flickerstreak@25 55 local anchor = config.anchor
flickerstreak@25 56 if anchor then
flickerstreak@25 57 local anchorTo
flickerstreak@25 58 if config.anchorTo then
flickerstreak@28 59 anchorTo = ReAction:GetBar(config.anchorTo) or _G[config.anchorTo]
flickerstreak@25 60 end
flickerstreak@25 61 f:SetPoint(anchor, anchorTo, config.relativePoint, config.x or 0, config.y or 0)
flickerstreak@25 62 else
flickerstreak@25 63 f:SetPoint("CENTER")
flickerstreak@25 64 end
flickerstreak@25 65 end
flickerstreak@25 66
flickerstreak@25 67 function Bar:GetFrame()
flickerstreak@25 68 return self.frame
flickerstreak@25 69 end
flickerstreak@25 70
flickerstreak@25 71 function Bar:GetSize()
flickerstreak@25 72 return self.frame:GetWidth() or 200, self.frame:GetHeight() or 200
flickerstreak@25 73 end
flickerstreak@25 74
flickerstreak@25 75 function Bar:SetSize(w,h)
flickerstreak@25 76 self.config.width = w
flickerstreak@25 77 self.config.height = h
flickerstreak@25 78 end
flickerstreak@25 79
flickerstreak@25 80 function Bar:GetButtonSize()
flickerstreak@25 81 local w = self.config.btnWidth or 32
flickerstreak@25 82 local h = self.config.btnHeight or 32
flickerstreak@25 83 -- TODO: get from modules?
flickerstreak@25 84 return w,h
flickerstreak@25 85 end
flickerstreak@25 86
flickerstreak@25 87 function Bar:SetButtonSize(w,h)
flickerstreak@25 88 if w > 0 and h > 0 then
flickerstreak@25 89 self.config.btnWidth = w
flickerstreak@25 90 self.config.btnHeight = h
flickerstreak@25 91 end
flickerstreak@25 92 end
flickerstreak@25 93
flickerstreak@25 94 function Bar:GetButtonGrid()
flickerstreak@25 95 local cfg = self.config
flickerstreak@25 96 local r = cfg.btnRows or 1
flickerstreak@25 97 local c = cfg.btnColumns or 1
flickerstreak@25 98 local s = cfg.spacing or 4
flickerstreak@25 99 return r,c,s
flickerstreak@25 100 end
flickerstreak@25 101
flickerstreak@25 102 function Bar:SetButtonGrid(r,c,s)
flickerstreak@25 103 if r > 0 and c > 0 and s > 0 then
flickerstreak@25 104 local cfg = self.config
flickerstreak@25 105 cfg.btnRows = r
flickerstreak@25 106 cfg.btnColumns = c
flickerstreak@25 107 cfg.spacing = s
flickerstreak@25 108 end
flickerstreak@25 109 end
flickerstreak@25 110
flickerstreak@25 111 function Bar:GetName()
flickerstreak@25 112 return self.name
flickerstreak@25 113 end
flickerstreak@25 114
flickerstreak@25 115 function Bar:PlaceButton(f, idx, baseW, baseH)
flickerstreak@25 116 local r, c, s = self:GetButtonGrid()
flickerstreak@25 117 local bh, bw = self:GetButtonSize()
flickerstreak@25 118 local row, col = floor((idx-1)/c), mod((idx-1),c) -- zero-based
flickerstreak@25 119 local x, y = col*bw + (col+0.5)*s, row*bh + (row+0.5)*s
flickerstreak@25 120 local scale = bw/baseW
flickerstreak@25 121
flickerstreak@25 122 f:ClearAllPoints()
flickerstreak@25 123 f:SetPoint("TOPLEFT",x/scale,-y/scale)
flickerstreak@25 124 f:SetScale(scale)
flickerstreak@25 125 -- f:Show()
flickerstreak@25 126 end
flickerstreak@25 127
flickerstreak@28 128
flickerstreak@28 129
flickerstreak@28 130 ------ Export as a class-factory ------
flickerstreak@28 131 ReAction.Bar = {
flickerstreak@28 132 prototype = Bar,
flickerstreak@28 133
flickerstreak@28 134 IsInstance = function(self, x)
flickerstreak@28 135 return type(x) == "table" and x._classID == Bar._classID
flickerstreak@28 136 end,
flickerstreak@28 137
flickerstreak@28 138 new = function(self, ...)
flickerstreak@28 139 local x = { }
flickerstreak@28 140 for k,v in pairs(Bar) do
flickerstreak@28 141 x[k] = v
flickerstreak@28 142 end
flickerstreak@28 143 Constructor(x, ...)
flickerstreak@28 144 return x
flickerstreak@28 145 end
flickerstreak@28 146 }