From f0eaf04e3674eb056a3870782c5dbe14e5d2f924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 7 Dec 2013 20:58:05 +0100 Subject: [PATCH] Platform: make virtual functions private, rendering protected, other public. * The default (empty) implementation of virtuals shouldn't be called, thus this effectively protects the user from doing it. * Only the application itself knows best when and how to call rendering-related functions such as swapBuffers() and redraw(), thus they are protected. * Functions for setting up fullscreen or hiding the mouse may be called from user code outside the application, thus they are kept public. --- src/Platform/AbstractXApplication.h | 19 +++++++----- src/Platform/GlutApplication.h | 23 +++++++++----- src/Platform/NaClApplication.h | 47 ++++++++++++++++++----------- src/Platform/ScreenedApplication.h | 5 +++ src/Platform/Sdl2Application.h | 45 ++++++++++++++++----------- 5 files changed, 89 insertions(+), 50 deletions(-) diff --git a/src/Platform/AbstractXApplication.h b/src/Platform/AbstractXApplication.h index 9d0bb7f29..8e8a1ec40 100644 --- a/src/Platform/AbstractXApplication.h +++ b/src/Platform/AbstractXApplication.h @@ -111,13 +111,7 @@ class AbstractXApplication { /** @copydoc Sdl2Application::tryCreateContext() */ bool tryCreateContext(const Configuration& configuration); - /** @{ @name Drawing functions */ - - /** @copydoc Sdl2Application::viewportEvent() */ - virtual void viewportEvent(const Vector2i& size) = 0; - - /** @copydoc Sdl2Application::drawEvent() */ - virtual void drawEvent() = 0; + /** @{ @name Screen handling */ /** @copydoc Sdl2Application::swapBuffers() */ void swapBuffers(); @@ -125,6 +119,17 @@ class AbstractXApplication { /** @copydoc Sdl2Application::redraw() */ void redraw() { flags |= Flag::Redraw; } + #ifdef DOXYGEN_GENERATING_OUTPUT + protected: + #else + private: + #endif + /** @copydoc Sdl2Application::viewportEvent() */ + virtual void viewportEvent(const Vector2i& size) = 0; + + /** @copydoc Sdl2Application::drawEvent() */ + virtual void drawEvent() = 0; + /*@}*/ /** @{ @name Keyboard handling */ diff --git a/src/Platform/GlutApplication.h b/src/Platform/GlutApplication.h index 97452a23b..e7267abe7 100644 --- a/src/Platform/GlutApplication.h +++ b/src/Platform/GlutApplication.h @@ -137,13 +137,7 @@ class GlutApplication { /** @copydoc Sdl2Application::tryCreateContext() */ bool tryCreateContext(const Configuration& configuration); - /** @{ @name Drawing functions */ - - /** @copydoc Sdl2Application::viewportEvent() */ - virtual void viewportEvent(const Vector2i& size) = 0; - - /** @copydoc Sdl2Application::drawEvent() */ - virtual void drawEvent() = 0; + /** @{ @name Screen handling */ /** @copydoc Sdl2Application::swapBuffers() */ void swapBuffers() { glutSwapBuffers(); } @@ -151,6 +145,17 @@ class GlutApplication { /** @copydoc Sdl2Application::redraw() */ void redraw() { glutPostRedisplay(); } + #ifdef DOXYGEN_GENERATING_OUTPUT + protected: + #else + private: + #endif + /** @copydoc Sdl2Application::viewportEvent() */ + virtual void viewportEvent(const Vector2i& size) = 0; + + /** @copydoc Sdl2Application::drawEvent() */ + virtual void drawEvent() = 0; + /*@}*/ /** @{ @name Keyboard handling */ @@ -201,7 +206,11 @@ class GlutApplication { glutWarpPointer(position.x(), position.y()); } + #ifdef DOXYGEN_GENERATING_OUTPUT protected: + #else + private: + #endif /** @copydoc Sdl2Application::mousePressEvent() */ virtual void mousePressEvent(MouseEvent& event); diff --git a/src/Platform/NaClApplication.h b/src/Platform/NaClApplication.h index 2e48bfc2e..0c9203f03 100644 --- a/src/Platform/NaClApplication.h +++ b/src/Platform/NaClApplication.h @@ -172,19 +172,6 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public /** @brief Moving is not allowed */ NaClApplication& operator=(NaClApplication&&) = delete; - /** @brief Whether the application runs fullscreen */ - bool isFullscreen(); - - /** - * @brief Set fullscreen - * @return `False` if switch to opposite mode is in progress or if the - * switch is not possible, `true` otherwise. - * - * The switch is done asynchronously, during the switch no event - * processing is done. - */ - bool setFullscreen(bool enabled); - protected: /* Nobody will need to have (and delete) NaClApplication*, thus this is faster than public pure virtual destructor */ @@ -202,20 +189,40 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public /** @copydoc Sdl2Application::tryCreateContext() */ bool tryCreateContext(const Configuration& configuration); - /** @{ @name Drawing functions */ + /** @{ @name Screen handling */ - /** @copydoc Sdl2Application::viewportEvent() */ - virtual void viewportEvent(const Vector2i& size) = 0; + public: + /** @brief Whether the application runs fullscreen */ + bool isFullscreen(); - /** @copydoc Sdl2Application::drawEvent() */ - virtual void drawEvent() = 0; + /** + * @brief Set fullscreen + * @return `False` if switch to opposite mode is in progress or if the + * switch is not possible, `true` otherwise. + * + * The switch is done asynchronously, during the switch no event + * processing is done. + */ + bool setFullscreen(bool enabled); + protected: /** @copydoc Sdl2Application::swapBuffers() */ void swapBuffers(); /** @copydoc Sdl2Application::redraw() */ void redraw() { flags |= Flag::Redraw; } + #ifdef DOXYGEN_GENERATING_OUTPUT + protected: + #else + private: + #endif + /** @copydoc Sdl2Application::viewportEvent() */ + virtual void viewportEvent(const Vector2i& size) = 0; + + /** @copydoc Sdl2Application::drawEvent() */ + virtual void drawEvent() = 0; + /*@}*/ /** @{ @name Keyboard handling */ @@ -255,7 +262,11 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public */ void setMouseLocked(bool enabled); + #ifdef DOXYGEN_GENERATING_OUTPUT protected: + #else + private: + #endif /** * @brief Mouse press event * diff --git a/src/Platform/ScreenedApplication.h b/src/Platform/ScreenedApplication.h index dc962bdf9..2836a63b1 100644 --- a/src/Platform/ScreenedApplication.h +++ b/src/Platform/ScreenedApplication.h @@ -161,6 +161,11 @@ template class BasicScreenedApplication: public Application, this is faster than public pure virtual destructor */ ~BasicScreenedApplication(); + #ifdef DOXYGEN_GENERATING_OUTPUT + protected: + #else + private: + #endif /** * @brief Global viewport event * diff --git a/src/Platform/Sdl2Application.h b/src/Platform/Sdl2Application.h index d13a98dc4..7df1cbf30 100644 --- a/src/Platform/Sdl2Application.h +++ b/src/Platform/Sdl2Application.h @@ -210,8 +210,28 @@ class Sdl2Application { */ bool tryCreateContext(const Configuration& configuration); - /** @{ @name Drawing functions */ + /** @{ @name Screen handling */ + /** + * @brief Swap buffers + * + * Paints currently rendered framebuffer on screen. + */ + void swapBuffers(); + + /** + * @brief Redraw immediately + * + * Marks the window for redrawing, resulting in call to @ref drawEvent() + * in the next iteration. + */ + void redraw() { flags |= Flag::Redraw; } + + #ifdef DOXYGEN_GENERATING_OUTPUT + protected: + #else + private: + #endif /** * @brief Viewport event * @@ -236,21 +256,6 @@ class Sdl2Application { */ virtual void drawEvent() = 0; - /** - * @brief Swap buffers - * - * Paints currently rendered framebuffer on screen. - */ - void swapBuffers(); - - /** - * @brief Redraw immediately - * - * Marks the window for redrawing, resulting in call to @ref drawEvent() - * in the next iteration. - */ - void redraw() { flags |= Flag::Redraw; } - /*@}*/ /** @{ @name Keyboard handling */ @@ -281,12 +286,16 @@ class Sdl2Application { * @brief Enable or disable mouse locking * * When mouse is locked, the cursor is hidden and only - * MouseMoveEvent::relativePosition() is changing, absolute position - * stays the same. + * @ref MouseMoveEvent::relativePosition() is changing, absolute + * position stays the same. */ void setMouseLocked(bool enabled); + #ifdef DOXYGEN_GENERATING_OUTPUT protected: + #else + private: + #endif /** * @brief Mouse press event *