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:
@@ -1,4 +1,4 @@
|
|||||||
# window-starter
|
# window-starter
|
||||||
[](https://github.com/McMassiveNZ/blank-slate/actions/workflows/ci.yml)
|
[](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
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ auto main() -> int
|
|||||||
.name = "Starter Window"
|
.name = "Starter Window"
|
||||||
});
|
});
|
||||||
|
|
||||||
while (window->PumpMessages())
|
while (!window->ShouldClose())
|
||||||
{
|
{
|
||||||
//do something
|
window->PumpMessages();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user