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@99: Nenue@99: local CreateFrame, tinsert, random = CreateFrame, tinsert, math.random Nenue@99: local ipairs, pairs = ipairs, pairs 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@99: DevianDockTabMixin = {} Nenue@93: Nenue@99: function DevianDockTabMixin: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@99: function DevianDockTabMixin:OnShow() Nenue@93: self:Update() Nenue@93: end Nenue@99: function DevianDockTabMixin:OnEnter() Nenue@93: end Nenue@99: function DevianDockTabMixin: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@99: function DevianDockTabMixin: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@99: Nenue@99: do Nenue@99: local numBeacons = 0 Nenue@99: function DevianDockHandler:GetDockButton(console) Nenue@99: self.usedButtons = self.usedButtons or {} Nenue@99: local index = console:GetID() Nenue@99: local button = self.usedButtons[index] Nenue@99: if not button then Nenue@99: numBeacons = numBeacons + 1 Nenue@99: button = CreateFrame('Button', 'DevianDockBeacon'.. numBeacons, UIParent, 'DevianDockTabTemplate') Nenue@99: button.color = {r = random(), g = random(), b = random()} Nenue@99: button.Stripe:SetColorTexture(button.color.r, button.color.g, button.color.b,1) Nenue@99: button.console = console Nenue@99: self.usedButtons[index] = button Nenue@99: tinsert(self.buttons, button) Nenue@99: --oldprint('create dock', index, console.signature) Nenue@99: end Nenue@99: button.index = console.index Nenue@99: button.caption.name:SetText(console.signature) Nenue@99: button:SetShown(true) Nenue@99: return button Nenue@99: end Nenue@99: end Nenue@99: 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