Browse Source

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.
pull/34/head
Vladimír Vondruš 13 years ago
parent
commit
f0eaf04e36
  1. 19
      src/Platform/AbstractXApplication.h
  2. 23
      src/Platform/GlutApplication.h
  3. 47
      src/Platform/NaClApplication.h
  4. 5
      src/Platform/ScreenedApplication.h
  5. 45
      src/Platform/Sdl2Application.h

19
src/Platform/AbstractXApplication.h

@ -111,13 +111,7 @@ class AbstractXApplication {
/** @copydoc Sdl2Application::tryCreateContext() */ /** @copydoc Sdl2Application::tryCreateContext() */
bool tryCreateContext(const Configuration& configuration); bool tryCreateContext(const Configuration& configuration);
/** @{ @name Drawing functions */ /** @{ @name Screen handling */
/** @copydoc Sdl2Application::viewportEvent() */
virtual void viewportEvent(const Vector2i& size) = 0;
/** @copydoc Sdl2Application::drawEvent() */
virtual void drawEvent() = 0;
/** @copydoc Sdl2Application::swapBuffers() */ /** @copydoc Sdl2Application::swapBuffers() */
void swapBuffers(); void swapBuffers();
@ -125,6 +119,17 @@ class AbstractXApplication {
/** @copydoc Sdl2Application::redraw() */ /** @copydoc Sdl2Application::redraw() */
void redraw() { flags |= Flag::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 */ /** @{ @name Keyboard handling */

23
src/Platform/GlutApplication.h

@ -137,13 +137,7 @@ class GlutApplication {
/** @copydoc Sdl2Application::tryCreateContext() */ /** @copydoc Sdl2Application::tryCreateContext() */
bool tryCreateContext(const Configuration& configuration); bool tryCreateContext(const Configuration& configuration);
/** @{ @name Drawing functions */ /** @{ @name Screen handling */
/** @copydoc Sdl2Application::viewportEvent() */
virtual void viewportEvent(const Vector2i& size) = 0;
/** @copydoc Sdl2Application::drawEvent() */
virtual void drawEvent() = 0;
/** @copydoc Sdl2Application::swapBuffers() */ /** @copydoc Sdl2Application::swapBuffers() */
void swapBuffers() { glutSwapBuffers(); } void swapBuffers() { glutSwapBuffers(); }
@ -151,6 +145,17 @@ class GlutApplication {
/** @copydoc Sdl2Application::redraw() */ /** @copydoc Sdl2Application::redraw() */
void redraw() { glutPostRedisplay(); } 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 */ /** @{ @name Keyboard handling */
@ -201,7 +206,11 @@ class GlutApplication {
glutWarpPointer(position.x(), position.y()); glutWarpPointer(position.x(), position.y());
} }
#ifdef DOXYGEN_GENERATING_OUTPUT
protected: protected:
#else
private:
#endif
/** @copydoc Sdl2Application::mousePressEvent() */ /** @copydoc Sdl2Application::mousePressEvent() */
virtual void mousePressEvent(MouseEvent& event); virtual void mousePressEvent(MouseEvent& event);

47
src/Platform/NaClApplication.h

@ -172,19 +172,6 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public
/** @brief Moving is not allowed */ /** @brief Moving is not allowed */
NaClApplication& operator=(NaClApplication&&) = delete; 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: protected:
/* Nobody will need to have (and delete) NaClApplication*, thus this is /* Nobody will need to have (and delete) NaClApplication*, thus this is
faster than public pure virtual destructor */ faster than public pure virtual destructor */
@ -202,20 +189,40 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public
/** @copydoc Sdl2Application::tryCreateContext() */ /** @copydoc Sdl2Application::tryCreateContext() */
bool tryCreateContext(const Configuration& configuration); bool tryCreateContext(const Configuration& configuration);
/** @{ @name Drawing functions */ /** @{ @name Screen handling */
/** @copydoc Sdl2Application::viewportEvent() */ public:
virtual void viewportEvent(const Vector2i& size) = 0; /** @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() */ /** @copydoc Sdl2Application::swapBuffers() */
void swapBuffers(); void swapBuffers();
/** @copydoc Sdl2Application::redraw() */ /** @copydoc Sdl2Application::redraw() */
void redraw() { flags |= Flag::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 */ /** @{ @name Keyboard handling */
@ -255,7 +262,11 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public
*/ */
void setMouseLocked(bool enabled); void setMouseLocked(bool enabled);
#ifdef DOXYGEN_GENERATING_OUTPUT
protected: protected:
#else
private:
#endif
/** /**
* @brief Mouse press event * @brief Mouse press event
* *

5
src/Platform/ScreenedApplication.h

@ -161,6 +161,11 @@ template<class Application> class BasicScreenedApplication: public Application,
this is faster than public pure virtual destructor */ this is faster than public pure virtual destructor */
~BasicScreenedApplication(); ~BasicScreenedApplication();
#ifdef DOXYGEN_GENERATING_OUTPUT
protected:
#else
private:
#endif
/** /**
* @brief Global viewport event * @brief Global viewport event
* *

45
src/Platform/Sdl2Application.h

@ -210,8 +210,28 @@ class Sdl2Application {
*/ */
bool tryCreateContext(const Configuration& configuration); 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 * @brief Viewport event
* *
@ -236,21 +256,6 @@ class Sdl2Application {
*/ */
virtual void drawEvent() = 0; 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 */ /** @{ @name Keyboard handling */
@ -281,12 +286,16 @@ class Sdl2Application {
* @brief Enable or disable mouse locking * @brief Enable or disable mouse locking
* *
* When mouse is locked, the cursor is hidden and only * When mouse is locked, the cursor is hidden and only
* MouseMoveEvent::relativePosition() is changing, absolute position * @ref MouseMoveEvent::relativePosition() is changing, absolute
* stays the same. * position stays the same.
*/ */
void setMouseLocked(bool enabled); void setMouseLocked(bool enabled);
#ifdef DOXYGEN_GENERATING_OUTPUT
protected: protected:
#else
private:
#endif
/** /**
* @brief Mouse press event * @brief Mouse press event
* *

Loading…
Cancel
Save