Created
May 27, 2017 09:27
-
-
Save cgillespie/0c55f780174b61742a8707f3875d1f26 to your computer and use it in GitHub Desktop.
Basis for a _Cursor style addon that works in patch 7.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local CursorFrame = CreateFrame("Frame", "CursorFrame", UIParent) | |
CursorFrame:SetFrameStrata("TOOLTIP") | |
CursorFrame:Show() | |
CursorFrame.Presets = { | |
["Electric, blue long"] = { | |
["Path"] = "spells\\lightningboltivus_missile.mdx", | |
["MagicNumber"] = 148.1, | |
["Facing"] = 0 | |
} | |
} | |
_CursorOptions = { | |
["Cursor"] = CursorFrame.Presets["Electric, blue long"], | |
["Scale"] = 0.03 | |
} | |
function CursorFrame.LoadModel(options) | |
local model = CreateFrame("PlayerModel", "CursorModelFrame", CursorFrame) | |
model:SetAllPoints(nil) | |
model:Hide() | |
model:SetModel(options["Cursor"]["Path"]) | |
model:SetFacing(options["Cursor"]["Facing"]) | |
model:SetScale(options["Scale"]) | |
model:SetFrameStrata("TOOLTIP") | |
model.MagicNumber = options["Cursor"]["MagicNumber"] | |
return model | |
end | |
do | |
local model = CursorFrame.LoadModel(_CursorOptions) | |
model:Show() | |
-- Maximum values GetCursorPosition() can return | |
local MAX_X = 1365 | |
local MAX_Y = 768 | |
local offsetX = MAX_X / 2 | |
local offsetY = MAX_Y / 2 | |
local scale = model.MagicNumber * model:GetScale() | |
local previousX, previousY | |
CursorFrame:SetScript("OnUpdate", function(self, elapsed) | |
local cursorX, cursorY = GetCursorPosition() | |
-- Do nothing if the cursor hasn't moved | |
if cursorX == previousX and cursorY == previousY then | |
return | |
end | |
previousX, previousY = cursorX, cursorY | |
-- Normalise the mouse coordinates between -1 and 1 | |
local normalX = (cursorX - offsetX) / offsetX | |
local normalY = (cursorY - offsetY) / offsetY | |
-- Maximum distance the model should appear from the center of the screen | |
local modelRangeX = MAX_X / scale | |
local modelRangeY = MAX_Y / scale | |
local posX = normalX * modelRangeX | |
local posY = normalY * modelRangeY | |
model:SetPosition(0, posX, posY) | |
end) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
please write some installation instructions