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
[![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

View File

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

View File

@@ -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; }
};

View File

@@ -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
m_close = true;
}
}
// GetMessage returned WM_QUIT
return false;
bool Win32WindowImpl::ShouldClose()
{
}
} // namespace starter_window

View File

@@ -18,7 +18,8 @@ class Window
{
public:
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)
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)