annotate UI.lua @ 47:eb7544afd77a

dock frame implementation fixes to /dvc command
author Nenue
date Mon, 04 Jan 2016 05:42:44 -0500
parents 5341e4d84622
children c3166f700438
rev   line source
Nenue@35 1 --- ${PACKAGE_NAME}
Nenue@35 2 -- @file-author@
Nenue@35 3 -- @project-revision@ @project-hash@
Nenue@35 4 -- @file-revision@ @file-hash@
Nenue@35 5 -- Created: 12/27/2015 3:01 AM
Nenue@35 6
Nenue@35 7
Nenue@35 8 if not LibStub then
Nenue@35 9 print('Something has happened...')
Nenue@35 10 end
Nenue@35 11 local D = LibStub("AceAddon-3.0"):GetAddon("Devian")
Nenue@35 12
Nenue@35 13
Nenue@35 14
Nenue@35 15 local DEVIAN_FRAME = 'DevianConsole'
Nenue@47 16 local DEVIAN_DOCK_FRAME = 'DevianDock'
Nenue@35 17
Nenue@35 18
Nenue@35 19 local function Console_MinMax(self)
Nenue@35 20 if self.minimized then
Nenue@35 21 self:Maximize()
Nenue@35 22 else
Nenue@35 23 self:Minimize()
Nenue@35 24 end
Nenue@35 25 end
Nenue@35 26
Nenue@35 27 local function Console_Minimize(self)
Nenue@35 28 self:SetHeight(20)
Nenue@35 29 self:SetMaxResize(GetScreenWidth(),20)
Nenue@35 30 self.minimized = true
Nenue@35 31 self.out:Hide()
Nenue@35 32 self:Save()
Nenue@35 33 end
Nenue@35 34
Nenue@35 35 local function Console_Maximize(self)
Nenue@35 36 local db = D.channels[self.index]
Nenue@35 37 self:SetHeight(db.height)
Nenue@35 38 self:SetMaxResize(GetScreenWidth(),GetScreenHeight())
Nenue@35 39 self.minimized = nil
Nenue@35 40 self.out:Show()
Nenue@35 41 self:Save()
Nenue@35 42 end
Nenue@35 43
Nenue@35 44
Nenue@35 45 local function Console_Save(self)
Nenue@35 46 local db = D.channels[self.index]
Nenue@35 47 if self.x then
Nenue@35 48 db.x = self.x
Nenue@35 49 else
Nenue@35 50 db.x = self:GetLeft()
Nenue@35 51 end
Nenue@35 52
Nenue@35 53 if self.y then
Nenue@35 54 db.y = self.y
Nenue@35 55 else
Nenue@35 56 db.y = (self:GetTop() - GetScreenHeight())
Nenue@35 57 end
Nenue@35 58
Nenue@35 59 if self.width then
Nenue@35 60 db.width = self.width
Nenue@35 61 else
Nenue@35 62 db.width = self:GetWidth()
Nenue@35 63 end
Nenue@35 64
Nenue@35 65 if not self.minimized then
Nenue@35 66 if self.height then
Nenue@35 67 db.height = self.height
Nenue@35 68 else
Nenue@35 69 db.height = self:GetHeight()
Nenue@35 70 end
Nenue@35 71 self:SetHeight(db.height)
Nenue@35 72 end
Nenue@35 73
Nenue@35 74 db.dockedTo = self.dockedTo
Nenue@35 75 db.docked = self.docked
Nenue@35 76
Nenue@35 77 db.minimized = self.minimized and true or nil
Nenue@35 78 db.enabled = self:IsVisible() and true or nil
Nenue@35 79 db.active = self.active and true or nil
Nenue@35 80 --print('save:', db.signature, 'min=', db.minimized, ' enabled=', db.enabled, ' active = ', db.active, 'x=', db.x, 'y=', db.y, 'h=', db.height, 'w=', db.width)
Nenue@35 81 self:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', db.x, db.y)
Nenue@35 82 self:SetWidth(db.width)
Nenue@35 83 end
Nenue@35 84
Nenue@35 85 --- Brings the console to the front.
Nenue@35 86 -- Frame method used to bring a console frame to the front of the display stack.
Nenue@35 87 local function Console_ToFront(c)
Nenue@35 88 local db = D.db
Nenue@35 89 --print(D.raise_ct, 'Raising', c.signature)
Nenue@35 90 --print(unpack(db.frontdrop))
Nenue@35 91 --print(unpack(db.frontgrad))
Nenue@35 92 --print(db.frontblend)
Nenue@35 93 -- D.raise_ct = D.raise_ct + 1
Nenue@35 94 c:Raise()
Nenue@35 95 c:SetAlpha(db.frontalpha)
Nenue@35 96 c.out.backdrop:SetTexture(unpack(db.frontdrop))
Nenue@35 97 c.out.backdrop:SetGradientAlpha(unpack(db.frontgrad))
Nenue@35 98 c.out.backdrop:SetBlendMode(db.frontblend)
Nenue@45 99 c.dropmenu.icon:SetVertexColor(unpack(db.frontheader))
Nenue@45 100 c.title:SetTextColor(unpack(db.frontborder))
Nenue@35 101 db.current_channel = c.index
Nenue@35 102
Nenue@35 103 for _, part in pairs(c.border) do
Nenue@35 104 part:SetTexture(unpack(db.frontborder))
Nenue@35 105 end
Nenue@35 106
Nenue@35 107 for id, bc in pairs(D.console) do
Nenue@35 108 if id ~= c.index then
Nenue@35 109 --print(D.raise_ct, 'Lowering', bc.signature)
Nenue@35 110 --print(unpack(db.backdrop))
Nenue@35 111 --print(unpack(db.backgrad))
Nenue@35 112 --print(db.backblend)
Nenue@35 113 bc:SetAlpha(db.backalpha)
Nenue@35 114 bc.out.backdrop:SetTexture(unpack(db.backdrop))
Nenue@35 115 bc.out.backdrop:SetGradientAlpha(unpack(db.backgrad))
Nenue@35 116 bc.out.backdrop:SetBlendMode(db.backblend)
Nenue@45 117 bc.dropmenu.icon:SetVertexColor(unpack(db.backheader))
Nenue@36 118 bc.title:SetTextColor(unpack(db.backborder))
Nenue@35 119
Nenue@35 120 for _, part in pairs(bc.border) do
Nenue@35 121 part:SetTexture(unpack(db.backborder))
Nenue@35 122 end
Nenue@35 123 end
Nenue@35 124 end
Nenue@35 125 end
Nenue@35 126
Nenue@35 127 local function Console_MouseDown(self, button, up)
Nenue@35 128 if button == 'LeftButton' then
Nenue@35 129 if up then
Nenue@35 130 self:StopMovingOrSizing()
Nenue@35 131 self:ToFront()
Nenue@35 132 self.x = nil
Nenue@35 133 self.y = nil
Nenue@35 134 self.width = nil
Nenue@35 135 self.height = nil
Nenue@35 136 self:Save()
Nenue@35 137 elseif self.out.grip:IsMouseOver() then
Nenue@35 138 self:StartSizing()
Nenue@35 139 else
Nenue@35 140 self:StartMoving()
Nenue@35 141 end
Nenue@35 142 else
Nenue@35 143 if up then
Nenue@35 144 self:MinMax()
Nenue@35 145 end
Nenue@35 146 end
Nenue@35 147 end
Nenue@35 148 local function Console_MouseUp(self, button)
Nenue@35 149 return Console_MouseDown(self, button, true)
Nenue@35 150 end
Nenue@35 151
Nenue@35 152
Nenue@35 153 --- Constructs the frame object for a console channel
Nenue@35 154 -- Initializes the console channel at a specified index.
Nenue@35 155 -- Configuration data can be overridden by passing a desired settings table.
Nenue@35 156 -- @param i Numeric index of the channel as it manifests in db.channels
Nenue@35 157 -- @param vars Optional settings table to be used.
Nenue@35 158 local function CreateConsole(i, vars)
Nenue@35 159 local db = D.db
Nenue@35 160 if tonumber(i) == nil or math.floor(i) ~= i then
Nenue@35 161 error('Non-integer index value.')
Nenue@35 162 end
Nenue@35 163 if not vars then
Nenue@35 164 vars = D.channels[i] and D.channels[i] or D.channels[db.primary_channel]
Nenue@35 165 end
Nenue@35 166 local f
Nenue@47 167 f= CreateFrame('Frame', 'DevianChannelFrame' .. i, UIParent, DEVIAN_FRAME)
Nenue@47 168
Nenue@35 169 --@debug@
Nenue@35 170 --print(f:GetName())
Nenue@35 171
Nenue@35 172 --print('create(2)')
Nenue@35 173 for k,v in pairs(vars) do
Nenue@35 174 f[k] = v
Nenue@35 175 --@debug@
Nenue@36 176 --print(' f['..type(k)..' '..tostring(k)..'] = '..type(v)..' '..tostring(v))
Nenue@35 177 end
Nenue@35 178
Nenue@35 179 f:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', vars.x, vars.y)
Nenue@35 180 f:SetSize(vars.width, vars.height)
Nenue@35 181 f:Lower()
Nenue@35 182 f.out:SetFont(db.font, db.fontsize, db.fontoutline)
Nenue@35 183 if (db.current_channel == i) then
Nenue@35 184 f.out.backdrop:SetTexture(unpack(db.frontdrop))
Nenue@36 185 f.dropmenu.icon:SetVertexColor(unpack(db.headerfontcolor))
Nenue@36 186 f.title:SetTextColor(unpack(db.headerfontcolor))
Nenue@45 187 f.header:SetAlpha(db.headeralpha)
Nenue@35 188 else
Nenue@35 189 f.out.backdrop:SetTexture(unpack(db.backdrop))
Nenue@35 190 end
Nenue@35 191
Nenue@35 192 f.Save = Console_Save
Nenue@35 193 f.Minimize = Console_Minimize
Nenue@35 194 f.Maximize = Console_Maximize
Nenue@35 195 f.MinMax = Console_MinMax
Nenue@35 196 f.ToFront = Console_ToFront
Nenue@35 197 f.Toggle = D.Console_Toggle
Nenue@35 198 f:SetScript('OnMouseDown', Console_MouseDown)
Nenue@35 199 f:SetScript('OnMouseUp', Console_MouseUp)
Nenue@35 200
Nenue@36 201
Nenue@36 202 UIDropDownMenu_Initialize(f.menuFrame, function()
Nenue@36 203 local info = { {
Nenue@36 204 text= "Close",
Nenue@36 205 value = "OptClose",
Nenue@36 206 func = function ()
Nenue@36 207 f.enabled = nil
Nenue@36 208 f:Hide()
Nenue@36 209 f:Save()
Nenue@38 210 end },--[[
Nenue@36 211 {
Nenue@36 212 text = "Dock",
Nenue@36 213 value = "OptDock",
Nenue@38 214 func = function() print('Dvn', 'docking shenanary') end }]]
Nenue@36 215 }
Nenue@36 216 for _, v in ipairs(info) do
Nenue@36 217 UIDropDownMenu_AddButton(v)
Nenue@36 218 end
Nenue@36 219 end, 'MENU')
Nenue@36 220
Nenue@47 221 D.dock.buttons[i] = CreateFrame('Button', 'Channel'..i..'Beacon', UIParent, 'DevianBeacon')
Nenue@47 222 D.dock.buttons[i].icon:SetVertexColor(math.random(),math.random(),math.random())
Nenue@47 223 D.dock.buttons[i].console = f
Nenue@47 224 D.dock.buttons[i].index = i
Nenue@47 225 D.dock.buttons[i].caption.name:SetText(vars.signature)
Nenue@47 226 D.dock.buttons[i]:Show()
Nenue@47 227
Nenue@35 228 if vars.minimized then
Nenue@35 229 f:Minimize()
Nenue@35 230 else
Nenue@35 231 f:Maximize()
Nenue@35 232 end
Nenue@35 233 if db.enabled and f.enabled then
Nenue@35 234 f:Show()
Nenue@35 235 end
Nenue@35 236
Nenue@35 237 return f
Nenue@35 238 end
Nenue@35 239
Nenue@35 240
Nenue@35 241 --- Updates console information and returns the handle of the channel object that was worked on.
Nenue@35 242 -- When key is nil or not a valid handle, a new channel is created using whatever signature can be found in cinfo.
Nenue@35 243 -- The signature can be passed as a string, or as a table entry under the key 'signature'
Nenue@35 244 -- If the signature of a new channel is also a tag, the channel will be added to that tag
Nenue@35 245 -- @param cinfo string signature of a new channel, or a table of config variables to be imposed on the channel
Nenue@35 246 -- @param key string signature or index number of channel to operate on
Nenue@35 247 -- @usage channel = D:SetChannel('new', nil) -- creates a new channel
Nenue@35 248 -- @usage channel = D:SetChannel({x = 200, y = 100}, 4) -- updates channel #4
Nenue@35 249 function D:SetChannel(cinfo, key)
Nenue@35 250 local db = self.db
Nenue@35 251 local t_info = {}
Nenue@35 252 local channel, isNew, id, sig, t_id
Nenue@36 253 --@debug@
Nenue@38 254 --print('setchan(0) cinfo, key', cinfo, key)--@end-debug@
Nenue@35 255 -- obtain source data
Nenue@35 256 if tonumber(key) ~= nil and db.channels[key] then
Nenue@35 257 id = tonumber(key)
Nenue@35 258 elseif D.sigID[tostring(key)] then
Nenue@35 259 id = D.sigID[tostring(key)]
Nenue@35 260 else
Nenue@35 261 id = db.primary_channel
Nenue@35 262 isNew = true
Nenue@35 263 end
Nenue@35 264 local dbvars = db.channels[id]
Nenue@35 265 t_id = id -- overridden later if new
Nenue@35 266 t_info.index = t_id --
Nenue@35 267 --@debug@
Nenue@38 268 --print('setchan(1) cinfo, key, id=', cinfo, key, id)--@end-debug@
Nenue@35 269
Nenue@35 270
Nenue@35 271 -- obtain config info
Nenue@35 272 if type(cinfo) == 'string' then
Nenue@35 273 sig = cinfo
Nenue@35 274 cinfo = {signature = sig}
Nenue@35 275 elseif type(cinfo) ~= 'table' then -- stop here if a table wans't passed
Nenue@35 276 error('Expecting table of string as arg1')
Nenue@35 277 elseif cinfo.signature then -- new sig
Nenue@35 278 sig = cinfo.signature
Nenue@35 279 elseif isNew then -- new channel sig
Nenue@35 280 sig = 'Ch'
Nenue@35 281 else -- old sig
Nenue@35 282 sig = db.channels[id].signature
Nenue@35 283 end
Nenue@35 284 t_info.signature = sig
Nenue@35 285 --@debug@
Nenue@38 286 --print('setchan(2) sig,id,isNew=', sig, id, isNew)--@end-debug@
Nenue@35 287
Nenue@35 288 for k,v in pairs(cinfo) do -- allow all cinfo to pass
Nenue@35 289 t_info[k] = v
Nenue@35 290 end
Nenue@35 291
Nenue@35 292 local blocked = { -- ignore these vars:
Nenue@35 293 ['docked'] = true, -- table
Nenue@35 294 ['dockedTo'] = true, -- table-related
Nenue@35 295 ['signature'] = true} -- already determined
Nenue@35 296 for k,v in pairs(dbvars) do
Nenue@35 297 if not t_info[k] and not blocked[k] then -- already set or blocked?
Nenue@35 298 t_info[k] = v
Nenue@35 299 end
Nenue@35 300 end
Nenue@35 301 -- new channel overrides
Nenue@35 302 if isNew then
Nenue@35 303 if D.sigID[sig]then -- find a non-clashing signature
Nenue@35 304 local result, i = sig, 1
Nenue@35 305 while D.sigID[result] do
Nenue@35 306 result = sig .. i
Nenue@35 307 i = i + 1
Nenue@35 308 end
Nenue@35 309 t_info.signature = result
Nenue@35 310 end
Nenue@36 311 t_id = self.max_channel + 1
Nenue@35 312 t_info.index = t_id
Nenue@35 313 --@debug@
Nenue@38 314 --print('setchan(3a) t_id, isNew, sig, t_info.signature=', t_id, isNew, sig, t_info.signature)--@end-debug@
Nenue@35 315 else
Nenue@35 316 --@debug@
Nenue@38 317 --print('setchan(3b) t_id, isNew, sig, t_info.signature=', t_id, isNew, sig, t_info.signature)--@end-debug@
Nenue@35 318 end
Nenue@35 319
Nenue@35 320 local channel
Nenue@35 321 if not self.console[t_id] then -- create a frame
Nenue@35 322 if isNew then -- position the channel frame
Nenue@36 323 self.max_channel = t_id
Nenue@36 324 db.max_channel = t_id
Nenue@36 325 t_info.x = t_info.x + 20
Nenue@36 326 t_info.y = t_info.y - 20
Nenue@36 327 db.channels[t_id] = t_info
Nenue@36 328 --@debug@
Nenue@38 329 --print('setchan(4a)', 't_id, x, y=', t_id, t_info.x, t_info.y)--@end-debug@
Nenue@35 330 end
Nenue@35 331 channel = CreateConsole(t_id, t_info)
Nenue@35 332 self.console[t_id] = channel
Nenue@35 333 self.sig[t_info.signature] = channel
Nenue@35 334 self.sigID[t_info.signature] = t_id
Nenue@35 335 self.IDsig[t_id] = t_info.signature
Nenue@35 336
Nenue@35 337 end
Nenue@35 338 channel = self.console[t_id]
Nenue@35 339 if channel.minimized then
Nenue@35 340 channel:Minimize()
Nenue@35 341 else
Nenue@35 342 channel:Maximize()
Nenue@35 343 end
Nenue@35 344
Nenue@35 345 if channel.enabled and db.enabled then -- hide or show last since Min/Max mess with visibility
Nenue@38 346 --print('setchan(5a) enable')
Nenue@35 347 channel:Show()
Nenue@45 348 channel:ToFront()
Nenue@35 349 else
Nenue@38 350 --print('setchan(5a) disable')
Nenue@35 351 channel:Hide()
Nenue@35 352 end
Nenue@35 353 --@debug@
Nenue@35 354 --print('setchan(end); c:IsVisible(), c.enabled, db.enabled=', channel:IsVisible(), channel.enabled, db.enabled)--@end-debug@
Nenue@35 355 return channel
Nenue@35 356 end