comparison State.lua @ 103:890e4c4ab143

- added alpha settings (base and stateful) - added scale settings (stateful only) - updated overlay to work with stateful anchor/scale (though when in a state with scale, the button size/spacing can't be manipulated)
author Flick <flickerstreak@gmail.com>
date Thu, 06 Nov 2008 01:28:07 +0000
parents 3699d7dad312
children
comparison
equal deleted inserted replaced
102:ad49739d110d 103:890e4c4ab143
74 74
75 -- PRIVATE -- 75 -- PRIVATE --
76 do 76 do
77 77
78 -- the field names must match the field names of the options table, below 78 -- the field names must match the field names of the options table, below
79 -- the field values are secure snippets 79 -- the field values are secure snippets or 'true' to skip the snippet for that property.
80 local properties = { 80 local properties = {
81 hide = 81 hide =
82 [[ 82 [[
83 local h = hide and hide[state] and not showAll 83 local h = hide and hide[state] and not showAll
84 if h ~= hidden then 84 if h ~= hidden then
88 self:Show() 88 self:Show()
89 end 89 end
90 hidden = h 90 hidden = h
91 end 91 end
92 if showAll then 92 if showAll then
93 control:CallMethod("UpdateHiddenLabel",hide[state]) 93 control:CallMethod("UpdateHiddenLabel", hide and hide[state])
94 end 94 end
95 ]], 95 ]],
96 96
97 --keybindState TODO: broken 97 --keybindState TODO: broken
98 98
120 anchorFrame = true, 120 anchorFrame = true,
121 anchorPoint = true, 121 anchorPoint = true,
122 anchorRelPoint = true, 122 anchorRelPoint = true,
123 anchorX = true, 123 anchorX = true,
124 anchorY = true, 124 anchorY = true,
125 enableScale = true, 125
126
127 enableScale =
128 [[
129 local old_scale = scalestate
130 scalestate = (enableScale and enableScale[state]) and state
131 if old_scale ~= scalestate or not set_state then
132 if scalestate and scale then
133 if scale[state] then
134 self:SetScale(scale[state])
135 end
136 else
137 self:SetScale(1.0)
138 end
139 end
140 ]],
141 -- enableScale handles scale
126 scale = true, 142 scale = true,
143
144 enableAlpha =
145 [[
146 local old_alpha = alphastate
147 alphastate = (enableAlpha and enableAlpha[state]) and state
148 if old_alpha ~= alphastate or not set_state then
149 control:CallMethod("UpdateAlpha", alphastate and alpha[state] or defaultAlpha)
150 end
151 ]],
152 -- enableAlpha handles alpha
153 alpha = true,
127 } 154 }
128 155
129 local weak = { __mode = "k" } 156 local weak = { __mode = "k" }
130 local statedrivers = setmetatable( { }, weak ) 157 local statedrivers = setmetatable( { }, weak )
131 local keybinds = setmetatable( { }, weak ) 158 local keybinds = setmetatable( { }, weak )
154 for i = 1, #propfuncs do 181 for i = 1, #propfuncs do
155 control:RunAttribute("func-"..propfuncs[i]) 182 control:RunAttribute("func-"..propfuncs[i])
156 end 183 end
157 184
158 control:ChildUpdate() 185 control:ChildUpdate()
186
187 if oldState ~= state then
188 control:CallMethod("StateRefresh", state)
189 end
159 ]] 190 ]]
160 191
161 local onClickHandler = 192 local onClickHandler =
162 -- function OnClick( self, button, down ) 193 -- function OnClick( self, button, down )
163 [[ 194 [[
165 state_override = nil -- toggle 196 state_override = nil -- toggle
166 else 197 else
167 state_override = button 198 state_override = button
168 end 199 end
169 ]] .. onStateHandler 200 ]] .. onStateHandler
201
202 local function UpdateAlpha( frame, alpha )
203 if alpha then
204 frame:SetAlpha(alpha)
205 end
206 end
170 207
171 -- Construct a lua assignment as a code string and execute it within the header 208 -- Construct a lua assignment as a code string and execute it within the header
172 -- frame's sandbox. 'value' must be a string, boolean, number, or nil. If called 209 -- frame's sandbox. 'value' must be a string, boolean, number, or nil. If called
173 -- with four arguments, then it treats 'varname' as an existing global table and 210 -- with four arguments, then it treats 'varname' as an existing global table and
174 -- sets a key-value pair. For a slight efficiency boost, pass the values in as 211 -- sets a key-value pair. For a slight efficiency boost, pass the values in as
201 local point, frame, relPoint, x, y = bar:GetAnchor() 238 local point, frame, relPoint, x, y = bar:GetAnchor()
202 SetHandlerData(bar, "defaultAnchor", point, "point") 239 SetHandlerData(bar, "defaultAnchor", point, "point")
203 SetHandlerData(bar, "defaultAnchor", relPoint, "relPoint") 240 SetHandlerData(bar, "defaultAnchor", relPoint, "relPoint")
204 SetHandlerData(bar, "defaultAnchor", x, "x") 241 SetHandlerData(bar, "defaultAnchor", x, "x")
205 SetHandlerData(bar, "defaultAnchor", y, "y") 242 SetHandlerData(bar, "defaultAnchor", y, "y")
243 SetHandlerData(bar, "defaultAlpha", bar:GetAlpha())
206 244
207 local f = bar:GetFrame() 245 local f = bar:GetFrame()
246 f.UpdateAlpha = UpdateAlpha
208 SetFrameRef(f, "defaultAnchor", _G[frame or "UIParent"]) 247 SetFrameRef(f, "defaultAnchor", _G[frame or "UIParent"])
209 f:Execute( 248 f:Execute(
210 [[ 249 [[
211 defaultAnchor.frame = self:GetAttribute("frameref-defaultAnchor") 250 defaultAnchor.frame = self:GetAttribute("frameref-defaultAnchor")
212 ]]) 251 ]])
227 266
228 if not f.UpdateHiddenLabel then 267 if not f.UpdateHiddenLabel then
229 function f:UpdateHiddenLabel(hide) 268 function f:UpdateHiddenLabel(hide)
230 bar:SetLabelSubtext( hide and L["Hidden"] ) 269 bar:SetLabelSubtext( hide and L["Hidden"] )
231 end 270 end
271 end
272
273 function f:StateRefresh( state )
274 bar:RefreshControls()
232 end 275 end
233 276
234 local props = { } 277 local props = { }
235 for p, h in pairs(properties) do 278 for p, h in pairs(properties) do
236 if type(h) == "string" then 279 if type(h) == "string" then
735 }, 778 },
736 scale = { 779 scale = {
737 name = L["Scale"], 780 name = L["Scale"],
738 order = 2, 781 order = 2,
739 type = "range", 782 type = "range",
740 min = 0.1, 783 min = 0.25,
741 max = 2.5, 784 max = 2.5,
742 step = 0.05, 785 step = 0.05,
743 isPercent = true, 786 isPercent = true,
744 set = "SetProp", 787 set = "SetProp",
745 get = "GetProp", 788 get = "GetScale",
746 disabled = "GetScaleDisabled", 789 disabled = "GetScaleDisabled",
747 hidden = "GetScaleDisabled", 790 hidden = "GetScaleDisabled",
791 },
792 },
793 },
794 alpha = {
795 name = L["Transparency"],
796 order = 94,
797 type = "group",
798 inline = true,
799 args = {
800 enableAlpha = {
801 name = L["Set Transparency"],
802 order = 1,
803 type = "toggle",
804 set = "SetProp",
805 get = "GetProp",
806 },
807 alpha = {
808 name = L["Transparency"],
809 order = 2,
810 type = "range",
811 min = 0,
812 max = 1,
813 step = 0.01,
814 bigStep = 0.05,
815 isPercent = true,
816 set = "SetProp",
817 get = "GetAlpha",
818 disabled = "GetAlphaDisabled",
819 hidden = "GetAlphaDisabled",
748 }, 820 },
749 }, 821 },
750 }, 822 },
751 }, 823 },
752 plugins = { } 824 plugins = { }
1051 1123
1052 function StateHandler:GetAnchorPointProp(info) 1124 function StateHandler:GetAnchorPointProp(info)
1053 return self:GetProp(info) or "NONE" 1125 return self:GetProp(info) or "NONE"
1054 end 1126 end
1055 1127
1128 function StateHandler:GetScale(info)
1129 return self:GetProp(info) or 1.0
1130 end
1131
1056 function StateHandler:GetScaleDisabled() 1132 function StateHandler:GetScaleDisabled()
1057 return not GetProperty(self.bar, self:GetName(), "enableScale") 1133 return not GetProperty(self.bar, self:GetName(), "enableScale")
1134 end
1135
1136 function StateHandler:GetAlpha(info)
1137 return self:GetProp(info) or 1.0
1138 end
1139
1140 function StateHandler:GetAlphaDisabled()
1141 return not GetProperty(self.bar, self:GetName(), "enableAlpha")
1058 end 1142 end
1059 1143
1060 function StateHandler:SetType(info, value) 1144 function StateHandler:SetType(info, value)
1061 self:SetRuleField("type", value) 1145 self:SetRuleField("type", value)
1062 self:FixAll() 1146 self:FixAll()
1240 1324
1241 function module:UnregisterStateProperty( field ) 1325 function module:UnregisterStateProperty( field )
1242 UnregisterProperty(field) 1326 UnregisterProperty(field)
1243 UnregisterPropertyOptions(field) 1327 UnregisterPropertyOptions(field)
1244 end 1328 end
1329
1330
1331 -- Export methods to Bar class --
1332
1333 function ReAction.Bar:GetState()
1334 return GetManagedEnvironment(self:GetFrame()).state
1335 end
1336
1337 ReAction.Bar.GetStateProperty = GetProperty
1338 ReAction.Bar.SetStateProperty = SetProperty