annotate Dock.lua @ 98:33bc8baba858

start of a lot of v3 groundwork based on better knowledge of the addon interface: - use of mixin as a lexical center for generated frames - removal of unfinished segments
author Nenue
date Wed, 26 Oct 2016 10:17:43 -0400
parents f6fae1a4c66c
children 7d94df3804a7
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@47 9 local db
Nenue@98 10 local print = DEVIAN_WORKSPACE and function(...) print('DvnDock', ...) end or nop
Nenue@93 11 local DOCK_BUTTON_PADDING = 6
Nenue@93 12
Nenue@98 13 DevianDockHandler = {
Nenue@98 14 usedButtons = {},
Nenue@98 15 buttons = {},
Nenue@98 16 }
Nenue@93 17 DevianDockButtonMixin = {}
Nenue@93 18
Nenue@93 19 --- Updates region visibility as needed
Nenue@93 20 local getFadeInArgs = function(sign, region)
Nenue@93 21 --print('Dvn', region)
Nenue@93 22 local db = D.db
Nenue@93 23 local alph = region:GetAlpha()
Nenue@93 24 local a = (db[sign..'_alpha_on'] - alph)
Nenue@93 25 local b = (db[sign..'_alpha_on']-db[sign..'_alpha_off'])
Nenue@93 26 local dur = (a / b) * db[sign..'_fade_in']
Nenue@93 27 return dur, alph, db[sign..'_alpha_on']
Nenue@93 28 end
Nenue@93 29
Nenue@93 30 local getFadeOutArgs = function(sign, region)
Nenue@93 31 local db = D.db
Nenue@93 32 local alph = region:GetAlpha()
Nenue@93 33 local a = (alph - db[sign..'_alpha_off'])
Nenue@93 34 local b = (db[sign..'_alpha_on']-db[sign..'_alpha_off'])
Nenue@93 35 local dur = (a / b) * db[sign..'_fade_out']
Nenue@93 36 return dur, alph, db[sign..'_alpha_off']
Nenue@93 37 end
Nenue@93 38
Nenue@93 39 local function queueFade (self, duration, from, to)
Nenue@93 40 self:SetAlpha(to)
Nenue@93 41 end
Nenue@93 42
Nenue@93 43 local numBeacons = 0
Nenue@98 44 function DevianDockHandler:GetDockButton(console)
Nenue@98 45 self.usedButtons = self.usedButtons or {}
Nenue@98 46 local index = console:GetID()
Nenue@98 47 local button = self.usedButtons[index]
Nenue@93 48 if not button then
Nenue@93 49 numBeacons = numBeacons + 1
Nenue@93 50 button = CreateFrame('Button', 'DevianDockBeacon'.. numBeacons, UIParent, 'DevianBeacon')
Nenue@93 51 button.color = {r = math.random(), g = math.random(), b = math.random()}
Nenue@93 52 button.Stripe:SetColorTexture(button.color.r, button.color.g, button.color.b,1)
Nenue@93 53 button.console = console
Nenue@98 54 self.usedButtons[index] = button
Nenue@98 55 tinsert(self.buttons, button)
Nenue@98 56 --oldprint('create dock', index, console.signature)
Nenue@93 57 end
Nenue@93 58 button.index = console.index
Nenue@93 59 button.caption.name:SetText(console.signature)
Nenue@93 60 button:SetShown(true)
Nenue@93 61 return button
Nenue@93 62 end
Nenue@93 63
Nenue@93 64 function DevianDockButtonMixin:OnMouseDown(button)
Nenue@93 65 --print("click", self:GetName(), button, self.console.index)
Nenue@93 66 if button == "LeftButton" then
Nenue@93 67 if IsShiftKeyDown() then
Nenue@98 68 self.console:Toggle()
Nenue@93 69 else
Nenue@98 70 if self.console.isFront or (not self.console.enabled) then
Nenue@98 71
Nenue@98 72 self.console:Toggle()
Nenue@93 73 if self.console.enabled then
Nenue@93 74 if self.console.minimized then
Nenue@93 75 self.console:MinMax()
Nenue@93 76 end
Nenue@93 77 self.console:ToFront()
Nenue@93 78 end
Nenue@93 79 else
Nenue@93 80 self.console:ToFront()
Nenue@93 81 end
Nenue@93 82 end
Nenue@93 83 elseif button == "RightButton" then
Nenue@93 84 self.console:MinMax()
Nenue@93 85 end
Nenue@93 86 end
Nenue@93 87 function DevianDockButtonMixin:OnShow()
Nenue@93 88 self:Update()
Nenue@93 89 end
Nenue@93 90 function DevianDockButtonMixin:OnEnter()
Nenue@93 91 end
Nenue@93 92 function DevianDockButtonMixin:Update()
Nenue@93 93 local db = D.db
Nenue@93 94 local isActive = (self.raised or self.selected or self.newMessage)
Nenue@93 95
Nenue@93 96 if (self.showName or isActive) then
Nenue@93 97 self.caption:SetAlpha(1)
Nenue@93 98 else
Nenue@93 99 self.caption:SetAlpha(0.5)
Nenue@93 100 end
Nenue@93 101
Nenue@93 102 if self.selected then
Nenue@93 103 self.Background:SetColorTexture(0.4,0.4,0.4,1)
Nenue@93 104 else
Nenue@93 105 self.Background:SetColorTexture(0,0,0,.5)
Nenue@93 106 end
Nenue@93 107
Nenue@93 108 if (not self.showName) and (not isActive) then
Nenue@93 109 --print(self:GetName(), 'no name no active, fade out')
Nenue@93 110 self:SetAlpha(0.5)
Nenue@93 111 else
Nenue@93 112 self:SetAlpha(1)
Nenue@93 113 end
Nenue@93 114
Nenue@93 115 self:SetWidth(self.caption.name:GetStringWidth() + DOCK_BUTTON_PADDING)
Nenue@93 116 end
Nenue@93 117
Nenue@93 118 function DevianDockButtonMixin:Select()
Nenue@93 119 self.caption.pulse:Stop()
Nenue@93 120 self:Update()
Nenue@93 121 end
Nenue@32 122
Nenue@32 123 --- Spaces each frame evenly across the screen.
Nenue@32 124 function D:DistributeFrames() --
Nenue@50 125 local max = self.num_channels
Nenue@50 126 local num_side = ceil(sqrt(max))
Nenue@50 127 local w = GetScreenWidth() / num_side
Nenue@50 128 local h = GetScreenHeight() / num_side
Nenue@50 129 for i, frame in pairs(D.console) do
Nenue@50 130 local dx = (i-1) % num_side
Nenue@50 131 local dy = floor((i-1) / num_side)
Nenue@50 132 frame.width = w
Nenue@50 133 frame.height = h
Nenue@50 134 frame.x = dx * w
Nenue@50 135 frame.y = -(dy * h)
Nenue@50 136 frame:Save()
Nenue@50 137 end
Nenue@32 138 end
Nenue@32 139
Nenue@32 140 --- Place all frames stacked beneath the primary frame.
Nenue@32 141 function D:StackFrames()
Nenue@32 142 local last
Nenue@50 143 for _, frame in pairs(self.console) do
Nenue@32 144 if last then
Nenue@32 145 frame.x = last.x
Nenue@32 146 frame.y = last.y - 20
Nenue@32 147 else
Nenue@32 148 frame.x = (GetScreenWidth()-frame:GetWidth())/2
Nenue@32 149 frame.y = 0
Nenue@32 150 end
Nenue@32 151 frame:Save()
Nenue@32 152 last = frame
Nenue@32 153 end
Nenue@32 154 end
Nenue@32 155
Nenue@98 156 function DevianDockHandler:OnMouseWheel(delta)
Nenue@93 157 if delta >= 1 then
Nenue@98 158 self.dockScale = (self.dockScale or 1) - 0.1
Nenue@93 159 else
Nenue@98 160 self.dockScale = (self.dockScale or 1) + 0.1
Nenue@93 161 end
Nenue@98 162 self:Update()
Nenue@93 163 end
Nenue@32 164
Nenue@50 165 --- Space everything and set the dock size
Nenue@98 166 function DevianDockHandler:Update()
Nenue@47 167 local pad_offset = 12
Nenue@93 168 local drawWidth = 0
Nenue@93 169 local lastButton
Nenue@93 170 local numButtons = 0
Nenue@98 171 for i, d in ipairs(self.buttons) do
Nenue@93 172 if d and d:IsShown() then
Nenue@93 173 d:SetScale(D.dockScale or 1)
Nenue@93 174 if lastButton then
Nenue@93 175 d:SetPoint('TOPLEFT', lastButton, 'TOPRIGHT', pad_offset, 0)
Nenue@93 176 else
Nenue@93 177 d:SetPoint('TOPLEFT', DevianDock, 'TOPLEFT', pad_offset, 0)
Nenue@93 178 end
Nenue@73 179
Nenue@93 180 drawWidth = drawWidth + d:GetWidth() + pad_offset
Nenue@93 181 lastButton = d
Nenue@93 182 numButtons = numButtons + 1
Nenue@93 183 print(numButtons)
Nenue@73 184 end
Nenue@47 185 end
Nenue@93 186 self.numButtons = numButtons
Nenue@98 187 self:SetWidth(drawWidth)
Nenue@98 188
Nenue@98 189 D.db.dockPoint = D.db.dockPoint or 'TOPLEFT'
Nenue@98 190 self:SetPoint(D.db.dockPoint , UIParent, D.db.dockPoint , 0, 0)
Nenue@50 191 end
Nenue@46 192
Nenue@47 193
Nenue@58 194 local function FrameFade(frame)
Nenue@58 195 if not D.fader then
Nenue@58 196 D.fader = CreateFrame('Frame', 'DevianFaderFrame', UIParent):CreateAnimationGroup('fader'):CreateAnimation('Alpha', 'FadeIn')
Nenue@58 197 end
Nenue@46 198 end