Advertisement
tcyknhrabirwjyljhp

Untitled

May 29th, 2022
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.79 KB | None | 0 0
  1.  
  2. #pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
  3.  
  4. #include "imgui.h"
  5. #include "imgui_impl_dx9.h"
  6. #include "imgui_impl_win32.h"
  7. #include <d3d9.h>
  8. #include <tchar.h>
  9. #include <string>
  10. #include <vector>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <time.h>
  14. #include <iostream>
  15. #include <fstream>
  16. #include <filesystem>
  17. #include <sstream>
  18. #include "imgui_internal.h"
  19. #include "imgui.h"
  20.  
  21. #include <D3dx9tex.h>
  22. #pragma comment(lib, "D3dx9")
  23.  
  24. namespace fs = std::filesystem;
  25.  
  26. static LPDIRECT3D9 g_pD3D = NULL;
  27. static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
  28. static D3DPRESENT_PARAMETERS g_d3dpp = {};
  29.  
  30. bool CreateDeviceD3D(HWND hWnd);
  31. void CleanupDeviceD3D();
  32. void ResetDevice();
  33. LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  34.  
  35. struct Wnds
  36. {
  37. //int ID = 0;
  38. std::string Name;
  39. std::string Text;
  40. };
  41.  
  42. std::vector<Wnds> WndList;
  43. std::vector<Wnds> WndList2;
  44. char Buffer[64];
  45. char Buffer2[512];
  46. bool bDelete = false;
  47. bool bShowWindows = true;
  48. bool bTextCenter = false;
  49. bool bOnlyText = false;
  50.  
  51. int GlobalIndex = -1;
  52. int GlobalIndex2 = -1;
  53.  
  54. bool LoadTextureFromFile(const char* filename, PDIRECT3DTEXTURE9* out_texture, int* out_width, int* out_height)
  55. {
  56. PDIRECT3DTEXTURE9 texture;
  57. HRESULT hr = D3DXCreateTextureFromFileA(g_pd3dDevice, filename, &texture);
  58. if (hr != S_OK)
  59. return false;
  60.  
  61. D3DSURFACE_DESC my_image_desc;
  62. texture->GetLevelDesc(0, &my_image_desc);
  63. *out_texture = texture;
  64. *out_width = (int)my_image_desc.Width;
  65. *out_height = (int)my_image_desc.Height;
  66. return true;
  67. }
  68.  
  69. void TextCentered(std::string text) {
  70. float win_width = ImGui::GetWindowSize().x;
  71. float text_width = ImGui::CalcTextSize(text.c_str()).x;
  72.  
  73. float text_indentation = (win_width - text_width) * 0.5f;
  74.  
  75.  
  76. float min_indentation = 20.0f;
  77. if (text_indentation <= min_indentation) {
  78. text_indentation = min_indentation;
  79. }
  80.  
  81. ImGui::SameLine(text_indentation);
  82. ImGui::PushTextWrapPos(win_width - text_indentation);
  83. ImGui::TextWrapped(text.c_str());
  84. ImGui::PopTextWrapPos();
  85. }
  86.  
  87. int main(int, char**)
  88. {
  89. srand (time(NULL));
  90.  
  91. //Wnds tmp;
  92. //tmp.ID = 1234;
  93. //tmp.Name = "ay##*";
  94. //WndList.push_back(tmp);
  95.  
  96. std::string path = "Data/";
  97. std::string path2 = "Data2/";
  98.  
  99. for (const auto& entry : fs::directory_iterator(path))
  100. {
  101. std::string line;
  102. std::ifstream myfile (entry.path());
  103.  
  104. std::string name;
  105.  
  106. std::stringstream ss;
  107. ss << entry.path();
  108. ss >> name;
  109.  
  110. name = name.substr(0, name.length()-1);
  111. name.erase(0, 6);
  112.  
  113. Wnds tmp;
  114. tmp.Name = name;
  115.  
  116. if (myfile.is_open())
  117. {
  118. while ( getline (myfile,line) )
  119. {
  120. tmp.Text += line + "\n";
  121. }
  122. }
  123. myfile.close();
  124. WndList.push_back(tmp);
  125. }
  126.  
  127. for (const auto& entry : fs::directory_iterator(path2))
  128. {
  129. std::string line;
  130. std::ifstream myfile (entry.path());
  131.  
  132. std::string name;
  133.  
  134. std::stringstream ss;
  135. ss << entry.path();
  136. ss >> name;
  137.  
  138. name = name.substr(0, name.length()-1);
  139. name.erase(0, 7);
  140.  
  141. Wnds tmp;
  142. tmp.Name = name;
  143.  
  144. if (myfile.is_open())
  145. {
  146. while ( getline (myfile,line) )
  147. {
  148. tmp.Text += line + "\n";
  149. }
  150. }
  151. myfile.close();
  152. WndList2.push_back(tmp);
  153. }
  154.  
  155. std::ifstream myfile ("bCenter");
  156.  
  157. if (myfile.is_open())
  158. {
  159. bTextCenter = true;
  160. }
  161. myfile.close();
  162.  
  163. WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, _T("ImGui Example"), NULL };
  164. ::RegisterClassEx(&wc);
  165. HWND hwnd = ::CreateWindow(wc.lpszClassName, _T("Social-Media-Planer"), WS_OVERLAPPEDWINDOW, 0, 0, 1920, 1080, NULL, NULL, wc.hInstance, NULL);
  166.  
  167. if (!CreateDeviceD3D(hwnd))
  168. {
  169. CleanupDeviceD3D();
  170. ::UnregisterClass(wc.lpszClassName, wc.hInstance);
  171. return 1;
  172. }
  173.  
  174.  
  175. // Show the window
  176. ::ShowWindow(hwnd, SW_SHOWDEFAULT);
  177. ::UpdateWindow(hwnd);
  178.  
  179. IMGUI_CHECKVERSION();
  180. ImGui::CreateContext();
  181. ImGuiIO& io = ImGui::GetIO(); (void)io;
  182. io.IniFilename = "Windows.ini";
  183.  
  184. io.Fonts->AddFontFromFileTTF("Roboto.ttf",25.0f);
  185.  
  186. int my_image_width = 1920;
  187. int my_image_height = 1080;
  188. PDIRECT3DTEXTURE9 my_texture = NULL;
  189. bool ret = LoadTextureFromFile("IMG.png", &my_texture, &my_image_width, &my_image_height);
  190. IM_ASSERT(ret);
  191.  
  192. ImGui::StyleColorsDark();
  193.  
  194. ImGui_ImplWin32_Init(hwnd);
  195. ImGui_ImplDX9_Init(g_pd3dDevice);
  196.  
  197. // Our state
  198. bool show_demo_window = true;
  199. bool show_another_window = false;
  200. ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
  201. clear_color = ImVec4(0.88f, 0.55f, 1.0f, 1.0f);
  202.  
  203. // Main loop
  204. bool done = false;
  205. while (!done)
  206. {
  207.  
  208. MSG msg;
  209. while (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
  210. {
  211. ::TranslateMessage(&msg);
  212. ::DispatchMessage(&msg);
  213. if (msg.message == WM_QUIT)
  214. done = true;
  215. }
  216. if (done)
  217. break;
  218.  
  219. ImGuiStyle& style = ImGui::GetStyle();
  220. //style.WindowRounding = 5.3f;
  221. //style.FrameRounding = 2.3f;
  222. //style.ScrollbarRounding = 0;
  223. style.Colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 0.90f);
  224. style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
  225. style.Colors[ImGuiCol_WindowBg] = ImVec4(0.09f, 0.09f, 0.15f, 1.00f);
  226. style.Colors[ImGuiCol_PopupBg] = ImVec4(0.05f, 0.05f, 0.10f, 0.85f);
  227. style.Colors[ImGuiCol_Border] = ImVec4(0.70f, 0.70f, 0.70f, 0.65f);
  228. style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
  229. style.Colors[ImGuiCol_FrameBg] = ImVec4(0.00f, 0.00f, 0.01f, 1.00f);
  230. style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.90f, 0.80f, 0.80f, 0.40f);
  231. style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.90f, 0.65f, 0.65f, 0.45f);
  232. style.Colors[ImGuiCol_TitleBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.83f);
  233. style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.0f, 0.40f, 0.80f, 0.20f);
  234. style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.00f, 0.00f, 0.00f, 0.87f);
  235. style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.01f, 0.01f, 0.02f, 0.80f);
  236. style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.20f, 0.25f, 0.30f, 0.60f);
  237. style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.55f, 0.53f, 0.55f, 0.51f);
  238. style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.56f, 0.56f, 0.56f, 1.00f);
  239. style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.56f, 0.56f, 0.56f, 0.91f);
  240. style.Colors[ImGuiCol_CheckMark] = ImVec4(0.90f, 0.90f, 0.90f, 0.83f);
  241. style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.70f, 0.70f, 0.70f, 0.62f);
  242. style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.30f, 0.30f, 0.30f, 0.84f);
  243. style.Colors[ImGuiCol_Button] = ImVec4(0.48f, 0.72f, 0.89f, 0.49f);
  244. style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.50f, 0.69f, 0.99f, 0.68f);
  245. style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f);
  246. style.Colors[ImGuiCol_Header] = ImVec4(0.30f, 0.69f, 1.00f, 0.53f);
  247. style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.44f, 0.61f, 0.86f, 1.00f);
  248. style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.38f, 0.62f, 0.83f, 1.00f);
  249. style.Colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.85f);
  250. style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(1.00f, 1.00f, 1.00f, 0.60f);
  251. style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(1.00f, 1.00f, 1.00f, 0.90f);
  252. style.Colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
  253. style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
  254. style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
  255. style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
  256. style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f);
  257.  
  258. style.Alpha = 1.0f;
  259. style.FrameRounding = 3.0f;
  260.  
  261. style.Colors[ImGuiCol_Text] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
  262. style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
  263. style.Colors[ImGuiCol_WindowBg] = ImVec4(0.94f, 0.94f, 0.94f, 0.94f);
  264. style.Colors[ImGuiCol_PopupBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.94f);
  265. style.Colors[ImGuiCol_Border] = ImVec4(0.00f, 0.00f, 0.00f, 0.39f);
  266. style.Colors[ImGuiCol_BorderShadow] = ImVec4(1.00f, 1.00f, 1.00f, 0.10f);
  267. style.Colors[ImGuiCol_FrameBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.94f);
  268. style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f);
  269. style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
  270. style.Colors[ImGuiCol_TitleBg] = ImVec4(0.96f, 0.96f, 0.96f, 1.00f);
  271. style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(1.00f, 1.00f, 1.00f, 0.51f);
  272. style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.82f, 0.82f, 0.82f, 1.00f);
  273. style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.86f, 0.86f, 0.86f, 1.00f);
  274. style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.98f, 0.98f, 0.98f, 0.53f);
  275. style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.69f, 0.69f, 0.69f, 1.00f);
  276. style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.59f, 0.59f, 0.59f, 1.00f);
  277. style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.49f, 0.49f, 0.49f, 1.00f);
  278. style.Colors[ImGuiCol_CheckMark] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
  279. style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.24f, 0.52f, 0.88f, 1.00f);
  280. style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
  281. style.Colors[ImGuiCol_Button] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f);
  282. style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
  283. style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.06f, 0.53f, 0.98f, 1.00f);
  284. style.Colors[ImGuiCol_Header] = ImVec4(0.26f, 0.59f, 0.98f, 0.31f);
  285. style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.80f);
  286. style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
  287. style.Colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.50f);
  288. style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
  289. style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
  290. style.Colors[ImGuiCol_PlotLines] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f);
  291. style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
  292. style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
  293. style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
  294. style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
  295.  
  296.  
  297. // Start the Dear ImGui frame
  298. ImGui_ImplDX9_NewFrame();
  299. ImGui_ImplWin32_NewFrame();
  300. ImGui::NewFrame();
  301.  
  302. if (GetAsyncKeyState(VK_F1) & 0x1)
  303. {
  304. bShowWindows = !bShowWindows;
  305. Sleep(250);
  306. }
  307.  
  308. if (GetAsyncKeyState(0x2) )
  309. {
  310. bDelete = true;
  311. }
  312. else
  313. {
  314. bDelete = false;
  315. }
  316.  
  317. ImGui::Begin(" ", (bool*)true, ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoTitleBar);
  318. ImGui::SetWindowPos(ImVec2(0, 0));
  319. ImGui::Image((void*)my_texture, ImVec2(1920, 1000));
  320. ImGui::End();
  321.  
  322. if (bShowWindows)
  323. {
  324. ImGui::Begin("Einstellungen");
  325. ImGui::SetWindowSize(ImVec2(300, 494));
  326. ImGui::Text("F1 = Einstellungen Sichtbar?");
  327. //ImGui::SetWindowPos(ImVec2(0, 0));
  328. // only set size
  329.  
  330. if (ImGui::Button("Neues Fenster"))
  331. {
  332. bool bOkay = true;
  333. for (char c : Buffer)
  334. {
  335. if (c == 32)
  336. {
  337. bOkay = false;
  338. }
  339. }
  340. if (!bOnlyText && strlen(Buffer) > 0 && bOkay)
  341. {
  342. Wnds tmp;
  343. int ID = rand() % 10000;
  344. std::string IDString;
  345.  
  346. std::stringstream ss;
  347. ss << ID;
  348. ss >> IDString;
  349.  
  350. std::string str(Buffer);
  351. str += "##";
  352. str += IDString;
  353. tmp.Name = str;
  354. tmp.Text = Buffer2;
  355. WndList.push_back(tmp);
  356. }
  357. if (bOnlyText && strlen(Buffer) > 0 && bOkay)
  358. {
  359. Wnds tmp;
  360. int ID = rand() % 10000;
  361. std::string IDString;
  362.  
  363. std::stringstream ss;
  364. ss << ID;
  365. ss >> IDString;
  366.  
  367. std::string str(Buffer);
  368. str += "##";
  369. str += IDString;
  370. tmp.Name = str;
  371. tmp.Text = Buffer2;
  372. WndList2.push_back(tmp);
  373. }
  374. }
  375.  
  376. if (ImGui::Button("Speichern"))
  377. {
  378.  
  379.  
  380. //std::remove("Windows.ini");
  381.  
  382. std::filesystem::remove_all("Data");
  383. Sleep(200);
  384. std::filesystem::create_directory("Data");
  385. Sleep(200);
  386.  
  387. std::filesystem::remove_all("Data2");
  388. Sleep(200);
  389. std::filesystem::create_directory("Data2");
  390. Sleep(200);
  391.  
  392. for (Wnds w : WndList)
  393. {
  394. std::ofstream myfile;
  395. std::string PathName = "Data/";
  396. PathName += w.Name;
  397. if (bTextCenter)
  398. {
  399. std::ofstream mybool;
  400. mybool.open ("bCenter");
  401. mybool << "dummy";
  402. mybool.close();
  403. }
  404. else
  405. {
  406. std::remove("bCenter");
  407. }
  408. myfile.open (PathName);
  409. myfile << w.Text << std::endl;
  410. myfile.close();
  411. }
  412.  
  413. for (Wnds w : WndList2)
  414. {
  415. std::ofstream myfile;
  416. std::string PathName = "Data2/";
  417. PathName += w.Name;
  418. myfile.open (PathName);
  419. myfile << w.Text << std::endl;
  420. myfile.close();
  421. }
  422. }
  423.  
  424. ImGui::InputText(":Titel", Buffer, 60);
  425. ImGui::InputTextMultiline(":Text", Buffer2, 512);
  426. ImGui::Checkbox("Delete Button?", &bDelete);
  427. ImGui::Checkbox("Center Text?", &bTextCenter);
  428. ImGui::Checkbox("Nur Text", &bOnlyText);
  429. ImGui::End();
  430. }
  431.  
  432. for (Wnds w : WndList)
  433. {
  434. std::string Name = " ";
  435. int len = w.Name.length();
  436. len = len - 13;
  437. if (len > 1)
  438. {
  439. for (int i = 0; i < len; i++)
  440. {
  441. if (i % 2 == 0)
  442. {
  443. Name.erase(0, 1);
  444. }
  445. }
  446. }
  447. Name += w.Name;
  448. ImGui::Begin(Name.c_str());
  449. ImVec2 Pos = ImGui::GetWindowPos();
  450. if ((int)Pos.x % 15 != 0)
  451. {
  452. Pos.x++;
  453. }
  454. if ((int)Pos.y % 20 != 0)
  455. {
  456. Pos.y++;
  457. }
  458. ImGui::SetWindowPos(Pos);
  459. ImGui::SetWindowSize(ImVec2(250, 120));
  460. if (bDelete && ImGui::Button("Del"))
  461. {
  462. int Counter = 0;
  463. for (Wnds ww : WndList)
  464. {
  465. if (ww.Name == w.Name)
  466. {
  467. GlobalIndex = Counter;
  468. break;
  469. }
  470. Counter++;
  471. }
  472. }
  473. //
  474. if (bTextCenter)
  475. {
  476. TextCentered(w.Text);
  477. }
  478. else
  479. {
  480. ImGui::Text(w.Text.c_str());
  481. }
  482. ImGui::End();
  483. }
  484.  
  485. for (Wnds w : WndList2)
  486. {
  487. ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.f);
  488. ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.0f, 0.0f, 0.0f, 0.0f));
  489.  
  490. ImGui::Begin(w.Name.c_str(), reinterpret_cast<bool*>(true), ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoResize);
  491.  
  492. if (bDelete)
  493. {
  494. if (ImGui::Button("Del"))
  495. {
  496. int Counter = 0;
  497. for (Wnds ww : WndList2)
  498. {
  499. if (ww.Name == w.Name)
  500. {
  501. GlobalIndex2 = Counter;
  502. break;
  503. }
  504. Counter++;
  505. }
  506. }
  507. }
  508. ImGui::Text(w.Text.c_str());
  509.  
  510. ImGui::End();
  511. ImGui::PopStyleColor();
  512. ImGui::PopStyleVar();
  513. }
  514.  
  515. if (GlobalIndex != -1)
  516. {
  517. WndList.erase(WndList.begin() + GlobalIndex);
  518. GlobalIndex = -1;
  519. }
  520. if (GlobalIndex2 != -1)
  521. {
  522. WndList2.erase(WndList2.begin() + GlobalIndex2);
  523. GlobalIndex2 = -1;
  524. }
  525. ImGui::EndFrame();
  526. g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
  527. g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
  528. g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
  529. D3DCOLOR clear_col_dx = D3DCOLOR_RGBA((int)(clear_color.x*clear_color.w*255.0f), (int)(clear_color.y*clear_color.w*255.0f), (int)(clear_color.z*clear_color.w*255.0f), (int)(clear_color.w*255.0f));
  530. g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, clear_col_dx, 1.0f, 0);
  531.  
  532. if (g_pd3dDevice->BeginScene() >= 0)
  533. {
  534. ImGui::Render();
  535. ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
  536. g_pd3dDevice->EndScene();
  537. }
  538. HRESULT result = g_pd3dDevice->Present(NULL, NULL, NULL, NULL);
  539.  
  540. if (result == D3DERR_DEVICELOST && g_pd3dDevice->TestCooperativeLevel() == D3DERR_DEVICENOTRESET)
  541. ResetDevice();
  542. }
  543.  
  544. ImGui_ImplDX9_Shutdown();
  545. ImGui_ImplWin32_Shutdown();
  546. ImGui::DestroyContext();
  547.  
  548. CleanupDeviceD3D();
  549. ::DestroyWindow(hwnd);
  550. ::UnregisterClass(wc.lpszClassName, wc.hInstance);
  551.  
  552. return 0;
  553. }
  554.  
  555.  
  556. bool CreateDeviceD3D(HWND hWnd)
  557. {
  558. if ((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
  559. return false;
  560.  
  561. ZeroMemory(&g_d3dpp, sizeof(g_d3dpp));
  562. g_d3dpp.Windowed = true;
  563. g_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
  564. g_d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
  565. g_d3dpp.EnableAutoDepthStencil = TRUE;
  566. g_d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
  567. g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
  568. //g_d3dpp.PresentationInterval
  569. if (g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &g_d3dpp, &g_pd3dDevice) < 0)
  570. return false;
  571.  
  572. return true;
  573. }
  574.  
  575. void CleanupDeviceD3D()
  576. {
  577. if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
  578. if (g_pD3D) { g_pD3D->Release(); g_pD3D = NULL; }
  579. }
  580.  
  581. void ResetDevice()
  582. {
  583. ImGui_ImplDX9_InvalidateDeviceObjects();
  584. HRESULT hr = g_pd3dDevice->Reset(&g_d3dpp);
  585. if (hr == D3DERR_INVALIDCALL)
  586. IM_ASSERT(0);
  587. ImGui_ImplDX9_CreateDeviceObjects();
  588. }
  589.  
  590. extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  591.  
  592. LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  593. {
  594. if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam))
  595. return true;
  596.  
  597. switch (msg)
  598. {
  599. case WM_SIZE:
  600. if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED)
  601. {
  602. g_d3dpp.BackBufferWidth = LOWORD(lParam);
  603. g_d3dpp.BackBufferHeight = HIWORD(lParam);
  604. ResetDevice();
  605. }
  606. return 0;
  607. case WM_SYSCOMMAND:
  608. if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
  609. return 0;
  610. break;
  611. case WM_DESTROY:
  612. ::PostQuitMessage(0);
  613. return 0;
  614. }
  615. return ::DefWindowProc(hWnd, msg, wParam, lParam);
  616. }
  617.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement