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@47: local db Nenue@32: Nenue@33: local function Dock_MenuClick() end Nenue@32: Nenue@32: local function Dock_MouseDown(self, button, up) 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@33: frame.scriptsMD = frame:GetScript('OnMouseDown') Nenue@33: frame.scriptsMU = frame:GetScript('OnMouseUp') 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: Nenue@46: --- 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@46: Nenue@47: self.dock:SetWidth(draw_offset) Nenue@47: end Nenue@47: Nenue@47: --- Dock interactions Nenue@47: function D.DockHighlight(beacon) Nenue@47: db = D.db Nenue@47: print('Dvn', 'dock mouse event', beacon) Nenue@47: local self = D.dock Nenue@47: local mouseOverDock Nenue@47: --for i, b in pairs(self.buttons) do Nenue@47: --print('polling', i, b:GetName()) Nenue@47: if self:IsMouseOver() then Nenue@47: mouseOverDock = true Nenue@47: end Nenue@47: Nenue@47: Nenue@47: if beacon and beacon:IsMouseOver() then Nenue@47: mouseOverDock = true Nenue@47: --print('mouse is over', i, b:GetName()) Nenue@47: Nenue@47: if not beacon.raised then Nenue@47: beacon.raised = true Nenue@47: local a = (db.dock_button_alpha_on - self:GetAlpha()) Nenue@47: local b = (db.dock_button_alpha_on-db.dock_button_alpha_off) Nenue@47: local dur = (a / b) * db.dock_button_fade_in Nenue@47: print(a, b, db.dock_button_fade_in, dur) Nenue@47: UIFrameFadeIn(beacon, dur,beacon:GetAlpha(),db.dock_button_alpha_on) Nenue@47: UIFrameFadeIn(beacon.caption, dur,beacon:GetAlpha(),1) Nenue@46: end Nenue@47: elseif beacon.raised and beacon.index ~= db.current_channel then Nenue@47: beacon.raised = nil Nenue@47: local a = (self:GetAlpha() - db.dock_button_alpha_off) Nenue@47: local b = (db.dock_button_alpha_on-db.dock_button_alpha_off) Nenue@47: local dur = (a / b) * db.dock_button_fade_out Nenue@47: print(a, b, db.dock_button_fade_in, dur) Nenue@47: UIFrameFadeOut(beacon, dur,beacon:GetAlpha(),db.dock_button_alpha_off) Nenue@47: UIFrameFadeOut(beacon.caption, dur,beacon:GetAlpha(),0) Nenue@47: end Nenue@46: Nenue@47: --end Nenue@47: --end Nenue@47: if mouseOverDock then Nenue@47: if not self.raised then Nenue@47: print('rising') Nenue@47: self.raised = true Nenue@47: local a = (db.dock_alpha_on - self:GetAlpha()) Nenue@47: local b = (db.dock_alpha_on-db.dock_alpha_off) Nenue@47: local dur = (a / b) * db.dock_fade_in Nenue@47: print(a, b, db.dock_fade_in, dur) Nenue@47: UIFrameFadeIn(self, dur,self:GetAlpha(),db.dock_alpha_on) Nenue@46: end Nenue@47: elseif self.raised then Nenue@47: print('dropping') Nenue@47: self.raised = nil Nenue@47: local a = (self:GetAlpha() - db.dock_alpha_off) Nenue@47: local b = (db.dock_alpha_on-db.dock_alpha_off) Nenue@47: local dur = (a / b) * db.dock_fade_out Nenue@47: print(a, b, db.dock_fade_in, dur) Nenue@47: UIFrameFadeOut(self, dur,self:GetAlpha(),db.dock_alpha_off) Nenue@46: end Nenue@47: Nenue@46: end