local imgui = require('mimgui');
local renderWindow = imgui.new.bool(true);
local state = false;
local animation = {
state = state,
start = 0,
radius = 0,
alpha = 0
};
imgui.OnInitialize(function()
imgui.GetStyle().WindowPadding = imgui.ImVec2(0, 0);
end)
local anim = {
current = imgui.ImVec2(150, 150),
next = imgui.ImVec2(150, 150),
start = os.clock();
}
require('lib.moonloader');
addEventHandler('onWindowMessage', function(msg, param)
if (msg == 0x0100) then
if (param == VK_A or param == VK_D) then
anim.start = os.clock();
anim.next.x = anim.current.x + (param == VK_A and -100 or 100);
elseif (param == VK_W or param == VK_S) then
anim.start = os.clock();
anim.next.y = anim.current.y + (param == VK_S and 100 or -100);
end
end
end);
imgui.OnFrame(
function() return renderWindow[0] end,
function(this)
if (imgui.Begin('Main Window', renderWindow)) then
local pos, size = imgui.GetWindowPos(), imgui.GetWindowSize();
local DL = imgui.GetWindowDrawList();
imgui.Text(('%s %s\n%s'):format(anim.current.x, anim.current.y, anim.start));
anim.current = bringVec2To(anim.current, anim.next, anim.start, 5);
imgui.SetCursorPos(anim.current);
imgui.Button('test', imgui.ImVec2(100, 20));
imgui.End();
end
end
);
function bringFloatTo(from, to, start_time, duration)
local timer = os.clock() - start_time
if timer >= 0.00 and timer <= duration then
local count = timer / (duration / 100)
return from + (count * (to - from) / 100), true
end
return (timer > duration) and to or from, false
end
function bringVec2To(from, to, start_time, duration)
local timer = os.clock() - start_time
if timer >= 0.00 and timer <= duration then
local count = timer / (duration / 100)
return imgui.ImVec2(
from.x + (count * (to.x - from.x) / 100),
from.y + (count * (to.y - from.y) / 100)
), true
end
return (timer > duration) and to or from, false
end