Mercurial > wow > reaction
changeset 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 | ad49739d110d |
children | 4bc50350f405 |
files | Bar.lua Overlay.lua State.lua locale/enUS.lua modules/ReAction_ConfigUI/ReAction_ConfigUI.lua |
diffstat | 5 files changed, 262 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/Bar.lua Sun Oct 26 02:26:31 2008 +0000 +++ b/Bar.lua Thu Nov 06 01:28:07 2008 +0000 @@ -38,6 +38,7 @@ f:SetFrameStrata("MEDIUM") f:SetWidth(self.width) f:SetWidth(self.height) + f:SetAlpha(config.alpha or 1.0) f:Show() f:EnableMouse(false) f:SetClampedToScreen(true) @@ -95,11 +96,12 @@ function Bar:SetAnchor(point, frame, relativePoint, x, y) local c = self.config c.point = point or c.point - c.anchor = frame and frame:GetName() or c.anchor + c.anchor = frame or c.anchor c.relpoint = relativePoint or c.relpoint c.x = x or c.x c.y = y or c.y self:ApplyAnchor() + ReAction:RefreshBar(self) end function Bar:GetAnchor() @@ -188,6 +190,16 @@ self:SetLabel(self.name) -- Bar:SetLabel() defined in Overlay.lua end +function Bar:GetAlpha() + return self.config.alpha or 1.0 +end + +function Bar:SetAlpha(value) + self.config.alpha = value + self:GetFrame():SetAlpha(value or 1.0) + ReAction:RefreshBar(self) +end + function Bar:AddButton(idx, button) local f = self:GetFrame()
--- a/Overlay.lua Sun Oct 26 02:26:31 2008 +0000 +++ b/Overlay.lua Thu Nov 06 01:28:07 2008 +0000 @@ -8,10 +8,9 @@ local GameTooltip = GameTooltip local Bar = ReAction.Bar local GetSize = Bar.GetSize +local SetSize = Bar.SetSize local GetButtonSize = Bar.GetButtonSize local GetButtonGrid = Bar.GetButtonGrid -local SetSize = Bar.SetSize -local SetAnchor = Bar.SetAnchor local SetButtonSize = Bar.SetButtonSize local SetButtonGrid = Bar.SetButtonGrid local ApplyAnchor = Bar.ApplyAnchor @@ -23,6 +22,42 @@ ReAction:UpdateRevision("$Revision$") + +-- +-- Wrap some of the bar manipulators to make them state-aware +-- +local function SetAnchor( bar, point, frame, relPoint, x, y ) + local state = bar:GetState() + if state then + local anchorstate = bar:GetStateProperty(state, "anchorEnable") + if anchorstate then + bar:SetStateProperty(state, "anchorFrame", frame) + bar:SetStateProperty(state, "anchorPoint", point) + bar:SetStateProperty(state, "anchorRelPoint", relPoint) + bar:SetStateProperty(state, "anchorX", x or 0) + bar:SetStateProperty(state, "anchorY", y or 0) + bar:SetAnchor(bar:GetAnchor()) + return + end + end + bar:SetAnchor(point, frame, relPoint, x, y) +end + +local function GetStateScale( bar ) + local state = bar:GetState() + if state and bar:GetStateProperty(state, "enableScale") then + return bar:GetStateProperty(state, "scale") + end +end + +local function SetStateScale( bar, scale ) + local state = bar:GetState() + if state and bar:GetStateProperty(state, "enableScale") then + bar:SetStateProperty(state, "scale", scale) + end +end + + -- -- Bar config overlay -- @@ -51,7 +86,7 @@ local function StoreExtents(bar) local f = bar:GetFrame() local p, fr, rp, x, y = f:GetPoint(1) - fr = fr or UIParent + fr = fr and fr:GetName() or "UIParent" SetAnchor( bar, p, fr, rp, x, y ) SetSize( bar, f:GetWidth(), f:GetHeight() ) end @@ -68,6 +103,24 @@ SetButtonSize(bar, scale * bw, scale * bh, s) end +local function ComputeBarScale(bar) + local w, h = bar.controlFrame:GetWidth() - 8, bar.controlFrame:GetHeight() - 8 + local bw, bh = GetButtonSize(bar) + local r, c, s = GetButtonGrid(bar) + + local scaleW = w / (c*(bw+s)) + local scaleH = h / (r*(bh+s)) + local scale = min(scaleW, scaleH) + + if scale > 2.5 then + scale = 2.5 + elseif scale < 0.25 then + scale = 0.25 + end + + return scale +end + local function RecomputeButtonSpacing(bar) local w, h = GetSize(bar) local bw, bh = GetButtonSize(bar) @@ -407,11 +460,12 @@ f:SetMovable(true) f:SetResizable(true) - local overlay = CreateFrame("Button", nil, f) + -- child of UIParent so that alpha and scale doesn't propagate to it + local overlay = CreateFrame("Button", nil, UIParent) overlay:EnableMouse(true) overlay:SetFrameLevel(3) -- set it above the buttons - overlay:SetPoint("TOPLEFT", -4, 4) - overlay:SetPoint("BOTTOMRIGHT", 4, -4) + overlay:SetPoint("TOPLEFT", f, "TOPLEFT", -4, 4) + overlay:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", 4, -4) overlay:SetBackdrop({ edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = true, @@ -473,27 +527,43 @@ f:SetScript("OnUpdate",nil) StoreSize(bar) ClampToButtons(bar) - --ApplyAnchor(bar) ReAction:RefreshOptions() end local function CornerUpdate() local bw, bh = GetButtonSize(bar) local r, c, s = GetButtonGrid(bar) + local ss = GetStateScale(bar) if IsShiftKeyDown() then - f:SetMinResize( (s+12)*c+1, (s+12)*r+1 ) - RecomputeButtonSize(bar) - elseif IsAltKeyDown() then + if ss then + f:SetMinResize( ((s+bw)*c*0.25)/ss, ((s+bh)*r*0.25)/ss ) + f:SetMaxResize( ((s+bw)*c*2.5 + 1)/ss, ((s+bh)*r*2.5 + 1)/ss ) + scale = ComputeBarScale(bar) + else + f:SetMinResize( (s+12)*c+1, (s+12)*r+1 ) + f:SetMaxResize( (s+128)*c+1, (s+128)*r+1 ) + RecomputeButtonSize(bar) + end + elseif not ss and IsAltKeyDown() then f:SetMinResize( bw*c, bh*r ) + f:SetMaxResize( 2*bw*c, 2*bh*r ) RecomputeButtonSpacing(bar) else f:SetMinResize( bw+s+1, bh+s+1 ) + f:SetMaxResize( 50*(bw+s)+1, 50*(bh+s)+1 ) RecomputeGrid(bar) end - local size = (bw == bh) and tostring(bw) or format("%d x %d",bw,bh) - GameTooltipTextRight1:SetText(format("%d x %d",r,c)) - GameTooltipTextRight2:SetText(size) - GameTooltipTextRight3:SetText(tostring(s)) + GameTooltipTextRight2:SetText(format("%d x %d",r,c)) + + local ss = GetStateScale(bar) + local state = bar:GetState() + if ss then + GameTooltipTextRight4:SetText(format("%d%%", scale*100)) + else + local size = (bw == bh) and tostring(bw) or format("%d x %d",bw,bh) + GameTooltipTextRight3:SetText(size) + GameTooltipTextRight4:SetText(tostring(s)) + end end -- corner drag handles @@ -511,24 +581,42 @@ tex:SetAlpha(0.6) tex:SetAllPoints() - --corner:RegisterForDrag("LeftButton") - corner:SetScript("OnMouseDown", function(_,btn) f:SetScript("OnUpdate", CornerUpdate) f:StartSizing(point) end ) - corner:SetScript("OnMouseUp",StopResize) + corner:SetScript("OnMouseUp", + function() + local ss = GetStateScale(bar) + if ss then + local state = bar:GetState() + SetStateScale(bar, ComputeBarScale(bar)) + end + StopResize() + end) corner:SetScript("OnEnter", function() local bw, bh = GetButtonSize(bar) local r, c, s = bar:GetButtonGrid() local size = (bw == bh) and tostring(bw) or format("%d x %d",bw,bh) + local ss = GetStateScale(bar) + local state = bar:GetState() GameTooltip:SetOwner(f, "ANCHOR_"..point) + if ss then + GameTooltip:AddLine(format("%s (%s: %s)", bar:GetName(), L["State"], state)) + else + GameTooltip:AddLine(bar:GetName()) + end GameTooltip:AddDoubleLine(format("|cffcccccc%s|r %s",L["Drag"],L["to add/remove buttons:"]), format("%d x %d",r,c)) - GameTooltip:AddDoubleLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to resize buttons:"]), size) - GameTooltip:AddDoubleLine(format("|cff0033cc%s|r %s",L["Hold Alt"],L["to change spacing:"]), tostring(s)) + if ss then + GameTooltip:AddLine(L["State Scale Override"]) + GameTooltip:AddDoubleLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to change scale:"]), format("%d%%", bar:GetStateProperty(state,"scale")*100)) + else + GameTooltip:AddDoubleLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to resize buttons:"]), tostring(floor(size))) + GameTooltip:AddDoubleLine(format("|cff0033cc%s|r %s",L["Hold Alt"], L["to change spacing:"]), tostring(floor(s))) + end GameTooltip:Show() end ) @@ -562,16 +650,22 @@ local function UpdateDragTooltip() GameTooltip:SetOwner(f, "ANCHOR_TOPRIGHT") - GameTooltip:AddLine(bar.name) + local ss = GetStateScale(bar) + local state = bar:GetState() + if ss then + GameTooltip:AddLine(format("%s (%s: %s)", bar:GetName(), L["State"], state)) + else + GameTooltip:AddLine(bar:GetName()) + end GameTooltip:AddLine(format("|cffcccccc%s|r %s",L["Drag"],L["to move"])) GameTooltip:AddLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to anchor to nearby frames"])) GameTooltip:AddLine(format("|cff00cccc%s|r %s",L["Right-click"],L["for options..."])) - local point, anchor, relpoint, x, y = bar:GetAnchor() + local point, frame, relpoint, x, y = bar:GetFrame():GetPoint(1) if point then local ofsx, ofsy = insidePointOffsetFuncs[point](x,y) - if (anchor and anchor ~= "UIParent") or (ofsx == 0 and ofsy == 0) then - --anchor = anchor or "UIParent" - GameTooltip:AddLine(format("%s <%s>",L["Currently anchored to"],anchor)) + if (frame and frame ~= UIParent) or (ofsx == 0 and ofsy == 0) then + frame = frame or UIParent + GameTooltip:AddLine(format("%s <%s>",L["Currently anchored to"],frame:GetName())) end end GameTooltip:Show() @@ -622,6 +716,12 @@ self:SetFrameLevel(3) end + function overlay:RefreshControls() + UpdateAnchorDecoration() + end + + overlay:SetScript("OnShow", overlay.RefreshControls) + KB.RegisterCallback(overlay,"LIBKEYBOUND_ENABLED") KB.RegisterCallback(overlay,"LIBKEYBOUND_DISABLED") @@ -652,6 +752,12 @@ end end +function Bar:RefreshControls() + if self.controlFrame and self.controlFrame:IsShown() then + self.controlFrame:RefreshControls() + end +end + function Bar:SetLabel(name) self.labelName = name UpdateLabelString(self)
--- a/State.lua Sun Oct 26 02:26:31 2008 +0000 +++ b/State.lua Thu Nov 06 01:28:07 2008 +0000 @@ -76,7 +76,7 @@ do -- the field names must match the field names of the options table, below - -- the field values are secure snippets + -- the field values are secure snippets or 'true' to skip the snippet for that property. local properties = { hide = [[ @@ -90,7 +90,7 @@ hidden = h end if showAll then - control:CallMethod("UpdateHiddenLabel",hide[state]) + control:CallMethod("UpdateHiddenLabel", hide and hide[state]) end ]], @@ -122,8 +122,35 @@ anchorRelPoint = true, anchorX = true, anchorY = true, - enableScale = true, + + + enableScale = + [[ + local old_scale = scalestate + scalestate = (enableScale and enableScale[state]) and state + if old_scale ~= scalestate or not set_state then + if scalestate and scale then + if scale[state] then + self:SetScale(scale[state]) + end + else + self:SetScale(1.0) + end + end + ]], + -- enableScale handles scale scale = true, + + enableAlpha = + [[ + local old_alpha = alphastate + alphastate = (enableAlpha and enableAlpha[state]) and state + if old_alpha ~= alphastate or not set_state then + control:CallMethod("UpdateAlpha", alphastate and alpha[state] or defaultAlpha) + end + ]], + -- enableAlpha handles alpha + alpha = true, } local weak = { __mode = "k" } @@ -156,6 +183,10 @@ end control:ChildUpdate() + + if oldState ~= state then + control:CallMethod("StateRefresh", state) + end ]] local onClickHandler = @@ -168,6 +199,12 @@ end ]] .. onStateHandler + local function UpdateAlpha( frame, alpha ) + if alpha then + frame:SetAlpha(alpha) + end + end + -- Construct a lua assignment as a code string and execute it within the header -- frame's sandbox. 'value' must be a string, boolean, number, or nil. If called -- with four arguments, then it treats 'varname' as an existing global table and @@ -203,8 +240,10 @@ SetHandlerData(bar, "defaultAnchor", relPoint, "relPoint") SetHandlerData(bar, "defaultAnchor", x, "x") SetHandlerData(bar, "defaultAnchor", y, "y") + SetHandlerData(bar, "defaultAlpha", bar:GetAlpha()) local f = bar:GetFrame() + f.UpdateAlpha = UpdateAlpha SetFrameRef(f, "defaultAnchor", _G[frame or "UIParent"]) f:Execute( [[ @@ -231,6 +270,10 @@ end end + function f:StateRefresh( state ) + bar:RefreshControls() + end + local props = { } for p, h in pairs(properties) do if type(h) == "string" then @@ -737,17 +780,46 @@ name = L["Scale"], order = 2, type = "range", - min = 0.1, + min = 0.25, max = 2.5, step = 0.05, isPercent = true, set = "SetProp", - get = "GetProp", + get = "GetScale", disabled = "GetScaleDisabled", hidden = "GetScaleDisabled", }, }, }, + alpha = { + name = L["Transparency"], + order = 94, + type = "group", + inline = true, + args = { + enableAlpha = { + name = L["Set Transparency"], + order = 1, + type = "toggle", + set = "SetProp", + get = "GetProp", + }, + alpha = { + name = L["Transparency"], + order = 2, + type = "range", + min = 0, + max = 1, + step = 0.01, + bigStep = 0.05, + isPercent = true, + set = "SetProp", + get = "GetAlpha", + disabled = "GetAlphaDisabled", + hidden = "GetAlphaDisabled", + }, + }, + }, }, plugins = { } }, @@ -1053,10 +1125,22 @@ return self:GetProp(info) or "NONE" end + function StateHandler:GetScale(info) + return self:GetProp(info) or 1.0 + end + function StateHandler:GetScaleDisabled() return not GetProperty(self.bar, self:GetName(), "enableScale") end + function StateHandler:GetAlpha(info) + return self:GetProp(info) or 1.0 + end + + function StateHandler:GetAlphaDisabled() + return not GetProperty(self.bar, self:GetName(), "enableAlpha") + end + function StateHandler:SetType(info, value) self:SetRuleField("type", value) self:FixAll() @@ -1242,3 +1326,13 @@ UnregisterProperty(field) UnregisterPropertyOptions(field) end + + +-- Export methods to Bar class -- + +function ReAction.Bar:GetState() + return GetManagedEnvironment(self:GetFrame()).state +end + +ReAction.Bar.GetStateProperty = GetProperty +ReAction.Bar.SetStateProperty = SetProperty
--- a/locale/enUS.lua Sun Oct 26 02:26:31 2008 +0000 +++ b/locale/enUS.lua Thu Nov 06 01:28:07 2008 +0000 @@ -27,10 +27,13 @@ "to add/remove buttons:", "to resize buttons:", "to change spacing:", +"to change scale:", "to move", "to anchor to nearby frames", "for options...", "Currently anchored to", +"State", +"State Scale Override", -- State.lua "Hidden", @@ -84,6 +87,8 @@ "Y Offset", "Scale", "Set New Scale", +"Transparency", +"Set Transparency", "Rule", "Select this state", "by default", @@ -191,6 +196,7 @@ "Anchor point on the target frame", "X offset", "Y offset", +"Transparency", "Button Grid", "Rows", "Columns",
--- a/modules/ReAction_ConfigUI/ReAction_ConfigUI.lua Sun Oct 26 02:26:31 2008 +0000 +++ b/modules/ReAction_ConfigUI/ReAction_ConfigUI.lua Thu Nov 06 01:28:07 2008 +0000 @@ -364,7 +364,8 @@ else f = _G[name] if f and type(f) == "table" and f.IsObjectType and f:IsObjectType("Frame") then - return true + local _, explicit = f:IsProtected() + return explicit end end end @@ -412,6 +413,18 @@ }, order = 3 }, + alpha = { + type = "range", + name = L["Transparency"], + get = function() return bar:GetAlpha() end, + set = function(info, val) bar:SetAlpha(val) end, + min = 0, + max = 1, + isPercent = true, + step = 0.01, + bigStep = 0.05, + order = 4, + }, }, }, }