From d03fe4d41d4b63b7451369ad4575d39a3e2139d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 9 Aug 2012 02:03:48 +0200 Subject: [PATCH] Limited static polymorphism of EglContext and GlutContext. If being careful, it's now possible to swap GlutContext with EglContext. GlutContext doesn't have keyReleaseEvent() and many keys, but EglContext doesn't have e.g. mouseMotionEvent(). --- src/Contexts/EglContext.h | 3 +++ src/Contexts/GlutContext.h | 40 +++++++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/Contexts/EglContext.h b/src/Contexts/EglContext.h index 02e337129..1c1c7f628 100644 --- a/src/Contexts/EglContext.h +++ b/src/Contexts/EglContext.h @@ -74,6 +74,9 @@ class EglContext: public AbstractContext { /** @copydoc GlutContext::swapBuffers() */ inline void swapBuffers() { eglSwapBuffers(display, surface); } + /** @todo implement */ + inline void redraw() {} + /*@}*/ /** @{ @name Keyboard handling */ diff --git a/src/Contexts/GlutContext.h b/src/Contexts/GlutContext.h index 454bd5b0a..17a3c921c 100644 --- a/src/Contexts/GlutContext.h +++ b/src/Contexts/GlutContext.h @@ -123,11 +123,13 @@ class GlutContext: public AbstractContext { protected: /** - * @brief Key event + * @brief Key press event + * @param key Key pressed + * @param position Cursor position * * Called when an key is pressed. Default implementation does nothing. */ - virtual void keyEvent(Key key, const Math::Vector2& position); + virtual void keyPressEvent(Key key, const Math::Vector2& position); /*@}*/ @@ -143,12 +145,6 @@ class GlutContext: public AbstractContext { WheelDown = 4 /**< Wheel down */ }; - /** @brief Mouse state */ - enum class MouseState: int { - Up = GLUT_UP, /**< No button pressed */ - Down = GLUT_DOWN /**< Button pressed */ - }; - /** @brief Mouse cursor */ enum class MouseCursor: int { Default = GLUT_CURSOR_INHERIT, /**< Default cursor provided by parent window */ @@ -177,12 +173,20 @@ class GlutContext: public AbstractContext { protected: /** - * @brief Mouse event + * @brief Mouse press event * - * Called when mouse button is pressed or released. Default - * implementation does nothing. + * Called when mouse button is pressed. Default implementation does + * nothing. + */ + virtual void mousePressEvent(MouseButton button, const Math::Vector2& position); + + /** + * @brief Mouse release event + * + * Called when mouse button is released. Default implementation does + * nothing. */ - virtual void mouseEvent(MouseButton button, MouseState state, const Math::Vector2& position); + virtual void mouseReleaseEvent(MouseButton button, const Math::Vector2& position); /** * @brief Mouse motion event @@ -202,11 +206,14 @@ class GlutContext: public AbstractContext { } inline static void staticKeyEvent(int key, int x, int y) { - instance->keyEvent(static_cast(key), {x, y}); + instance->keyPressEvent(static_cast(key), {x, y}); } inline static void staticMouseEvent(int button, int state, int x, int y) { - instance->mouseEvent(static_cast(button), static_cast(state), {x, y}); + if(state == GLUT_DOWN) + instance->mousePressEvent(static_cast(button), {x, y}); + else + instance->mouseReleaseEvent(static_cast(button), {x, y}); } inline static void staticMouseMotionEvent(int x, int y) { @@ -224,8 +231,9 @@ class GlutContext: public AbstractContext { }; /* Implementations for inline functions with unused parameters */ -inline void GlutContext::keyEvent(GlutContext::Key, const Math::Vector2&) {} -inline void GlutContext::mouseEvent(GlutContext::MouseButton, GlutContext::MouseState, const Math::Vector2&) {} +inline void GlutContext::keyPressEvent(GlutContext::Key, const Math::Vector2&) {} +inline void GlutContext::mousePressEvent(GlutContext::MouseButton, const Math::Vector2&) {} +inline void GlutContext::mouseReleaseEvent(GlutContext::MouseButton, const Math::Vector2&) {} inline void GlutContext::mouseMotionEvent(const Math::Vector2&) {} }}