Mercurial > wow > devian
diff Dock.lua @ 50:c3166f700438
dock beacons and text fader cleaned up
fixed OnLeave ending at mouseOverDock false and causing beacons to stick
fixed a nil argument in dock framescript
author | Nenue |
---|---|
date | Tue, 05 Jan 2016 01:37:29 -0500 |
parents | 2bf7eb1844cb |
children | 0a9a6740ea5d |
line wrap: on
line diff
--- a/Dock.lua Mon Jan 04 08:39:07 2016 -0500 +++ b/Dock.lua Tue Jan 05 01:37:29 2016 -0500 @@ -1,100 +1,36 @@ ---- ${PACKAGE_NAME} +--- Devian - Dock.lua -- @file-author@ -- @project-revision@ @project-hash@ -- @file-revision@ @file-hash@ -- Created: 12/26/2015 12:32 PM --- Dock management functions +-- Docking and arrangement calls local D = LibStub("AceAddon-3.0"):GetAddon("Devian") -local _G = _G +local ceil, floor, sqrt, pairs, GetScreenWidth, GetScreenHeight = math.ceil, math.floor, math.sqrt, pairs, GetScreenWidth, GetScreenHeight +local UIFrameFadeIn, UIFrameFadeOut = UIFrameFadeIn, UIFrameFadeOut local db -local function Dock_MenuClick() end - -local function Dock_MouseDown(self, button, up) -end -local function Dock_MouseUp (self, button) - Dock_MouseDown(self, button, true) -end - ---- Adjusts frame element alignments -local function PrepareForDock (frame, draw_x) - frame.left:SetPoint('TOPLEFT', frame.out, 'TOPLEFT', -2, 0) - frame.left:SetPoint('BOTTOMRIGHT', frame.out, 'BOTTOMLEFT', 0, 0) - frame.topleft:SetPoint('BOTTOMRIGHT', frame.out, 'TOPLEFT', 0, 0) - frame.top: SetPoint('TOPLEFT', frame.out, 'TOPLEFT', 0, 2) - frame.top:SetPoint('BOTTOMRIGHT', frame.out, 'TOPRIGHT', 0, 0) - frame.topright:SetPoint('BOTTOMLEFT', frame.out, 'TOPRIGHT', 0, 0) - frame.right:SetPoint('TOPLEFT', frame.out, 'TOPRIGHT', 0, 0) - frame.header:SetWidth(frame.header:GetStringWidth() * 1.2) - frame.header:SetPoint('TOPLEFT', frame, 'TOPLEFT', draw_x+4, 0) - frame.titlebar:SetPoint('TOPLEFT', frame.header, 'TOPLEFT', -4, 0) - frame.titlebar:SetPoint('TOPRIGHT', frame.header, 'TOPRIGHT', 0, 0) - - return (draw_x + frame.header:GetStringWidth() * 1.2 + 4) -end - - ---- Docks frames together --- @param target frame on which to dock --- @param ... frame objects to be docked --- -function D:DockFrame(...) - local target = D.console[select(1,...)] - if target.dockedTo then - local t = D.c[target.dockedTo] - --print('channel',target.index,target.signature, 'is docked to',t.index, t.signature..'. using that instead') - target = D.console[target.DockedTo] - end - - target.docked = {} - local draw_x = PrepareForDock(target, 4) - for i = 2, select('#', ...) do - local frame = D.console[select(i, ...)] - frame.dockedTo = target.index - width, draw_x = MorphToDock (frame, draw_x) - table.insert(target.docked, frame.index) - frame:ClearAllPoints() - frame:SetPoint('TOPLEFT', target, 'TOPLEFT', 0, 0) - frame:SetSize(target:GetWidth(), target:GetHeight()) - frame.x = nil - frame.y = nil - frame.width = nil - frame.height = nil - frame.scriptsMD = frame:GetScript('OnMouseDown') - frame.scriptsMU = frame:GetScript('OnMouseUp') - frame:SetScript('OnMouseDown', nil) - frame:SetScript('OnMouseUp', nil) - frame:Save() - end -end - --- Spaces each frame evenly across the screen. function D:DistributeFrames() -- ---print('frame grid:', max, num_side) -local max = self.num_channels -local num_side = math.ceil(math.sqrt(max)) -local w = GetScreenWidth() / num_side -local h = GetScreenHeight() / num_side -for i, frame in pairs(D.console) do - local dx = (i-1) % num_side - local dy = math.floor((i-1) / num_side) - - --print('move:', frame.signature, 'dx=', dx, 'dy=', dy) - --print('move:', frame.signature, ' x=', dx * w, 'y=', -(dy * h), 'h=', h, 'w=', w) - frame.width = w - frame.height = h - frame.x = dx * w - frame.y = -(dy * h) - frame:Save() -end - + local max = self.num_channels + local num_side = ceil(sqrt(max)) + local w = GetScreenWidth() / num_side + local h = GetScreenHeight() / num_side + for i, frame in pairs(D.console) do + local dx = (i-1) % num_side + local dy = floor((i-1) / num_side) + frame.width = w + frame.height = h + frame.x = dx * w + frame.y = -(dy * h) + frame:Save() + end end --- Place all frames stacked beneath the primary frame. function D:StackFrames() local last - for i, frame in pairs(self.console) do + for _, frame in pairs(self.console) do if last then frame.x = last.x frame.y = last.y - 20 @@ -108,7 +44,7 @@ end ---- +--- Space everything and set the dock size function D:UpdateDock() local pad_offset = 12 local draw_offset = pad_offset @@ -117,66 +53,77 @@ d:SetPoint('TOPLEFT', DevianDock, 'TOPLEFT', draw_offset, 0) draw_offset= draw_offset + d:GetWidth() + pad_offset end + self.dock:SetWidth(draw_offset) +end - self.dock:SetWidth(draw_offset) +--- Updates region visibility as needed +local getFadeInArgs = function(sign, region) + --print('Dvn', region) + local db = D.db + local alph = region:GetAlpha() + local a = (db[sign..'_alpha_on'] - alph) + local b = (db[sign..'_alpha_on']-db[sign..'_alpha_off']) + local dur = (a / b) * db[sign..'_fade_in'] + return dur, alph, db[sign..'_alpha_on'] +end + +local getFadeOutArgs = function(sign, region) + local db = D.db + local alph = region:GetAlpha() + local a = (alph - db[sign..'_alpha_off']) + local b = (db[sign..'_alpha_on']-db[sign..'_alpha_off']) + local dur = (a / b) * db[sign..'_fade_out'] + return dur, alph, db[sign..'_alpha_off'] +end + +function D.UpdateBeacon(beacon) + local db = D.db + local isActive = (beacon.raised or beacon.selected) + if isActive then + UIFrameFadeIn(beacon, getFadeInArgs('dock_button', beacon)) + end + if beacon.showName or isActive then + UIFrameFadeIn(beacon.caption, getFadeInArgs('dock_button', beacon.caption)) + end + + if not isActive then + UIFrameFadeOut(beacon, getFadeOutArgs('dock_button', beacon)) + end + if (not beacon.showName) and (not isActive) then + UIFrameFadeOut(beacon.caption,getFadeOutArgs('dock_button', beacon.caption)) + end end --- Dock interactions function D.DockHighlight(beacon) db = D.db - --print('Dvn', 'dock mouse event', beacon) local self = D.dock local mouseOverDock - --for i, b in pairs(self.buttons) do - --print('polling', i, b:GetName()) if self:IsMouseOver() then mouseOverDock = true end - if beacon and beacon:IsMouseOver() then mouseOverDock = true - --print('mouse is over', i, b:GetName()) - if not beacon.raised then beacon.raised = true - local a = (db.dock_button_alpha_on - self:GetAlpha()) - local b = (db.dock_button_alpha_on-db.dock_button_alpha_off) - local dur = (a / b) * db.dock_button_fade_in - --print(a, b, db.dock_button_fade_in, dur) - UIFrameFadeIn(beacon, dur,beacon:GetAlpha(),db.dock_button_alpha_on) - UIFrameFadeIn(beacon.caption, dur,beacon:GetAlpha(),1) + D.UpdateBeacon(beacon) end elseif beacon.raised and beacon.index ~= db.current_channel then beacon.raised = nil - local a = (self:GetAlpha() - db.dock_button_alpha_off) - local b = (db.dock_button_alpha_on-db.dock_button_alpha_off) - local dur = (a / b) * db.dock_button_fade_out - --print(a, b, db.dock_button_fade_in, dur) - UIFrameFadeOut(beacon, dur,beacon:GetAlpha(),db.dock_button_alpha_off) - UIFrameFadeOut(beacon.caption, dur,beacon:GetAlpha(),0) + D.UpdateBeacon(beacon) end - --end - --end if mouseOverDock then + -- Raise it up if not self.raised then - --print('rising') self.raised = true - local a = (db.dock_alpha_on - self:GetAlpha()) - local b = (db.dock_alpha_on-db.dock_alpha_off) - local dur = (a / b) * db.dock_fade_in - --print(a, b, db.dock_fade_in, dur) - UIFrameFadeIn(self, dur,self:GetAlpha(),db.dock_alpha_on) + UIFrameFadeIn(self, getFadeInArgs('dock', self)) end elseif self.raised then - --print('dropping') + -- Drop it down self.raised = nil - local a = (self:GetAlpha() - db.dock_alpha_off) - local b = (db.dock_alpha_on-db.dock_alpha_off) - local dur = (a / b) * db.dock_fade_out - --print(a, b, db.dock_fade_in, dur) - UIFrameFadeOut(self, dur,self:GetAlpha(),db.dock_alpha_off) + UIFrameFadeOut(self, getFadeOutArgs('dock', self)) end end \ No newline at end of file