Created
July 7, 2022 13:19
-
-
Save Meorawr/b52d7999d27dbf6d4030d682efd4a27d to your computer and use it in GitHub Desktop.
Texture Load Watcher
This file contains 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 TextureParent = CreateFrame("Frame") | |
TextureParent:SetPoint("BOTTOMRIGHT", nil, "TOPLEFT") | |
TextureParent:SetSize(1, 1) | |
local TexturePool = CreateTexturePool(TextureParent) | |
local WatcherPool = CreateFramePool("Frame", TextureParent) | |
function ContinueOnTextureLoad(path, callback) | |
local texture = TexturePool:Acquire() | |
local watcher | |
local OnTextureLoad = function() | |
if texture:GetTextureFileID() then | |
xpcall(callback, CallErrorHandler, path, true, texture:GetSize()) | |
else -- Path doesn't exist. | |
xpcall(callback, CallErrorHandler, path, false, 0, 0) | |
end | |
if watcher then | |
watcher:SetScript("OnSizeChanged", nil) | |
WatcherPool:Release(watcher) | |
end | |
texture:SetTexture(nil) | |
TexturePool:Release(texture) | |
end | |
texture:SetPoint("BOTTOMRIGHT") | |
texture:SetTexture(path) | |
texture:Show() | |
if texture:GetRect() then | |
OnTextureLoad(); | |
else | |
watcher = WatcherPool:Acquire() | |
watcher:SetAllPoints(texture) | |
watcher:SetScript("OnSizeChanged", OnTextureLoad) | |
watcher:Show() | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment