annotate Dock.lua @ 99:7d94df3804a7

- Console drag buttons for resizing - While dragging a console frame, other frames are ghosted out - Dropdown menu includes Toggle, Pin, and MinMax
author Nenue
date Thu, 27 Oct 2016 06:11:04 -0400
parents 33bc8baba858
children 790dca545f1d
rev   line source
Nenue@50 1 --- Devian - Dock.lua
Nenue@32 2 -- @file-author@
Nenue@32 3 -- @project-revision@ @project-hash@
Nenue@32 4 -- @file-revision@ @file-hash@
Nenue@32 5 -- Created: 12/26/2015 12:32 PM
Nenue@50 6 -- Docking and arrangement calls
Nenue@66 7 local _, D = ...
Nenue@50 8 local ceil, floor, sqrt, pairs, GetScreenWidth, GetScreenHeight = math.ceil, math.floor, math.sqrt, pairs, GetScreenWidth, GetScreenHeight
Nenue@99 9
Nenue@99 10 local CreateFrame, tinsert, random = CreateFrame, tinsert, math.random
Nenue@99 11 local ipairs, pairs = ipairs, pairs
Nenue@47 12 local db
Nenue@98 13 local print = DEVIAN_WORKSPACE and function(...) print('DvnDock', ...) end or nop
Nenue@93 14 local DOCK_BUTTON_PADDING = 6
Nenue@93 15
Nenue@98 16 DevianDockHandler = {
Nenue@98 17 usedButtons = {},
Nenue@98 18 buttons = {},
Nenue@98 19 }
Nenue@99 20 DevianDockTabMixin = {}
Nenue@93 21
Nenue@99 22 function DevianDockTabMixin:OnMouseDown(button)
Nenue@93 23 --print("click", self:GetName(), button, self.console.index)
Nenue@93 24 if button == "LeftButton" then
Nenue@93 25 if IsShiftKeyDown() then
Nenue@98 26 self.console:Toggle()
Nenue@93 27 else
Nenue@98 28 if self.console.isFront or (not self.console.enabled) then
Nenue@98 29
Nenue@98 30 self.console:Toggle()
Nenue@93 31 if self.console.enabled then
Nenue@93 32 if self.console.minimized then
Nenue@93 33 self.console:MinMax()
Nenue@93 34 end
Nenue@93 35 self.console:ToFront()
Nenue@93 36 end
Nenue@93 37 else
Nenue@93 38 self.console:ToFront()
Nenue@93 39 end
Nenue@93 40 end
Nenue@93 41 elseif button == "RightButton" then
Nenue@93 42 self.console:MinMax()
Nenue@93 43 end
Nenue@93 44 end
Nenue@99 45 function DevianDockTabMixin:OnShow()
Nenue@93 46 self:Update()
Nenue@93 47 end
Nenue@99 48 function DevianDockTabMixin:OnEnter()
Nenue@93 49 end
Nenue@99 50 function DevianDockTabMixin:Update()
Nenue@93 51 local db = D.db
Nenue@93 52 local isActive = (self.raised or self.selected or self.newMessage)
Nenue@93 53
Nenue@93 54 if (self.showName or isActive) then
Nenue@93 55 self.caption:SetAlpha(1)
Nenue@93 56 else
Nenue@93 57 self.caption:SetAlpha(0.5)
Nenue@93 58 end
Nenue@93 59
Nenue@93 60 if self.selected then
Nenue@93 61 self.Background:SetColorTexture(0.4,0.4,0.4,1)
Nenue@93 62 else
Nenue@93 63 self.Background:SetColorTexture(0,0,0,.5)
Nenue@93 64 end
Nenue@93 65
Nenue@93 66 if (not self.showName) and (not isActive) then
Nenue@93 67 --print(self:GetName(), 'no name no active, fade out')
Nenue@93 68 self:SetAlpha(0.5)
Nenue@93 69 else
Nenue@93 70 self:SetAlpha(1)
Nenue@93 71 end
Nenue@93 72
Nenue@93 73 self:SetWidth(self.caption.name:GetStringWidth() + DOCK_BUTTON_PADDING)
Nenue@93 74 end
Nenue@93 75
Nenue@99 76 function DevianDockTabMixin:Select()
Nenue@93 77 self.caption.pulse:Stop()
Nenue@93 78 self:Update()
Nenue@93 79 end
Nenue@32 80
Nenue@32 81 --- Spaces each frame evenly across the screen.
Nenue@32 82 function D:DistributeFrames() --
Nenue@50 83 local max = self.num_channels
Nenue@50 84 local num_side = ceil(sqrt(max))
Nenue@50 85 local w = GetScreenWidth() / num_side
Nenue@50 86 local h = GetScreenHeight() / num_side
Nenue@50 87 for i, frame in pairs(D.console) do
Nenue@50 88 local dx = (i-1) % num_side
Nenue@50 89 local dy = floor((i-1) / num_side)
Nenue@50 90 frame.width = w
Nenue@50 91 frame.height = h
Nenue@50 92 frame.x = dx * w
Nenue@50 93 frame.y = -(dy * h)
Nenue@50 94 frame:Save()
Nenue@50 95 end
Nenue@32 96 end
Nenue@32 97
Nenue@32 98 --- Place all frames stacked beneath the primary frame.
Nenue@32 99 function D:StackFrames()
Nenue@32 100 local last
Nenue@50 101 for _, frame in pairs(self.console) do
Nenue@32 102 if last then
Nenue@32 103 frame.x = last.x
Nenue@32 104 frame.y = last.y - 20
Nenue@32 105 else
Nenue@32 106 frame.x = (GetScreenWidth()-frame:GetWidth())/2
Nenue@32 107 frame.y = 0
Nenue@32 108 end
Nenue@32 109 frame:Save()
Nenue@32 110 last = frame
Nenue@32 111 end
Nenue@32 112 end
Nenue@32 113
Nenue@99 114
Nenue@99 115 do
Nenue@99 116 local numBeacons = 0
Nenue@99 117 function DevianDockHandler:GetDockButton(console)
Nenue@99 118 self.usedButtons = self.usedButtons or {}
Nenue@99 119 local index = console:GetID()
Nenue@99 120 local button = self.usedButtons[index]
Nenue@99 121 if not button then
Nenue@99 122 numBeacons = numBeacons + 1
Nenue@99 123 button = CreateFrame('Button', 'DevianDockBeacon'.. numBeacons, UIParent, 'DevianDockTabTemplate')
Nenue@99 124 button.color = {r = random(), g = random(), b = random()}
Nenue@99 125 button.Stripe:SetColorTexture(button.color.r, button.color.g, button.color.b,1)
Nenue@99 126 button.console = console
Nenue@99 127 self.usedButtons[index] = button
Nenue@99 128 tinsert(self.buttons, button)
Nenue@99 129 --oldprint('create dock', index, console.signature)
Nenue@99 130 end
Nenue@99 131 button.index = console.index
Nenue@99 132 button.caption.name:SetText(console.signature)
Nenue@99 133 button:SetShown(true)
Nenue@99 134 return button
Nenue@99 135 end
Nenue@99 136 end
Nenue@99 137
Nenue@98 138 function DevianDockHandler:OnMouseWheel(delta)
Nenue@93 139 if delta >= 1 then
Nenue@98 140 self.dockScale = (self.dockScale or 1) - 0.1
Nenue@93 141 else
Nenue@98 142 self.dockScale = (self.dockScale or 1) + 0.1
Nenue@93 143 end
Nenue@98 144 self:Update()
Nenue@93 145 end
Nenue@32 146
Nenue@50 147 --- Space everything and set the dock size
Nenue@98 148 function DevianDockHandler:Update()
Nenue@47 149 local pad_offset = 12
Nenue@93 150 local drawWidth = 0
Nenue@93 151 local lastButton
Nenue@93 152 local numButtons = 0
Nenue@98 153 for i, d in ipairs(self.buttons) do
Nenue@93 154 if d and d:IsShown() then
Nenue@93 155 d:SetScale(D.dockScale or 1)
Nenue@93 156 if lastButton then
Nenue@93 157 d:SetPoint('TOPLEFT', lastButton, 'TOPRIGHT', pad_offset, 0)
Nenue@93 158 else
Nenue@93 159 d:SetPoint('TOPLEFT', DevianDock, 'TOPLEFT', pad_offset, 0)
Nenue@93 160 end
Nenue@73 161
Nenue@93 162 drawWidth = drawWidth + d:GetWidth() + pad_offset
Nenue@93 163 lastButton = d
Nenue@93 164 numButtons = numButtons + 1
Nenue@93 165 print(numButtons)
Nenue@73 166 end
Nenue@47 167 end
Nenue@93 168 self.numButtons = numButtons
Nenue@98 169 self:SetWidth(drawWidth)
Nenue@98 170
Nenue@98 171 D.db.dockPoint = D.db.dockPoint or 'TOPLEFT'
Nenue@98 172 self:SetPoint(D.db.dockPoint , UIParent, D.db.dockPoint , 0, 0)
Nenue@50 173 end