annotate Dock.lua @ 32:c6a2c2df4790

v2 work
author Nenue
date Sat, 26 Dec 2015 21:51:57 -0500
parents
children e6650821a2c0
rev   line source
Nenue@32 1 --- ${PACKAGE_NAME}
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@32 6 -- Dock management functions
Nenue@32 7
Nenue@32 8 local D = LibStub("AceAddon-3.0"):GetAddon("Devian")
Nenue@32 9 local _G = _G
Nenue@32 10 local db = DevianDB
Nenue@32 11
Nenue@32 12
Nenue@32 13 local function Dock_MouseDown(self, button, up)
Nenue@32 14 local parent = self.dockedTo and D.console[self.dockedTo] or self
Nenue@32 15 local docked = parent.docked
Nenue@32 16 if docked == nil then
Nenue@32 17 docked = {}
Nenue@32 18 end
Nenue@32 19 local worklist = {}
Nenue@32 20 for _, i in pairs(docked) do
Nenue@32 21 table.insert(worklist, D.console[i])
Nenue@32 22 end
Nenue@32 23
Nenue@32 24 if not up then
Nenue@32 25 if button ~= 'RightButton' then
Nenue@32 26 if parent.titlebar:IsMouseOver() or not parent.isDocked then
Nenue@32 27 parent:ToFront()
Nenue@32 28 else
Nenue@32 29 parent.out:Hide()
Nenue@32 30 end
Nenue@32 31
Nenue@32 32 if parent.out.grip:IsMouseOver() then
Nenue@32 33 parent:StartSizing()
Nenue@32 34 else
Nenue@32 35 parent:StartMoving()
Nenue@32 36 end
Nenue@32 37 else
Nenue@32 38 parent:MinMax()
Nenue@32 39 end
Nenue@32 40
Nenue@32 41 else
Nenue@32 42 if button ~= 'RightButton' then
Nenue@32 43 if parent.titlebar:IsMouseOver() then
Nenue@32 44 parent.out:Show()
Nenue@32 45 end
Nenue@32 46 parent:StopMovingOrSizing()
Nenue@32 47 end
Nenue@32 48 end
Nenue@32 49
Nenue@32 50 local fixparent = true
Nenue@32 51 for _, frame in pairs(worklist) do
Nenue@32 52 if not up then
Nenue@32 53 if button ~= 'RightButton' then
Nenue@32 54 if frame.titlebar:IsMouseOver() then
Nenue@32 55 frame:ToFront()
Nenue@32 56 fixparent = nil
Nenue@32 57 else
Nenue@32 58 frame.out:Hide()
Nenue@32 59 end
Nenue@32 60 if parent.out.grip:IsMouseOver() then
Nenue@32 61 frame:StartSizing()
Nenue@32 62 else
Nenue@32 63 frame:StartMoving()
Nenue@32 64 end
Nenue@32 65 end
Nenue@32 66 else
Nenue@32 67 if button ~= 'RightButton' then
Nenue@32 68 frame:StopMovingOrSizing()
Nenue@32 69 frame:SetPoint('TOPLEFT', parent, 'TOPLEFT')
Nenue@32 70 frame:SetPoint('BOTTOMRIGHT', parent, 'BOTTOMRIGHT')
Nenue@32 71 frame.x = nil
Nenue@32 72 frame.y = nil
Nenue@32 73 frame.width = nil
Nenue@32 74 frame.height = nil
Nenue@32 75 frame:Save()
Nenue@32 76
Nenue@32 77 end
Nenue@32 78 end
Nenue@32 79 end
Nenue@32 80
Nenue@32 81 if fixparent then
Nenue@32 82 parent.out:Show()
Nenue@32 83 end
Nenue@32 84 end
Nenue@32 85 local function Dock_MouseUp (self, button)
Nenue@32 86 Dock_MouseDown(self, button, true)
Nenue@32 87 end
Nenue@32 88
Nenue@32 89 --- Adjusts frame element alignments
Nenue@32 90 local function PrepareForDock (frame, draw_x)
Nenue@32 91 frame.left:SetPoint('TOPLEFT', frame.out, 'TOPLEFT', -2, 0)
Nenue@32 92 frame.left:SetPoint('BOTTOMRIGHT', frame.out, 'BOTTOMLEFT', 0, 0)
Nenue@32 93 frame.topleft:SetPoint('BOTTOMRIGHT', frame.out, 'TOPLEFT', 0, 0)
Nenue@32 94 frame.top: SetPoint('TOPLEFT', frame.out, 'TOPLEFT', 0, 2)
Nenue@32 95 frame.top:SetPoint('BOTTOMRIGHT', frame.out, 'TOPRIGHT', 0, 0)
Nenue@32 96 frame.topright:SetPoint('BOTTOMLEFT', frame.out, 'TOPRIGHT', 0, 0)
Nenue@32 97 frame.right:SetPoint('TOPLEFT', frame.out, 'TOPRIGHT', 0, 0)
Nenue@32 98 frame.header:SetWidth(frame.header:GetStringWidth() * 1.2)
Nenue@32 99 frame.header:SetPoint('TOPLEFT', frame, 'TOPLEFT', draw_x+4, 0)
Nenue@32 100 frame.titlebar:SetPoint('TOPLEFT', frame.header, 'TOPLEFT', -4, 0)
Nenue@32 101 frame.titlebar:SetPoint('TOPRIGHT', frame.header, 'TOPRIGHT', 0, 0)
Nenue@32 102
Nenue@32 103 return (draw_x + frame.header:GetStringWidth() * 1.2 + 4)
Nenue@32 104 end
Nenue@32 105
Nenue@32 106
Nenue@32 107 --- Docks frames together
Nenue@32 108 -- @param target frame on which to dock
Nenue@32 109 -- @param ... frame objects to be docked
Nenue@32 110 --
Nenue@32 111 function D:DockFrame(...)
Nenue@32 112 local target = D.console[select(1,...)]
Nenue@32 113 if target.dockedTo then
Nenue@32 114 local t = D.c[target.dockedTo]
Nenue@32 115 print('channel',target.index,target.signature, 'is docked to',t.index, t.signature..'. using that instead')
Nenue@32 116 target = D.console[target.DockedTo]
Nenue@32 117 end
Nenue@32 118
Nenue@32 119 target.docked = {}
Nenue@32 120 local draw_x = PrepareForDock(target, 4)
Nenue@32 121 for i = 2, select('#', ...) do
Nenue@32 122 local frame = D.console[select(i, ...)]
Nenue@32 123 frame.dockedTo = target.index
Nenue@32 124 width, draw_x = MorphToDock (frame, draw_x)
Nenue@32 125 table.insert(target.docked, frame.index)
Nenue@32 126 frame:ClearAllPoints()
Nenue@32 127 frame:SetPoint('TOPLEFT', target, 'TOPLEFT', 0, 0)
Nenue@32 128 frame:SetSize(target:GetWidth(), target:GetHeight())
Nenue@32 129 frame.x = nil
Nenue@32 130 frame.y = nil
Nenue@32 131 frame.width = nil
Nenue@32 132 frame.height = nil
Nenue@32 133 frame.oldscript = frame:GetScript('OnMousedown')
Nenue@32 134 frame:SetScript('OnMouseDown', nil)
Nenue@32 135 frame:SetScript('OnMouseUp', nil)
Nenue@32 136 frame:Save()
Nenue@32 137 end
Nenue@32 138 end
Nenue@32 139
Nenue@32 140 --- Spaces each frame evenly across the screen.
Nenue@32 141 function D:DistributeFrames() --
Nenue@32 142 --print('frame grid:', max, num_side)
Nenue@32 143 local max = self.num_channels
Nenue@32 144 local num_side = math.ceil(math.sqrt(max))
Nenue@32 145 local w = GetScreenWidth() / num_side
Nenue@32 146 local h = GetScreenHeight() / num_side
Nenue@32 147 for i, frame in pairs(D.console) do
Nenue@32 148 local dx = (i-1) % num_side
Nenue@32 149 local dy = math.floor((i-1) / num_side)
Nenue@32 150
Nenue@32 151 --print('move:', frame.signature, 'dx=', dx, 'dy=', dy)
Nenue@32 152 --print('move:', frame.signature, ' x=', dx * w, 'y=', -(dy * h), 'h=', h, 'w=', w)
Nenue@32 153 frame.width = w
Nenue@32 154 frame.height = h
Nenue@32 155 frame.x = dx * w
Nenue@32 156 frame.y = -(dy * h)
Nenue@32 157 frame:Save()
Nenue@32 158 end
Nenue@32 159
Nenue@32 160 end
Nenue@32 161
Nenue@32 162 --- Place all frames stacked beneath the primary frame.
Nenue@32 163 function D:StackFrames()
Nenue@32 164 local last
Nenue@32 165 for i, frame in pairs(self.console) do
Nenue@32 166 if last then
Nenue@32 167 frame.x = last.x
Nenue@32 168 frame.y = last.y - 20
Nenue@32 169 else
Nenue@32 170 frame.x = (GetScreenWidth()-frame:GetWidth())/2
Nenue@32 171 frame.y = 0
Nenue@32 172 end
Nenue@32 173 frame:Save()
Nenue@32 174 last = frame
Nenue@32 175 end
Nenue@32 176 end
Nenue@32 177
Nenue@32 178