Piratux

Untitled

Jan 31st, 2022
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1.  
  2. return olc::rcode::OK;
  3. }
  4.  
  5. olc::rcode SaveImageResource(olc::Sprite* spr, const std::string& sImageFile) override
  6. {
  7. return olc::rcode::OK;
  8. }
  9. };
  10. }
  11. #endif
  12. // O------------------------------------------------------------------------------O
  13. // | START IMAGE LOADER: stb_image.h |
  14. // O------------------------------------------------------------------------------O
  15.  
  16.  
  17. // O------------------------------------------------------------------------------O
  18. // | START PLATFORM: MICROSOFT WINDOWS XP, VISTA, 7, 8, 10 |
  19. // O------------------------------------------------------------------------------O
  20. #if defined(OLC_PLATFORM_WINAPI)
  21.  
  22. #if defined(_WIN32) && !defined(__MINGW32__)
  23. #pragma comment(lib, "user32.lib") // Visual Studio Only
  24. #pragma comment(lib, "gdi32.lib") // For other Windows Compilers please add
  25. #pragma comment(lib, "opengl32.lib") // these libs to your linker input
  26. #endif
  27.  
  28. namespace olc
  29. {
  30. class Platform_Windows : public olc::Platform
  31. {
  32. private:
  33. HWND olc_hWnd = nullptr;
  34. std::wstring wsAppName;
  35.  
  36. std::wstring ConvertS2W(std::string s)
  37. {
  38. #ifdef __MINGW32__
  39. wchar_t* buffer = new wchar_t[s.length() + 1];
  40. mbstowcs(buffer, s.c_str(), s.length());
  41. buffer[s.length()] = L'\0';
  42. #else
  43. int count = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, NULL, 0);
  44. wchar_t* buffer = new wchar_t[count];
  45. MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, buffer, count);
  46. #endif
  47. std::wstring w(buffer);
  48. delete[] buffer;
  49. return w;
  50. }
  51.  
  52. public:
  53. virtual olc::rcode ApplicationStartUp() override { return olc::rcode::OK; }
  54. virtual olc::rcode ApplicationCleanUp() override { return olc::rcode::OK; }
  55. virtual olc::rcode ThreadStartUp() override { return olc::rcode::OK; }
  56.  
  57. virtual olc::rcode ThreadCleanUp() override
  58. {
  59. renderer->DestroyDevice();
  60. PostMessage(olc_hWnd, WM_DESTROY, 0, 0);
  61. return olc::OK;
  62. }
  63.  
  64. virtual olc::rcode CreateGraphics(bool bFullScreen, bool bEnableVSYNC, const olc::vi2d& vViewPos, const olc::vi2d& vViewSize) override
  65. {
  66. if (renderer->CreateDevice({ olc_hWnd }, bFullScreen, bEnableVSYNC) == olc::rcode::OK)
  67. {
  68. renderer->UpdateViewport(vViewPos, vViewSize);
  69. return olc::rcode::OK;
  70. }
  71. else
  72. return olc::rcode::FAIL;
  73. }
  74.  
  75. virtual olc::rcode CreateWindowPane(const olc::vi2d& vWindowPos, olc::vi2d& vWindowSize, bool bFullScreen) override
  76. {
  77. WNDCLASS wc;
  78. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  79. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  80. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  81. wc.hInstance = GetModuleHandle(nullptr);
  82. wc.lpfnWndProc = olc_WindowEvent;
  83. wc.cbClsExtra = 0;
  84. wc.cbWndExtra = 0;
  85. wc.lpszMenuName = nullptr;
  86. wc.hbrBackground = nullptr;
  87. wc.lpszClassName = olcT("OLC_PIXEL_GAME_ENGINE");
  88. RegisterClass(&wc);
  89.  
  90. // Define window furniture
  91. DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
  92. DWORD dwStyle = WS_CAPTION | WS_SYSMENU | WS_VISIBLE | WS_THICKFRAME;
  93.  
  94. olc::vi2d vTopLeft = vWindowPos;
  95.  
  96. // Handle Fullscreen
  97. if (bFullScreen)
  98. {
  99. dwExStyle = 0;
  100. dwStyle = WS_VISIBLE | WS_POPUP;
Advertisement
Add Comment
Please, Sign In to add comment