#include "imgui.h" #include "imgui_impl_win32.h" #include "imgui_impl_dx9.h" #include #include "Fonts.h" #define IMGUI_DEFINE_MATH_OPERATORS #include <../ImGui/imgui_internal.h> #include "imgui_settings.h" #include #include #pragma comment (lib, "d3dx9.lib") #include "images.h" #include "blur.hpp" static LPDIRECT3D9 g_pD3D = NULL; static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; static D3DPRESENT_PARAMETERS g_d3dpp = {}; bool CreateDeviceD3D(HWND hWnd); void CleanupDeviceD3D(); void CreateRenderTarget(); void CleanupRenderTarget(); LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); IDirect3DTexture9* bg = nullptr; IDirect3DTexture9* logo = nullptr; static bool image_loaded = false; void LoadImages() { if (image_loaded) return; D3DXCreateTextureFromFileInMemory(g_pd3dDevice, &background, sizeof(background), &bg); D3DXCreateTextureFromFileInMemory(g_pd3dDevice, &logotype, sizeof(logotype), &logo); image_loaded = true; } void Trinage_background() { ImVec2 screen_size = { (float)GetSystemMetrics(SM_CXSCREEN), (float)GetSystemMetrics(SM_CYSCREEN) }; static ImVec2 partile_pos[100]; static ImVec2 partile_target_pos[100]; static float partile_speed[100]; static float partile_size[100]; static float partile_radius[100]; static float partile_rotate[100]; for (int i = 1; i < 50; i++) { if (partile_pos[i].x == 0 || partile_pos[i].y == 0) { partile_pos[i].x = rand() % (int)screen_size.x + 1; partile_pos[i].y = screen_size.y + 30; partile_speed[i] = 70 + rand() % 135; partile_radius[i] = 2 + rand() % 10; partile_size[i] = 15 + rand() % 40; partile_target_pos[i].x = rand() % (int)screen_size.x; partile_target_pos[i].y = -50; } partile_pos[i].y -= ImGui::GetIO().DeltaTime * partile_speed[i]; partile_rotate[i] -= ImGui::GetIO().DeltaTime; if (partile_pos[i].y < 10) { partile_pos[i].x = 0; partile_pos[i].y = 0; partile_rotate[i] = 0; } ImRotateStart(); ImGui::GetWindowDrawList()->AddShadowRect(partile_pos[i] - ImVec2(partile_size[i], partile_size[i]), partile_pos[i] + ImVec2(partile_size[i], partile_size[i]), ImColor(0.f, 0.f, 0.f, 0.5f), 15.f, ImVec2(0,0), ImDrawFlags_ShadowCutOutShapeBackground, 15.f); ImGui::GetWindowDrawList()->AddRectFilled(partile_pos[i] - ImVec2(partile_size[i], partile_size[i]), partile_pos[i] + ImVec2(partile_size[i], partile_size[i]), GetColorWithAlpha(main_color, 0.3f), 5.f); ImRotateEnd(partile_rotate[i]); } } bool CreateDeviceD3D(HWND hWnd) { if ((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL) return false; // Create the D3DDevice ZeroMemory(&g_d3dpp, sizeof(g_d3dpp)); g_d3dpp.Windowed = TRUE; g_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; g_d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; // Need to use an explicit format with alpha if needing per-pixel alpha composition. g_d3dpp.EnableAutoDepthStencil = TRUE; g_d3dpp.AutoDepthStencilFormat = D3DFMT_D16; g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; // Present with vsync //g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // Present without vsync, maximum unthrottled framerate if (g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &g_d3dpp, &g_pd3dDevice) < 0) return false; return true; } void CleanupDeviceD3D() { if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; } if (g_pD3D) { g_pD3D->Release(); g_pD3D = NULL; } } void ResetDevice() { blur::device_reset(); ImGui_ImplDX9_InvalidateDeviceObjects(); HRESULT hr = g_pd3dDevice->Reset(&g_d3dpp); if (hr == D3DERR_INVALIDCALL) IM_ASSERT(0); ImGui_ImplDX9_CreateDeviceObjects(); } extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam)) return true; switch (msg) { case WM_SIZE: if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED) { g_d3dpp.BackBufferWidth = LOWORD(lParam); g_d3dpp.BackBufferHeight = HIWORD(lParam); ResetDevice(); } return 0; case WM_SYSCOMMAND: if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu return 0; break; case WM_DESTROY: ::PostQuitMessage(0); return 0; } return ::DefWindowProc(hWnd, msg, wParam, lParam); }