comparison State.lua @ 101:3699d7dad312

added stateful anchoring
author Flick <flickerstreak@gmail.com>
date Sat, 25 Oct 2008 18:49:18 +0000
parents a44173c7a82c
children 890e4c4ab143
comparison
equal deleted inserted replaced
100:9715174ff220 101:3699d7dad312
49 local olhs = tfetch(t[lhs], unpack(path)) or 0 49 local olhs = tfetch(t[lhs], unpack(path)) or 0
50 local orhs = tfetch(t[rhs], unpack(path)) or 0 50 local orhs = tfetch(t[rhs], unpack(path)) or 0
51 return olhs < orhs 51 return olhs < orhs
52 end) 52 end)
53 return r 53 return r
54 end
55
56 -- set a frame-ref, if the frame is valid, or set nil to the
57 -- corresponding attribute
58 local function SetFrameRef(frame, name, refFrame)
59 if refFrame then
60 local _, explicit = refFrame:IsProtected()
61 if not explicit then
62 refFrame = nil
63 end
64 end
65 if refFrame then
66 frame:SetFrameRef(name,refFrame)
67 else
68 frame:SetAttribute("frameref-"..name,nil)
69 end
54 end 70 end
55 71
56 72
57 local InitRules, ApplyStates, CleanupStates, SetProperty, GetProperty, RegisterProperty, ShowAll 73 local InitRules, ApplyStates, CleanupStates, SetProperty, GetProperty, RegisterProperty, ShowAll
58 74
78 end 94 end
79 ]], 95 ]],
80 96
81 --keybindState TODO: broken 97 --keybindState TODO: broken
82 98
83 -- the anchoring is handled in a special handler 99 anchorEnable =
84 anchorEnable = true, 100 [[
85 --anchorFrame = true, TODO: broken 101 local old_anchor = anchorstate
102 anchorstate = (anchorEnable and anchorEnable[state]) and state
103 if old_anchor ~= anchorstate or not set_state then
104 if anchorstate and anchorPoint then
105 if anchorPoint[state] then
106 self:ClearAllPoints()
107 local f = self:GetAttribute("frameref-anchor-"..anchorstate)
108 if f then
109 self:SetPoint(anchorPoint[state], f, anchorRelPoint[state], anchorX[state], anchorY[state])
110 end
111 end
112 elseif defaultAnchor and defaultAnchor.point then
113 self:ClearAllPoints()
114 self:SetPoint(defaultAnchor.point, defaultAnchor.frame,
115 defaultAnchor.relPoint, defaultAnchor.x, defaultAnchor.y)
116 end
117 end
118 ]],
119 -- anchorEnable handles all the other bits
120 anchorFrame = true,
86 anchorPoint = true, 121 anchorPoint = true,
87 anchorRelPoint = true, 122 anchorRelPoint = true,
88 anchorX = true, 123 anchorX = true,
89 anchorY = true, 124 anchorY = true,
90 enableScale = true, 125 enableScale = true,
110 ]] 145 ]]
111 146
112 local onStateHandler = 147 local onStateHandler =
113 -- function _onstate-reaction( self, stateid, newstate ) 148 -- function _onstate-reaction( self, stateid, newstate )
114 [[ 149 [[
115 set_state = newstate or set_state 150 set_state = newstate
116 151
117 local oldState = state 152 local oldState = state
118 state = state_override or set_state or state 153 state = state_override or set_state or state
119
120 for i = 1, #propfuncs do 154 for i = 1, #propfuncs do
121 control:RunAttribute("func-"..propfuncs[i]) 155 control:RunAttribute("func-"..propfuncs[i])
122 end 156 end
123 157
124 if anchorEnable and anchorEnable[state] ~= anchorstate then
125 anchorstate = anchorEnable[state]
126 control:RunAttribute("func-doanchor")
127 end
128
129 control:ChildUpdate() 158 control:ChildUpdate()
130 ]]
131
132 local anchorHandler =
133 -- function func-doanchor( self )
134 [[
135 -- TODO
136 if anchorstate then
137 -- TODO: get anchor data from state tables
138 else
139 -- TODO: get anchor data from defaults
140 end
141 ]] 159 ]]
142 160
143 local onClickHandler = 161 local onClickHandler =
144 -- function OnClick( self, button, down ) 162 -- function OnClick( self, button, down )
145 [[ 163 [[
184 SetHandlerData(bar, "defaultAnchor", point, "point") 202 SetHandlerData(bar, "defaultAnchor", point, "point")
185 SetHandlerData(bar, "defaultAnchor", relPoint, "relPoint") 203 SetHandlerData(bar, "defaultAnchor", relPoint, "relPoint")
186 SetHandlerData(bar, "defaultAnchor", x, "x") 204 SetHandlerData(bar, "defaultAnchor", x, "x")
187 SetHandlerData(bar, "defaultAnchor", y, "y") 205 SetHandlerData(bar, "defaultAnchor", y, "y")
188 206
189 if frame then 207 local f = bar:GetFrame()
190 local f = bar:GetFrame() 208 SetFrameRef(f, "defaultAnchor", _G[frame or "UIParent"])
191 f:SetFrameRef("defaultAnchor", f) 209 f:Execute(
192 f:Execute( 210 [[
193 [[ 211 defaultAnchor.frame = self:GetAttribute("frameref-defaultAnchor")
194 defaultAnchor.frame = self:GetAttribute("frameref-defaultAnchor") 212 ]])
195 ]])
196 end
197 end 213 end
198 214
199 function RefreshState( bar ) 215 function RefreshState( bar )
200 SetDefaultAnchor(bar) 216 SetDefaultAnchor(bar)
201 bar:GetFrame():Execute( 217 bar:GetFrame():Execute(
223 end 239 end
224 end 240 end
225 f:SetAttribute("prop-func-list", table.concat(props," ")) 241 f:SetAttribute("prop-func-list", table.concat(props," "))
226 f:Execute(stateHandler_propInit) 242 f:Execute(stateHandler_propInit)
227 f:SetAttribute("reaction-refresh", onStateHandler) 243 f:SetAttribute("reaction-refresh", onStateHandler)
228 f:SetAttribute("func-doanchor", anchorHandler)
229 244
230 if rule and #rule > 0 then 245 if rule and #rule > 0 then
231 f:SetAttribute( "_onstate-reaction", onStateHandler ) 246 f:SetAttribute( "_onstate-reaction", onStateHandler )
232 RegisterStateDriver(f, "reaction", rule) 247 RegisterStateDriver(f, "reaction", rule)
233 statedrivers[bar] = rule 248 statedrivers[bar] = rule
409 function ApplyStates( bar ) 424 function ApplyStates( bar )
410 local states = tfetch(module.db.profile.bars, bar:GetName(), "states") 425 local states = tfetch(module.db.profile.bars, bar:GetName(), "states")
411 if states then 426 if states then
412 for propname in pairs(properties) do 427 for propname in pairs(properties) do
413 for name, s in pairs(states) do 428 for name, s in pairs(states) do
414 SetHandlerData(bar, propname, s[propname], name) 429 if propname == "anchorFrame" then
430 SetFrameRef(bar:GetFrame(), "anchor-"..name, _G[s.anchorFrame])
431 else
432 SetHandlerData(bar, propname, s[propname], name)
433 end
415 end 434 end
416 end 435 end
417 BuildKeybinds(bar, states) 436 BuildKeybinds(bar, states)
418 SetHandlerData(bar, "showAll", ReAction:GetConfigMode()) 437 SetHandlerData(bar, "showAll", ReAction:GetConfigMode())
419 SetStateDriver(bar, BuildRule(states)) 438 SetStateDriver(bar, BuildRule(states))
637 order = 92, 656 order = 92,
638 type = "group", 657 type = "group",
639 inline = true, 658 inline = true,
640 args = { 659 args = {
641 anchorEnable = { 660 anchorEnable = {
642 name = L["Set New Position"], 661 name = L["Reposition"],
643 order = 1, 662 order = 1,
644 type = "toggle", 663 type = "toggle",
645 set = "SetProp", 664 set = "SetProp",
646 get = "GetProp", 665 get = "GetProp",
647 }, 666 },
648 --[[ TODO: broken
649 anchorFrame = { 667 anchorFrame = {
650 name = L["Anchor Frame"], 668 name = L["Anchor Frame"],
651 order = 2, 669 order = 2,
652 type = "select", 670 type = "select",
653 values = "GetAnchorFrames", 671 values = "GetAnchorFrames",
654 set = ??? 672 set = "SetAnchorFrame",
655 get = ??? 673 get = "GetAnchorFrame",
656 }, ]] 674 disabled = "GetAnchorDisabled",
675 hidden = "GetAnchorDisabled",
676 },
657 anchorPoint = { 677 anchorPoint = {
658 name = L["Point"], 678 name = L["Point"],
659 order = 3, 679 order = 3,
660 type = "select", 680 type = "select",
661 values = pointTable, 681 values = pointTable,
992 ApplyStates(self.bar) 1012 ApplyStates(self.bar)
993 end 1013 end
994 end 1014 end
995 1015
996 function StateHandler:GetAnchorDisabled() 1016 function StateHandler:GetAnchorDisabled()
997 return not GetProperty(self.bar, self:GetName(), "enableAnchor") 1017 return not GetProperty(self.bar, self:GetName(), "anchorEnable")
1018 end
1019
1020 function StateHandler:GetAnchorFrames(info)
1021 self._anchorframes = self._anchorframes or { }
1022 table.wipe(self._anchorframes)
1023
1024 table.insert(self._anchorframes, "UIParent")
1025 for name, bar in ReAction:IterateBars() do
1026 table.insert(self._anchorframes, bar:GetFrame():GetName())
1027 end
1028 return self._anchorframes
1029 end
1030
1031 function StateHandler:GetAnchorFrame(info)
1032 local value = self:GetProp(info)
1033 for k,v in pairs(self._anchorframes) do
1034 if v == value then
1035 return k
1036 end
1037 end
1038 end
1039
1040 function StateHandler:SetAnchorFrame(info, value)
1041 local f = _G[self._anchorframes[value]]
1042 if f then
1043 SetFrameRef(self.bar:GetFrame(), "anchor-"..self:GetName(), f)
1044 self:SetProp(info, f:GetName())
1045 end
998 end 1046 end
999 1047
1000 function StateHandler:SetAnchorPointProp(info, value) 1048 function StateHandler:SetAnchorPointProp(info, value)
1001 self:SetProp(info, value ~= "NONE" and value or nil) 1049 self:SetProp(info, value ~= "NONE" and value or nil)
1002 end 1050 end