Update ReadMe and add ShouldClose() function

- Removed all references to blank-slate
+ added a ShouldClose() function which gets polled to see if the window should close
This commit is contained in:
McMassiveNZ
2023-05-04 20:39:25 +02:00
parent fdd92cc500
commit d4dc5fb2f1
6 changed files with 25 additions and 14 deletions

View File

@@ -1,4 +1,4 @@
# window-starter # 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 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

View File

@@ -12,9 +12,9 @@ auto main() -> int
.name = "Starter Window" .name = "Starter Window"
}); });
while (window->PumpMessages()) while (!window->ShouldClose())
{ {
//do something window->PumpMessages();
} }
} }

View File

@@ -3,7 +3,7 @@
namespace starter_window namespace starter_window
{ {
class NullWindowImpl : public Window class NullWindowImpl final : public Window
{ {
public: public:
NullWindowImpl() = default; NullWindowImpl() = default;
@@ -14,7 +14,8 @@ public:
NullWindowImpl(const NullWindowImpl&) = delete; NullWindowImpl(const NullWindowImpl&) = delete;
NullWindowImpl& operator=(const NullWindowImpl&) = delete; NullWindowImpl& operator=(const NullWindowImpl&) = delete;
bool PumpMessages() override { return true; } void PumpMessages() override {}
bool ShouldClose() override { return false; }
}; };

View File

@@ -35,7 +35,7 @@ static LRESULT CALLBACK WindowProc(HWND window, UINT message, WPARAM wParam, LPA
namespace starter_window namespace starter_window
{ {
class Win32WindowImpl : public Window class Win32WindowImpl final : public Window
{ {
public: public:
Win32WindowImpl(); Win32WindowImpl();
@@ -46,14 +46,17 @@ public:
bool init(WindowCreateParams params); bool init(WindowCreateParams params);
bool PumpMessages() override; bool PumpMessages() override;
bool ShouldClose() override;
HINSTANCE hInstance; HINSTANCE hInstance;
HWND hWnd; HWND hWnd;
bool m_close;
}; };
Win32WindowImpl::Win32WindowImpl() Win32WindowImpl::Win32WindowImpl()
: hInstance(GetModuleHandle(NULL)) : hInstance(GetModuleHandle(NULL))
, hWnd(nullptr) , hWnd(nullptr)
, m_close(false)
{ {
} }
@@ -96,18 +99,24 @@ bool Win32WindowImpl::init(WindowCreateParams params)
return true; return true;
} }
bool Win32WindowImpl::PumpMessages() void Win32WindowImpl::PumpMessages()
{ {
MSG message = {}; MSG message = {};
if (GetMessage(&message, NULL, 0, 0) != 0) if (GetMessage(&message, NULL, 0, 0) != 0)
{ {
TranslateMessage(&message); TranslateMessage(&message);
DispatchMessage(&message); DispatchMessage(&message);
return true;
} }
else
{
// GetMessage returned WM_QUIT // GetMessage returned WM_QUIT
return false; m_close = true;
}
}
bool Win32WindowImpl::ShouldClose()
{
} }
} // namespace starter_window } // namespace starter_window

View File

@@ -18,7 +18,8 @@ class Window
{ {
public: public:
virtual ~Window() = default; virtual ~Window() = default;
virtual bool PumpMessages() = 0; virtual void PumpMessages() = 0;
virtual bool ShouldClose() = 0;
}; };
} }

View File

@@ -1,14 +1,14 @@
include(${CMAKE_SCRIPTS_DIR}/googletest.cmake) include(${CMAKE_SCRIPTS_DIR}/googletest.cmake)
add_executable( add_executable(
blank-slate-test window-starter-test
test_main.cpp test_main.cpp
) )
target_link_libraries( target_link_libraries(
blank-slate-test window-starter-test
gtest_main gtest_main
) )
include(GoogleTest) include(GoogleTest)
gtest_discover_tests(blank-slate-test) gtest_discover_tests(window-starter-test)