InitGui.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "InitGui.h"
  2. float alpha = 0;
  3. void MergeIconsWithLatestFont(float font_size, bool FontDataOwnedByAtlas) {
  4. static const ImWchar icons_ranges[] = {ICON_MIN_FA, ICON_MAX_FA, 0};
  5. ImFontConfig icons_config;
  6. //icons_config.MergeMode = true;
  7. icons_config.PixelSnapH = true;
  8. icons_config.FontDataOwnedByAtlas = FontDataOwnedByAtlas;
  9. ImGui::GetIO().Fonts->AddFontFromMemoryTTF((void*)fa_solid_900, sizeof(fa_solid_900), font_size, &icons_config, icons_ranges);
  10. }
  11. void gui::InitImGui(HWND window, ID3D11Device* pDevice, ID3D11DeviceContext* pContext) {
  12. ImGui::CreateContext();
  13. ImGuiIO& io = ImGui::GetIO();
  14. io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
  15. ImGui_ImplWin32_Init(window);
  16. ImGui_ImplDX11_Init(pDevice, pContext);
  17. ImGui::GetIO().ImeWindowHandle = window;
  18. ImFontConfig font_cfg;
  19. font_cfg.FontDataOwnedByAtlas = false;
  20. ImGui::GetIO().Fonts->AddFontFromMemoryTTF((void*)tahoma, sizeof(tahoma), 17.f, &font_cfg);
  21. // init notify
  22. //MergeIconsWithLatestFont(16.f, false);
  23. LoadThemes();
  24. //LoadFonts();
  25. LoadFontFromResources(font_cfg, MAKEINTRESOURCEW(R_FONT_CN), 20.f);
  26. Init();
  27. }
  28. void gui::Render() {
  29. ImGui_ImplWin32_NewFrame();
  30. ImGui_ImplDX11_NewFrame();
  31. ImGui::NewFrame();
  32. Outer();
  33. Status();
  34. auto& settings = cheat::Settings::getInstance();
  35. static double startTime = ImGui::GetTime();
  36. static bool prevShowMenu = settings.f_ShowMenu.getValue();
  37. const float animDuration = settings.f_AnimationDuration.getValue();
  38. if (settings.f_ShowMenu.getValue() != prevShowMenu) {
  39. startTime = ImGui::GetTime();
  40. prevShowMenu = settings.f_ShowMenu.getValue();
  41. }
  42. float alpha = settings.f_ShowMenu.getValue() ? min(1.0f, (ImGui::GetTime() - startTime) / animDuration) : max(0.0f, 1.0f - (ImGui::GetTime() - startTime) / animDuration);
  43. ImGui::PushStyleVar(ImGuiStyleVar_Alpha, alpha);
  44. if (settings.f_ShowMenu.getValue() || alpha > 0.0f)
  45. gui::FrameLoadGui();
  46. ImGui::PopStyleVar();
  47. //ImGui::GetIO().MouseDrawCursor = settings.f_ShowMenu.getValue();
  48. ImGui::Render();
  49. }