annotate Dock.lua @ 93:f6fae1a4c66c v2.2.95-rc1

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