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