This commit is contained in:
Attila Uygun 2023-08-09 23:03:08 +02:00
parent 92dbf5cd97
commit 41a1cfe6f5
2 changed files with 65 additions and 67 deletions

View File

@ -36,7 +36,7 @@ class Platform {
#elif defined(__linux__) #elif defined(__linux__)
Platform(); Platform();
#elif defined(_WIN32) #elif defined(_WIN32)
Platform(HINSTANCE hInstance, int nCmdShow); Platform(HINSTANCE instance, int cmd_show);
#endif #endif
~Platform(); ~Platform();
@ -127,11 +127,10 @@ class Platform {
#elif defined(_WIN32) #elif defined(_WIN32)
// Global Variables: HINSTANCE instance_;
HINSTANCE hInst; // current instance HWND wnd_;
HWND hWnd; int cmd_show_;
// Forward declarations of functions included in this code module:
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
#endif #endif

View File

@ -8,7 +8,7 @@
#include "base/log.h" #include "base/log.h"
// #include "base/vecmath.h" // #include "base/vecmath.h"
// #include "engine/input_event.h" // #include "engine/input_event.h"
// #include "engine/platform/platform_observer.h" #include "engine/platform/platform_observer.h"
using namespace base; using namespace base;
@ -16,7 +16,8 @@ namespace eng {
void KaliberMain(Platform* platform); void KaliberMain(Platform* platform);
Platform::Platform(HINSTANCE hInstance, int nCmdShow) : hInst(hInstance) { Platform::Platform(HINSTANCE instance, int cmd_show)
: instance_(instance), cmd_show_(cmd_show) {
LOG(0) << "Initializing platform."; LOG(0) << "Initializing platform.";
root_path_ = "./"; root_path_ = "./";
@ -33,31 +34,44 @@ Platform::Platform(HINSTANCE hInstance, int nCmdShow) : hInst(hInstance) {
wcex.lpfnWndProc = WndProc; wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0; wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0; wcex.cbWndExtra = 0;
wcex.hInstance = hInstance; wcex.hInstance = instance_;
wcex.hIcon = wcex.hIcon = nullptr;
nullptr; // LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WINDOWSPROJECT1));
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wcex.hbrBackground = nullptr;
wcex.lpszMenuName = nullptr; // MAKEINTRESOURCEW(IDC_WINDOWSPROJECT1); wcex.lpszMenuName = nullptr;
wcex.lpszClassName = L"szWindowClass"; wcex.lpszClassName = L"KaliberWndClass";
wcex.hIconSm = wcex.hIconSm = nullptr;
nullptr; // LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); RegisterClassEx(&wcex);
RegisterClassExW(&wcex); }
hWnd = CreateWindowW(L"szWindowClass", L"kaliber", WS_OVERLAPPEDWINDOW, void Platform::CreateMainWindow() {
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, wnd_ = CreateWindow(L"KaliberWndClass", L"Kaliber", WS_OVERLAPPEDWINDOW,
hInstance, nullptr); CW_USEDEFAULT, 0, 800, 1205, nullptr, nullptr, instance_,
CHECK(hWnd); this);
CHECK(wnd_);
ShowWindow(hWnd, nCmdShow); ShowWindow(wnd_, cmd_show_);
UpdateWindow(hWnd); UpdateWindow(wnd_);
} }
Platform::~Platform() { Platform::~Platform() {
LOG(0) << "Shutting down platform."; LOG(0) << "Shutting down platform.";
DestroyWindow(wnd_);
} }
void Platform::Update() {} void Platform::Update() {
DCHECK(!should_exit_);
MSG msg;
while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT) {
should_exit_ = true;
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
void Platform::Exit() { void Platform::Exit() {
should_exit_ = true; should_exit_ = true;
@ -72,60 +86,45 @@ void Platform::ShareFile(const std::string& file_name) {}
void Platform::SetKeepScreenOn(bool keep_screen_on) {} void Platform::SetKeepScreenOn(bool keep_screen_on) {}
HINSTANCE Platform::GetInstance() { HINSTANCE Platform::GetInstance() {
return hInst; return instance_;
} }
HWND Platform::GetWindow() { HWND Platform::GetWindow() {
return hWnd; return wnd_;
} }
LRESULT CALLBACK Platform::WndProc(HWND hWnd, LRESULT CALLBACK Platform::WndProc(HWND wnd,
UINT message, UINT message,
WPARAM wParam, WPARAM wparam,
LPARAM lParam) { LPARAM lparam) {
// switch (message) auto* platform =
// { reinterpret_cast<Platform*>(GetWindowLongPtr(wnd, GWL_USERDATA));
// case WM_COMMAND:
// { switch (message) {
// int wmId = LOWORD(wParam); case WM_CREATE:
// // Parse the menu selections: SetWindowLongPtr(wnd, GWL_USERDATA,
// switch (wmId) (LONG_PTR)(((LPCREATESTRUCT)lparam)->lpCreateParams));
// { break;
// case IDM_ABOUT: case WM_SIZE:
// DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); platform->observer_->OnWindowResized(LOWORD(lparam), HIWORD(lparam));
// break; break;
// case IDM_EXIT: case WM_DESTROY:
// DestroyWindow(hWnd); platform->observer_->OnWindowDestroyed();
// break; PostQuitMessage(0);
// default: break;
// return DefWindowProc(hWnd, message, wParam, lParam); default:
// } return DefWindowProc(wnd, message, wparam, lparam);
// } }
// break; return 0;
// case WM_PAINT:
// {
// PAINTSTRUCT ps;
// HDC hdc = BeginPaint(hWnd, &ps);
// // TODO: Add any drawing code that uses hdc here...
// EndPaint(hWnd, &ps);
// }
// break;
// case WM_DESTROY:
// PostQuitMessage(0);
// break;
// default:
return DefWindowProc(hWnd, message, wParam, lParam);
// }
// return 0;
} }
} // namespace eng } // namespace eng
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, int WINAPI WinMain(HINSTANCE instance,
_In_opt_ HINSTANCE hPrevInstance, HINSTANCE prev_instance,
_In_ LPWSTR lpCmdLine, PSTR cmd_line,
_In_ int nCmdShow) { int cmd_show) {
eng::Platform platform(hInstance, nCmdShow); eng::Platform platform(instance, cmd_show);
eng::KaliberMain(&platform); eng::KaliberMain(&platform);
return 0; return 0;
} }