From 77b52da44b263df4884be2f35f885d8edccbb6fa Mon Sep 17 00:00:00 2001 From: boris Date: Wed, 19 Dec 2018 00:13:24 +1300 Subject: added new loader project :) merry christmas --- .../csgo-client/UserExperience/UserInterface.cpp | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 csgo-loader/csgo-client/UserExperience/UserInterface.cpp (limited to 'csgo-loader/csgo-client/UserExperience/UserInterface.cpp') diff --git a/csgo-loader/csgo-client/UserExperience/UserInterface.cpp b/csgo-loader/csgo-client/UserExperience/UserInterface.cpp new file mode 100644 index 0000000..f8f465f --- /dev/null +++ b/csgo-loader/csgo-client/UserExperience/UserInterface.cpp @@ -0,0 +1,65 @@ +#include + +#include +#include +#include + +// Global accessor for the user interface. +UserExperience::UserInterfacePtr UserInterface = std::make_unique(); + +namespace UserExperience { + void OnDirectXFrame() { + if(g_d3d.run_frame(g_window.m_d3d_device)) { + g_d3d.begin(); + for(auto& it : d3d::sprites) { + it->begin(g_window.m_d3d_device); + } + + static auto last_time = GetTickCount() * 0.001f; + auto cur_time = GetTickCount() * 0.001f; + + auto deltatime = cur_time - last_time; + + last_time = cur_time; + + constexpr float anim_step = 1.0f / 15.f; + static float anim_time = 0.f; + static bool flip = false; + if(anim_time == 1.0f) { + flip = true; + } + if(anim_time == 0.f) { + flip = false; + } + + if(flip) anim_time = std::clamp(anim_time - anim_step * deltatime, 0.f, 1.0f); + else anim_time = std::clamp(anim_time + anim_step * deltatime, 0.f, 1.0f); + + ui::set_animtime(anim_time); + ui::render(); + + RECT cur_rect{ }; + GetWindowRect(g_window.get_hwnd(), &cur_rect); + + g_d3d.end(); + for(auto& it : d3d::sprites) { + it->end(); + } + } + } + + bool UserInterface::Start() { + bool result = g_window.create(); + + if(result) { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + g_window.add_on_frame(&OnDirectXFrame); + } + + return result; + } + + void UserInterface::RunUiFrame() { + g_window.on_frame(); + } +} \ No newline at end of file -- cgit v1.2.3