Nenue@54: -- Veneer Nenue@71: -- Base framework for making things draggable. Nenue@0: Nenue@75: local vn, print = LibStub("LibKraken").register(Veneer) Nenue@80: local wipe = table.wipe Nenue@0: Nenue@59: local defaults = { Nenue@59: enableAll = true, Nenue@59: enableModule = { Nenue@59: BuffFrame = true, Nenue@59: }, Nenue@59: BuffFrame = { Nenue@59: width = 48, Nenue@59: height = 48, Nenue@59: } Nenue@59: } Nenue@71: local configMode Nenue@71: local veneers = {} Nenue@71: Nenue@79: local anonID = 0 Nenue@79: Nenue@79: local tostring = tostring Nenue@79: local IsFrameHandle = IsFrameHandle Nenue@79: local GetAnonymousName = function(key) Nenue@79: if not key then Nenue@71: anonID = anonID + 1 Nenue@79: key = anonID Nenue@71: end Nenue@79: return 'VN' .. key Nenue@71: end Nenue@79: local GetTableName = function(table) Nenue@79: return (IsFrameHandle(table) and table:GetName()) or tostring(table) Nenue@79: end Nenue@79: Nenue@79: Nenue@71: Nenue@72: local anchor_coefficients = { Nenue@72: ['TOP'] = function(x, y) return x, y end, Nenue@72: ['BOTTOM'] = function(x, y) return x,y end, Nenue@72: ['LEFT'] = function(x, y) return x,y end, Nenue@72: ['RIGHT'] = function(x,y) return x,y end, Nenue@72: } Nenue@72: Nenue@72: local VeneerButton_OnDragStart = function(self) Nenue@72: self.startingLeft = self:GetLeft() Nenue@72: self.startingBottom = self:GetBottom() Nenue@72: self.anchors = self.anchors or {} Nenue@72: table.wipe(self.anchors) Nenue@72: Nenue@72: local frame = self:GetParent() Nenue@72: local n = frame:GetNumPoints() Nenue@72: for i = 1, n do Nenue@72: local anchor, parent, relative, x, y = frame:GetPoint(i) Nenue@72: self.anchors[i] = { Nenue@72: anchor = anchor, Nenue@72: parent = parent, Nenue@72: relative = relative, Nenue@72: x = x, Nenue@72: y = y Nenue@72: } Nenue@72: end Nenue@72: Nenue@72: print(self:GetName(), 'start moving', self.startingLeft, self.startingBottom) Nenue@72: self:StartMoving() Nenue@72: end Nenue@72: Nenue@72: local VeneerButton_OnDragStop = function(self) Nenue@72: self:StopMovingOrSizing() Nenue@72: if self.OnDragStop then Nenue@72: self.OnDragStop(self) Nenue@72: else Nenue@72: local frame = self:GetParent() Nenue@72: local dx = self:GetLeft() - self.startingLeft Nenue@72: local dy = self:GetBottom() - self.startingBottom Nenue@72: Nenue@72: frame:ClearAllPoints() Nenue@72: for i, point in ipairs(self.anchors) do Nenue@72: frame:SetPoint(point.anchor, point.parent, point.relative, point.x + dx, point.y + dy) Nenue@72: print('adjusting anchor', point.anchor, point.parent, point.relative, point.x + dx, point.y + dy) Nenue@72: end Nenue@72: end Nenue@72: end Nenue@72: Nenue@72: local Veneer_FixMovers = function() Nenue@72: for frame, veneer in pairs(veneers) do Nenue@72: if veneer:IsMoving() then Nenue@72: VeneerButton_OnDragStop(veneer) Nenue@72: end Nenue@72: end Nenue@72: end Nenue@71: Nenue@71: local VeneerButton_Update = function(self) Nenue@71: if configMode then Nenue@72: self:SetScript('OnDragStart', VeneerButton_OnDragStart) Nenue@72: self:SetScript('OnDragStop', VeneerButton_OnDragStop) Nenue@72: self:SetMovable(true) Nenue@72: self:EnableMouse(true) Nenue@71: self:RegisterForDrag('LeftButton') Nenue@71: Nenue@71: self.bg:SetColorTexture(0,1,0,0.5) Nenue@72: for i, region in ipairs(self.configLayers) do Nenue@72: region:Show() Nenue@72: end Nenue@72: self:Show() Nenue@71: else Nenue@71: Nenue@71: self:SetScript('OnDragStart', self.StartMoving) Nenue@71: self:SetScript('OnDragStop', self.StopMovingOrSizing) Nenue@71: self:SetMovable(false) Nenue@71: self:EnableMouse(false) Nenue@71: Nenue@71: self.bg:SetColorTexture(0,1,0,0) Nenue@72: for i, region in ipairs(self.configLayers) do Nenue@72: region:Hide() Nenue@72: end Nenue@72: if self.isHidden then Nenue@72: self:Hide() Nenue@72: end Nenue@72: Nenue@71: end Nenue@71: end Nenue@71: Nenue@71: local ToggleVeneerConfig = function() Nenue@71: if configMode then Nenue@71: configMode = false Nenue@71: vn:print('Config mode off.') Nenue@71: else Nenue@71: configMode = true Nenue@71: vn:print('Config mode on.') Nenue@71: end Nenue@71: Nenue@71: for frame, veneer in pairs(veneers) do Nenue@71: VeneerButton_Update(veneer) Nenue@71: end Nenue@71: end Nenue@71: Nenue@71: local VeneerButton_OnShow = function(self) Nenue@71: VeneerButton_Update(self) Nenue@71: end Nenue@71: Nenue@73: vn.GetVeneer = function(frame, template) Nenue@71: if not frame then Nenue@71: print('|cFFFF4400Unable to acquire frame...|r') Nenue@71: return Nenue@71: end Nenue@71: Nenue@71: if veneers[frame] then Nenue@71: return veneers[frame] Nenue@71: end Nenue@71: Nenue@79: local name = type(frame) == 'table' and GetTableName(frame) or GetAnonymousName() Nenue@73: local veneer = CreateFrame('Frame', name, frame, template or 'VeneerTemplate') Nenue@72: print('+veneer', name) Nenue@71: Nenue@71: veneer:SetAllPoints(frame) Nenue@71: veneer:SetParent(frame) Nenue@72: veneer.label:SetText(name) Nenue@74: veneer.bg:SetColorTexture(0,0,0,0) Nenue@71: veneer:Hide() Nenue@71: veneer:EnableMouse(false) Nenue@71: Nenue@71: veneer:SetScript('OnShow', VeneerButton_OnShow) Nenue@71: Nenue@71: -- find current X/Y Nenue@71: veneer.currentLeft = frame:GetLeft() Nenue@71: veneer.currentTop = frame:GetTop() Nenue@71: Nenue@72: Nenue@71: veneers[frame] = veneer Nenue@71: return veneers[frame] Nenue@71: end Nenue@0: Nenue@80: local mixin_probe = { Nenue@80: 'ArtifactFrame', Nenue@80: 'ArtifactFrameUnderlay', Nenue@80: } Nenue@80: Nenue@80: vn.event = function(event, arg) Nenue@80: Nenue@80: end Nenue@80: Nenue@59: vn.init = function() Nenue@59: if (not VeneerData) or (not VeneerData.version) then Nenue@59: VeneerData = defaults Nenue@0: end Nenue@59: vn.db = VeneerData Nenue@80: Nenue@71: end Nenue@62: Nenue@71: Nenue@71: SLASH_VENEER1 = "/veneer" Nenue@71: SLASH_VENEER2 = "/vn" Nenue@71: Nenue@75: SlashCmdList.VENEER = function(cmd) Nenue@75: for i, module in pairs(vn.modules) do Nenue@75: if module.cmd then Nenue@75: local result = module.cmd(cmd) Nenue@75: if result then Nenue@75: return Nenue@75: end Nenue@75: end Nenue@75: end Nenue@71: ToggleVeneerConfig() Nenue@59: end