Nenue@32: --- ${PACKAGE_NAME} 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@32: -- Dock management functions Nenue@32: Nenue@32: local D = LibStub("AceAddon-3.0"):GetAddon("Devian") Nenue@32: local _G = _G Nenue@32: local db = DevianDB Nenue@32: Nenue@32: Nenue@32: local function Dock_MouseDown(self, button, up) Nenue@32: local parent = self.dockedTo and D.console[self.dockedTo] or self Nenue@32: local docked = parent.docked Nenue@32: if docked == nil then Nenue@32: docked = {} Nenue@32: end Nenue@32: local worklist = {} Nenue@32: for _, i in pairs(docked) do Nenue@32: table.insert(worklist, D.console[i]) Nenue@32: end Nenue@32: Nenue@32: if not up then Nenue@32: if button ~= 'RightButton' then Nenue@32: if parent.titlebar:IsMouseOver() or not parent.isDocked then Nenue@32: parent:ToFront() Nenue@32: else Nenue@32: parent.out:Hide() Nenue@32: end Nenue@32: Nenue@32: if parent.out.grip:IsMouseOver() then Nenue@32: parent:StartSizing() Nenue@32: else Nenue@32: parent:StartMoving() Nenue@32: end Nenue@32: else Nenue@32: parent:MinMax() Nenue@32: end Nenue@32: Nenue@32: else Nenue@32: if button ~= 'RightButton' then Nenue@32: if parent.titlebar:IsMouseOver() then Nenue@32: parent.out:Show() Nenue@32: end Nenue@32: parent:StopMovingOrSizing() Nenue@32: end Nenue@32: end Nenue@32: Nenue@32: local fixparent = true Nenue@32: for _, frame in pairs(worklist) do Nenue@32: if not up then Nenue@32: if button ~= 'RightButton' then Nenue@32: if frame.titlebar:IsMouseOver() then Nenue@32: frame:ToFront() Nenue@32: fixparent = nil Nenue@32: else Nenue@32: frame.out:Hide() Nenue@32: end Nenue@32: if parent.out.grip:IsMouseOver() then Nenue@32: frame:StartSizing() Nenue@32: else Nenue@32: frame:StartMoving() Nenue@32: end Nenue@32: end Nenue@32: else Nenue@32: if button ~= 'RightButton' then Nenue@32: frame:StopMovingOrSizing() Nenue@32: frame:SetPoint('TOPLEFT', parent, 'TOPLEFT') Nenue@32: frame:SetPoint('BOTTOMRIGHT', parent, 'BOTTOMRIGHT') Nenue@32: frame.x = nil Nenue@32: frame.y = nil Nenue@32: frame.width = nil Nenue@32: frame.height = nil Nenue@32: frame:Save() Nenue@32: Nenue@32: end Nenue@32: end Nenue@32: end Nenue@32: Nenue@32: if fixparent then Nenue@32: parent.out:Show() Nenue@32: end Nenue@32: end Nenue@32: local function Dock_MouseUp (self, button) Nenue@32: Dock_MouseDown(self, button, true) Nenue@32: end Nenue@32: Nenue@32: --- Adjusts frame element alignments Nenue@32: local function PrepareForDock (frame, draw_x) Nenue@32: frame.left:SetPoint('TOPLEFT', frame.out, 'TOPLEFT', -2, 0) Nenue@32: frame.left:SetPoint('BOTTOMRIGHT', frame.out, 'BOTTOMLEFT', 0, 0) Nenue@32: frame.topleft:SetPoint('BOTTOMRIGHT', frame.out, 'TOPLEFT', 0, 0) Nenue@32: frame.top: SetPoint('TOPLEFT', frame.out, 'TOPLEFT', 0, 2) Nenue@32: frame.top:SetPoint('BOTTOMRIGHT', frame.out, 'TOPRIGHT', 0, 0) Nenue@32: frame.topright:SetPoint('BOTTOMLEFT', frame.out, 'TOPRIGHT', 0, 0) Nenue@32: frame.right:SetPoint('TOPLEFT', frame.out, 'TOPRIGHT', 0, 0) Nenue@32: frame.header:SetWidth(frame.header:GetStringWidth() * 1.2) Nenue@32: frame.header:SetPoint('TOPLEFT', frame, 'TOPLEFT', draw_x+4, 0) Nenue@32: frame.titlebar:SetPoint('TOPLEFT', frame.header, 'TOPLEFT', -4, 0) Nenue@32: frame.titlebar:SetPoint('TOPRIGHT', frame.header, 'TOPRIGHT', 0, 0) Nenue@32: Nenue@32: return (draw_x + frame.header:GetStringWidth() * 1.2 + 4) Nenue@32: end Nenue@32: Nenue@32: Nenue@32: --- Docks frames together Nenue@32: -- @param target frame on which to dock Nenue@32: -- @param ... frame objects to be docked Nenue@32: -- Nenue@32: function D:DockFrame(...) Nenue@32: local target = D.console[select(1,...)] Nenue@32: if target.dockedTo then Nenue@32: local t = D.c[target.dockedTo] Nenue@32: print('channel',target.index,target.signature, 'is docked to',t.index, t.signature..'. using that instead') Nenue@32: target = D.console[target.DockedTo] Nenue@32: end Nenue@32: Nenue@32: target.docked = {} Nenue@32: local draw_x = PrepareForDock(target, 4) Nenue@32: for i = 2, select('#', ...) do Nenue@32: local frame = D.console[select(i, ...)] Nenue@32: frame.dockedTo = target.index Nenue@32: width, draw_x = MorphToDock (frame, draw_x) Nenue@32: table.insert(target.docked, frame.index) Nenue@32: frame:ClearAllPoints() Nenue@32: frame:SetPoint('TOPLEFT', target, 'TOPLEFT', 0, 0) Nenue@32: frame:SetSize(target:GetWidth(), target:GetHeight()) Nenue@32: frame.x = nil Nenue@32: frame.y = nil Nenue@32: frame.width = nil Nenue@32: frame.height = nil Nenue@32: frame.oldscript = frame:GetScript('OnMousedown') Nenue@32: frame:SetScript('OnMouseDown', nil) Nenue@32: frame:SetScript('OnMouseUp', nil) Nenue@32: frame:Save() Nenue@32: end Nenue@32: end Nenue@32: Nenue@32: --- Spaces each frame evenly across the screen. Nenue@32: function D:DistributeFrames() -- Nenue@32: --print('frame grid:', max, num_side) Nenue@32: local max = self.num_channels Nenue@32: local num_side = math.ceil(math.sqrt(max)) Nenue@32: local w = GetScreenWidth() / num_side Nenue@32: local h = GetScreenHeight() / num_side Nenue@32: for i, frame in pairs(D.console) do Nenue@32: local dx = (i-1) % num_side Nenue@32: local dy = math.floor((i-1) / num_side) Nenue@32: Nenue@32: --print('move:', frame.signature, 'dx=', dx, 'dy=', dy) Nenue@32: --print('move:', frame.signature, ' x=', dx * w, 'y=', -(dy * h), 'h=', h, 'w=', w) Nenue@32: frame.width = w Nenue@32: frame.height = h Nenue@32: frame.x = dx * w Nenue@32: frame.y = -(dy * h) Nenue@32: frame:Save() Nenue@32: end Nenue@32: 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@32: for i, 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: