Mercurial > wow > reaction
diff Overlay.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 | f200bcb193d6 |
children |
line wrap: on
line diff
--- 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)