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@98: local print = DEVIAN_WORKSPACE and function(...) print('DvnDock', ...) end or nop Nenue@93: local DOCK_BUTTON_PADDING = 6 Nenue@93: Nenue@98: DevianDockHandler = { Nenue@98: usedButtons = {}, Nenue@98: buttons = {}, Nenue@98: } Nenue@93: DevianDockButtonMixin = {} Nenue@93: Nenue@93: --- Updates region visibility as needed Nenue@93: local getFadeInArgs = function(sign, region) Nenue@93: --print('Dvn', region) Nenue@93: local db = D.db Nenue@93: local alph = region:GetAlpha() Nenue@93: local a = (db[sign..'_alpha_on'] - alph) Nenue@93: local b = (db[sign..'_alpha_on']-db[sign..'_alpha_off']) Nenue@93: local dur = (a / b) * db[sign..'_fade_in'] Nenue@93: return dur, alph, db[sign..'_alpha_on'] Nenue@93: end Nenue@93: Nenue@93: local getFadeOutArgs = function(sign, region) Nenue@93: local db = D.db Nenue@93: local alph = region:GetAlpha() Nenue@93: local a = (alph - db[sign..'_alpha_off']) Nenue@93: local b = (db[sign..'_alpha_on']-db[sign..'_alpha_off']) Nenue@93: local dur = (a / b) * db[sign..'_fade_out'] Nenue@93: return dur, alph, db[sign..'_alpha_off'] Nenue@93: end Nenue@93: Nenue@93: local function queueFade (self, duration, from, to) Nenue@93: self:SetAlpha(to) Nenue@93: end Nenue@93: Nenue@93: local numBeacons = 0 Nenue@98: function DevianDockHandler:GetDockButton(console) Nenue@98: self.usedButtons = self.usedButtons or {} Nenue@98: local index = console:GetID() Nenue@98: local button = self.usedButtons[index] Nenue@93: if not button then Nenue@93: numBeacons = numBeacons + 1 Nenue@93: button = CreateFrame('Button', 'DevianDockBeacon'.. numBeacons, UIParent, 'DevianBeacon') Nenue@93: button.color = {r = math.random(), g = math.random(), b = math.random()} Nenue@93: button.Stripe:SetColorTexture(button.color.r, button.color.g, button.color.b,1) Nenue@93: button.console = console Nenue@98: self.usedButtons[index] = button Nenue@98: tinsert(self.buttons, button) Nenue@98: --oldprint('create dock', index, console.signature) Nenue@93: end Nenue@93: button.index = console.index Nenue@93: button.caption.name:SetText(console.signature) Nenue@93: button:SetShown(true) Nenue@93: return button Nenue@93: end Nenue@93: Nenue@93: function DevianDockButtonMixin:OnMouseDown(button) Nenue@93: --print("click", self:GetName(), button, self.console.index) Nenue@93: if button == "LeftButton" then Nenue@93: if IsShiftKeyDown() then Nenue@98: self.console:Toggle() Nenue@93: else Nenue@98: if self.console.isFront or (not self.console.enabled) then Nenue@98: Nenue@98: self.console:Toggle() Nenue@93: if self.console.enabled then Nenue@93: if self.console.minimized then Nenue@93: self.console:MinMax() Nenue@93: end Nenue@93: self.console:ToFront() Nenue@93: end Nenue@93: else Nenue@93: self.console:ToFront() Nenue@93: end Nenue@93: end Nenue@93: elseif button == "RightButton" then Nenue@93: self.console:MinMax() Nenue@93: end Nenue@93: end Nenue@93: function DevianDockButtonMixin:OnShow() Nenue@93: self:Update() Nenue@93: end Nenue@93: function DevianDockButtonMixin:OnEnter() Nenue@93: end Nenue@93: function DevianDockButtonMixin:Update() Nenue@93: local db = D.db Nenue@93: local isActive = (self.raised or self.selected or self.newMessage) Nenue@93: Nenue@93: if (self.showName or isActive) then Nenue@93: self.caption:SetAlpha(1) Nenue@93: else Nenue@93: self.caption:SetAlpha(0.5) Nenue@93: end Nenue@93: Nenue@93: if self.selected then Nenue@93: self.Background:SetColorTexture(0.4,0.4,0.4,1) Nenue@93: else Nenue@93: self.Background:SetColorTexture(0,0,0,.5) Nenue@93: end Nenue@93: Nenue@93: if (not self.showName) and (not isActive) then Nenue@93: --print(self:GetName(), 'no name no active, fade out') Nenue@93: self:SetAlpha(0.5) Nenue@93: else Nenue@93: self:SetAlpha(1) Nenue@93: end Nenue@93: Nenue@93: self:SetWidth(self.caption.name:GetStringWidth() + DOCK_BUTTON_PADDING) Nenue@93: end Nenue@93: Nenue@93: function DevianDockButtonMixin:Select() Nenue@93: self.caption.pulse:Stop() Nenue@93: self:Update() Nenue@93: end 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@98: function DevianDockHandler:OnMouseWheel(delta) Nenue@93: if delta >= 1 then Nenue@98: self.dockScale = (self.dockScale or 1) - 0.1 Nenue@93: else Nenue@98: self.dockScale = (self.dockScale or 1) + 0.1 Nenue@93: end Nenue@98: self:Update() Nenue@93: end Nenue@32: Nenue@50: --- Space everything and set the dock size Nenue@98: function DevianDockHandler:Update() Nenue@47: local pad_offset = 12 Nenue@93: local drawWidth = 0 Nenue@93: local lastButton Nenue@93: local numButtons = 0 Nenue@98: for i, d in ipairs(self.buttons) do Nenue@93: if d and d:IsShown() then Nenue@93: d:SetScale(D.dockScale or 1) Nenue@93: if lastButton then Nenue@93: d:SetPoint('TOPLEFT', lastButton, 'TOPRIGHT', pad_offset, 0) Nenue@93: else Nenue@93: d:SetPoint('TOPLEFT', DevianDock, 'TOPLEFT', pad_offset, 0) Nenue@93: end Nenue@73: Nenue@93: drawWidth = drawWidth + d:GetWidth() + pad_offset Nenue@93: lastButton = d Nenue@93: numButtons = numButtons + 1 Nenue@93: print(numButtons) Nenue@73: end Nenue@47: end Nenue@93: self.numButtons = numButtons Nenue@98: self:SetWidth(drawWidth) Nenue@98: Nenue@98: D.db.dockPoint = D.db.dockPoint or 'TOPLEFT' Nenue@98: self:SetPoint(D.db.dockPoint , UIParent, D.db.dockPoint , 0, 0) Nenue@50: end Nenue@46: 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@46: end