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