Nenue@50: --- Devian - Dock.lua Nenue@32: -- @file-author@ Nenue@32: -- @project-revision@ @project-hash@ Nenue@32: -- @file-revision@ @file-hash@ Nenue@32: -- Created: 12/26/2015 12:32 PM Nenue@50: -- Docking and arrangement calls Nenue@32: Nenue@32: local D = LibStub("AceAddon-3.0"):GetAddon("Devian") Nenue@50: local ceil, floor, sqrt, pairs, GetScreenWidth, GetScreenHeight = math.ceil, math.floor, math.sqrt, pairs, GetScreenWidth, GetScreenHeight Nenue@50: local UIFrameFadeIn, UIFrameFadeOut = UIFrameFadeIn, UIFrameFadeOut Nenue@47: local db Nenue@32: Nenue@32: --- Spaces each frame evenly across the screen. Nenue@32: function D:DistributeFrames() -- Nenue@50: local max = self.num_channels Nenue@50: local num_side = ceil(sqrt(max)) Nenue@50: local w = GetScreenWidth() / num_side Nenue@50: local h = GetScreenHeight() / num_side Nenue@50: for i, frame in pairs(D.console) do Nenue@50: local dx = (i-1) % num_side Nenue@50: local dy = floor((i-1) / num_side) Nenue@50: frame.width = w Nenue@50: frame.height = h Nenue@50: frame.x = dx * w Nenue@50: frame.y = -(dy * h) Nenue@50: frame:Save() Nenue@50: end Nenue@32: end Nenue@32: Nenue@32: --- Place all frames stacked beneath the primary frame. Nenue@32: function D:StackFrames() Nenue@32: local last Nenue@50: for _, frame in pairs(self.console) do Nenue@32: if last then Nenue@32: frame.x = last.x Nenue@32: frame.y = last.y - 20 Nenue@32: else Nenue@32: frame.x = (GetScreenWidth()-frame:GetWidth())/2 Nenue@32: frame.y = 0 Nenue@32: end Nenue@32: frame:Save() Nenue@32: last = frame Nenue@32: end Nenue@32: end Nenue@32: Nenue@32: Nenue@50: --- Space everything and set the dock size Nenue@46: function D:UpdateDock() Nenue@47: local pad_offset = 12 Nenue@47: local draw_offset = pad_offset Nenue@47: for i = 1, #self.dock.buttons do Nenue@47: local d = self.dock.buttons[i] Nenue@47: d:SetPoint('TOPLEFT', DevianDock, 'TOPLEFT', draw_offset, 0) Nenue@47: draw_offset= draw_offset + d:GetWidth() + pad_offset Nenue@47: end Nenue@50: self.dock:SetWidth(draw_offset) Nenue@50: end Nenue@46: Nenue@50: --- Updates region visibility as needed Nenue@50: local getFadeInArgs = function(sign, region) Nenue@50: --print('Dvn', region) Nenue@50: local db = D.db Nenue@50: local alph = region:GetAlpha() Nenue@50: local a = (db[sign..'_alpha_on'] - alph) Nenue@50: local b = (db[sign..'_alpha_on']-db[sign..'_alpha_off']) Nenue@50: local dur = (a / b) * db[sign..'_fade_in'] Nenue@50: return dur, alph, db[sign..'_alpha_on'] Nenue@50: end Nenue@50: Nenue@50: local getFadeOutArgs = function(sign, region) Nenue@50: local db = D.db Nenue@50: local alph = region:GetAlpha() Nenue@50: local a = (alph - db[sign..'_alpha_off']) Nenue@50: local b = (db[sign..'_alpha_on']-db[sign..'_alpha_off']) Nenue@50: local dur = (a / b) * db[sign..'_fade_out'] Nenue@50: return dur, alph, db[sign..'_alpha_off'] Nenue@50: end Nenue@50: Nenue@50: function D.UpdateBeacon(beacon) Nenue@50: local db = D.db Nenue@50: local isActive = (beacon.raised or beacon.selected) Nenue@50: if isActive then Nenue@50: UIFrameFadeIn(beacon, getFadeInArgs('dock_button', beacon)) Nenue@50: end Nenue@50: if beacon.showName or isActive then Nenue@50: UIFrameFadeIn(beacon.caption, getFadeInArgs('dock_button', beacon.caption)) Nenue@50: end Nenue@50: Nenue@50: if not isActive then Nenue@50: UIFrameFadeOut(beacon, getFadeOutArgs('dock_button', beacon)) Nenue@50: end Nenue@50: if (not beacon.showName) and (not isActive) then Nenue@50: UIFrameFadeOut(beacon.caption,getFadeOutArgs('dock_button', beacon.caption)) Nenue@50: end Nenue@47: end Nenue@47: Nenue@47: --- Dock interactions Nenue@47: function D.DockHighlight(beacon) Nenue@47: db = D.db Nenue@47: local self = D.dock Nenue@47: local mouseOverDock Nenue@47: if self:IsMouseOver() then Nenue@47: mouseOverDock = true Nenue@47: end Nenue@47: Nenue@47: if beacon and beacon:IsMouseOver() then Nenue@47: mouseOverDock = true Nenue@47: if not beacon.raised then Nenue@47: beacon.raised = true Nenue@50: D.UpdateBeacon(beacon) Nenue@46: end Nenue@47: elseif beacon.raised and beacon.index ~= db.current_channel then Nenue@47: beacon.raised = nil Nenue@50: D.UpdateBeacon(beacon) Nenue@47: end Nenue@46: Nenue@47: if mouseOverDock then Nenue@50: -- Raise it up Nenue@47: if not self.raised then Nenue@47: self.raised = true Nenue@50: UIFrameFadeIn(self, getFadeInArgs('dock', self)) Nenue@46: end Nenue@47: elseif self.raised then Nenue@50: -- Drop it down Nenue@47: self.raised = nil Nenue@50: UIFrameFadeOut(self, getFadeOutArgs('dock', self)) Nenue@46: end Nenue@47: Nenue@46: end