Skip to content

Instantly share code, notes, and snippets.

@eandre
Created March 20, 2016 12:10
Show Gist options
  • Save eandre/04e46d2b37d8edd4efd4 to your computer and use it in GitHub Desktop.
Save eandre/04e46d2b37d8edd4efd4 to your computer and use it in GitHub Desktop.
-- Package declaration
local _draw = _G["github.com/eandre/groupauras/pkg/draw"] or {}
_G["github.com/eandre/groupauras/pkg/draw"] = _draw
local builtins = _G.lunar_go_builtins
local _widget = _G["github.com/eandre/groupauras/shim/widget"]
_draw.Point = {}
_draw.NewPoint = function(pos, texture)
local point = setmetatable({ ["Pos"] = pos, ["frame"] = _draw.getPointFrame() }, {__index=_draw.Point})
point.frame:SetTexture(texture)
point.frame.frame:SetSize(20, 20)
return point
end
_draw.Point.Free = function(p)
_draw.freePointFrame(p.frame)
end
_draw.pointFrame = {}
_draw.pointFrame.SetTexture = function(f, texture)
local entry = (_draw.textureMap[texture] or nil)
if entry ~= nil then
f.texture:SetTexture(entry.Texture)
f.texture:SetTexCoord(unpack(entry.TexCoords))
f.texture:SetBlendMode(entry.Blend)
else
f.texture:SetTexture(texture)
f.texture:SetTexCoord(0, 1, 0, 1)
f.texture:SetBlendMode(_widget.BlendBlend)
end
end
_draw.pointFrameCache = {}
_draw.getPointFrame = function()
for f in pairs(_draw.pointFrameCache or {}) do
builtins.delete(_draw.pointFrameCache, f)
return f
end
return _draw.newPointFrame()
end
_draw.freePointFrame = function(f)
_draw.pointFrameCache[f] = true
end
_draw.newPointFrame = function()
local f = setmetatable({ }, {__index=_draw.pointFrame})
f.frame = _widget.CreateFrame(_draw.canvas)
f.frame:SetFrameStrata(_widget.StrataMedium)
f.texture = f.frame:CreateTexture()
f.texture:SetAllPoints(f.frame)
f.texture:SetDrawLayer(_widget.LayerArtwork, 0)
return f
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment