summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcflip <cflip@cflip.net>2022-03-21 21:31:13 -0600
committercflip <cflip@cflip.net>2022-03-21 22:13:14 -0600
commitbc5bac66b18de6d377f6b9562f9847e66482bc32 (patch)
treebb7428fc09d00d2056f5c87befe801f0cd44339a
parente13dd6b4625f4b56941ae38f9278b175b4c15c05 (diff)
Minor improvements in Window class
* Ensure event callbacks are not null before calling them * Mark shouldClose() as const * Use nullptr instead of NULL
-rw-r--r--src/window.cpp13
-rw-r--r--src/window.h2
2 files changed, 9 insertions, 6 deletions
diff --git a/src/window.cpp b/src/window.cpp
index 5f8de7e..3a06f18 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -38,13 +38,16 @@ void Window::update()
m_isRunning = false;
break;
case SDL_MOUSEBUTTONDOWN:
- m_mouseDown(event.button.button, event.button.x, event.button.y);
+ if (m_mouseDown)
+ m_mouseDown(event.button.button, event.button.x, event.button.y);
break;
case SDL_MOUSEMOTION:
- m_mouseMove(event.button.x, event.button.y);
+ if (m_mouseMove)
+ m_mouseMove(event.button.x, event.button.y);
break;
case SDL_MOUSEBUTTONUP:
- m_mouseUp(event.button.button, event.button.x, event.button.y);
+ if (m_mouseUp)
+ m_mouseUp(event.button.button, event.button.x, event.button.y);
break;
}
}
@@ -56,7 +59,7 @@ void Window::update()
void Window::draw(Bitmap& bitmap)
{
SDL_RenderClear(m_renderer);
- SDL_UpdateTexture(m_texture, NULL, bitmap.data, m_width * 4);
- SDL_RenderCopy(m_renderer, m_texture, NULL, NULL);
+ SDL_UpdateTexture(m_texture, nullptr, bitmap.data, m_width * 4);
+ SDL_RenderCopy(m_renderer, m_texture, nullptr, nullptr);
SDL_RenderPresent(m_renderer);
} \ No newline at end of file
diff --git a/src/window.h b/src/window.h
index 14494a6..fb9d255 100644
--- a/src/window.h
+++ b/src/window.h
@@ -16,7 +16,7 @@ public:
void update();
void draw(Bitmap&);
- bool shouldClose() { return !m_isRunning; }
+ bool shouldClose() const { return !m_isRunning; }
void onMouseDown(std::function<void(int, int, int)> callback) { m_mouseDown = callback; }
void onMouseUp(std::function<void(int, int, int)> callback) { m_mouseUp = callback; }