diff --git a/README.md b/README.md index 65f9946..74eb559 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ # window-starter -[![build](https://github.com/McMassiveNZ/blank-slate/actions/workflows/ci.yml/badge.svg)](https://github.com/McMassiveNZ/blank-slate/actions/workflows/ci.yml) +[![build](https://github.com/McMassiveNZ/window-starter/actions/workflows/ci.yml/badge.svg)](https://github.com/McMassiveNZ/window-starter/actions/workflows/ci.yml) A window-starter cpp project which can open a simple window. The project contains boilerplate for CMake, testing and basic CI. Static Analysis, Unit Tests and Sanitizers are off by default diff --git a/src/main.cpp b/src/main.cpp index f212782..a3961ef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,9 +12,9 @@ auto main() -> int .name = "Starter Window" }); - while (window->PumpMessages()) + while (!window->ShouldClose()) { - //do something + window->PumpMessages(); } } diff --git a/src/platform/null_window.cpp b/src/platform/null_window.cpp index 63bdb5e..9e3d114 100644 --- a/src/platform/null_window.cpp +++ b/src/platform/null_window.cpp @@ -3,7 +3,7 @@ namespace starter_window { -class NullWindowImpl : public Window +class NullWindowImpl final : public Window { public: NullWindowImpl() = default; @@ -14,7 +14,8 @@ public: NullWindowImpl(const NullWindowImpl&) = delete; NullWindowImpl& operator=(const NullWindowImpl&) = delete; - bool PumpMessages() override { return true; } + void PumpMessages() override {} + bool ShouldClose() override { return false; } }; diff --git a/src/platform/win32_window.cpp b/src/platform/win32_window.cpp index 7c2ee6f..a295bd1 100644 --- a/src/platform/win32_window.cpp +++ b/src/platform/win32_window.cpp @@ -35,7 +35,7 @@ static LRESULT CALLBACK WindowProc(HWND window, UINT message, WPARAM wParam, LPA namespace starter_window { -class Win32WindowImpl : public Window +class Win32WindowImpl final : public Window { public: Win32WindowImpl(); @@ -46,14 +46,17 @@ public: bool init(WindowCreateParams params); bool PumpMessages() override; + bool ShouldClose() override; HINSTANCE hInstance; HWND hWnd; + bool m_close; }; Win32WindowImpl::Win32WindowImpl() : hInstance(GetModuleHandle(NULL)) , hWnd(nullptr) + , m_close(false) { } @@ -96,18 +99,24 @@ bool Win32WindowImpl::init(WindowCreateParams params) return true; } -bool Win32WindowImpl::PumpMessages() +void Win32WindowImpl::PumpMessages() { MSG message = {}; if (GetMessage(&message, NULL, 0, 0) != 0) { TranslateMessage(&message); DispatchMessage(&message); - return true; } - + else + { // GetMessage returned WM_QUIT - return false; + m_close = true; + } +} + +bool Win32WindowImpl::ShouldClose() +{ + } } // namespace starter_window diff --git a/src/window.h b/src/window.h index d9d4938..91fbc43 100644 --- a/src/window.h +++ b/src/window.h @@ -18,7 +18,8 @@ class Window { public: virtual ~Window() = default; - virtual bool PumpMessages() = 0; + virtual void PumpMessages() = 0; + virtual bool ShouldClose() = 0; }; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c68308a..921320b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,14 +1,14 @@ include(${CMAKE_SCRIPTS_DIR}/googletest.cmake) add_executable( - blank-slate-test + window-starter-test test_main.cpp ) target_link_libraries( - blank-slate-test + window-starter-test gtest_main ) include(GoogleTest) -gtest_discover_tests(blank-slate-test) +gtest_discover_tests(window-starter-test)