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@66: local _, D = ... Nenue@50: local ceil, floor, sqrt, pairs, GetScreenWidth, GetScreenHeight = math.ceil, math.floor, math.sqrt, pairs, GetScreenWidth, GetScreenHeight Nenue@47: local db Nenue@66: local print = D.print 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@73: Nenue@73: local dockn = 1 Nenue@73: for i, d in pairs(self.dock.buttons) do Nenue@73: dockn = max(i, dockn) Nenue@73: end Nenue@73: for i = 1, dockn do Nenue@47: local d = self.dock.buttons[i] Nenue@73: if d then Nenue@73: d:SetPoint('TOPLEFT', DevianDock, 'TOPLEFT', draw_offset, 0) Nenue@73: draw_offset= draw_offset + d:GetWidth() + pad_offset Nenue@73: end 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@58: local function queueFade (self, duration, from, to) Nenue@58: self:SetAlpha(to) Nenue@58: end Nenue@58: Nenue@50: function D.UpdateBeacon(beacon) Nenue@50: local db = D.db Nenue@58: local isActive = (beacon.raised or beacon.selected or beacon.newMessage) Nenue@50: if isActive then Nenue@58: --print(beacon:GetName(), 'active, fade in') Nenue@58: queueFade(beacon, getFadeInArgs('dock_button', beacon)) Nenue@50: end Nenue@58: Nenue@50: if beacon.showName or isActive then Nenue@58: --print(beacon:GetName(), 'show name, fade in name') Nenue@58: queueFade(beacon.caption, getFadeInArgs('dock_button', beacon.caption)) Nenue@50: end Nenue@50: Nenue@50: if not isActive then Nenue@58: queueFade(beacon, getFadeOutArgs('dock_button', beacon)) Nenue@50: end Nenue@58: Nenue@50: if (not beacon.showName) and (not isActive) then Nenue@58: --print(beacon:GetName(), 'no name no active, fade out') Nenue@58: queueFade(beacon.caption,getFadeOutArgs('dock_button', beacon.caption)) Nenue@50: end Nenue@47: end Nenue@47: Nenue@58: local function FrameFade(frame) Nenue@58: if not D.fader then Nenue@58: D.fader = CreateFrame('Frame', 'DevianFaderFrame', UIParent):CreateAnimationGroup('fader'):CreateAnimation('Alpha', 'FadeIn') Nenue@58: end Nenue@58: end Nenue@58: Nenue@58: --- Dock interaction framescript Nenue@47: function D.DockHighlight(beacon) Nenue@47: db = D.db Nenue@47: local self = D.dock Nenue@58: local mouseOverDock = false Nenue@47: if self:IsMouseOver() then Nenue@47: mouseOverDock = true Nenue@47: end Nenue@47: Nenue@58: if beacon then Nenue@58: --print(beacon:GetName(), ' highlighter got beacon') Nenue@47: mouseOverDock = true Nenue@47: if not beacon.raised then Nenue@58: --print(beacon:GetName(), ' beacon not raised') Nenue@47: beacon.raised = true Nenue@50: D.UpdateBeacon(beacon) Nenue@58: Nenue@58: -- IsMouseOver can still return false during its frame's OnEnter Nenue@58: beacon.inc = 0 Nenue@58: beacon:SetScript('OnUpdate', function(self) Nenue@58: if not self:IsMouseOver() then Nenue@58: self.inc = self.inc + 1 Nenue@58: --print(self:GetName(),self.inc) Nenue@58: if self.inc > 10 then Nenue@58: --print(self:GetName(), 'lost mouseover, terminating OnUpdate') Nenue@58: self.raised = nil Nenue@58: D.UpdateBeacon(self) Nenue@58: self:SetScript('OnUpdate', nil) Nenue@58: end Nenue@58: end Nenue@58: end) 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@58: --beacon:SetScript('OnUpdate', nil) Nenue@47: end Nenue@46: Nenue@47: if mouseOverDock then Nenue@50: -- Raise it up Nenue@47: if not self.raised then Nenue@58: Nenue@58: self.raised = true Nenue@58: queueFade(self, getFadeInArgs('dock', self)) Nenue@46: end Nenue@47: elseif self.raised then Nenue@50: -- Drop it down Nenue@47: self.raised = nil Nenue@58: queueFade(self, getFadeOutArgs('dock', self)) Nenue@58: for k, v in pairs(self.buttons) do Nenue@58: v.raised = nil Nenue@58: D.UpdateBeacon(v) Nenue@58: end Nenue@46: end Nenue@47: Nenue@46: end