From dedc74abfa44f7dac344da1868588193f91dd4f1 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 8 Aug 2011 21:43:53 +0200 Subject: SDL: Add a new base class for graphics managers utilizing SDL. --- backends/graphics/sdl/sdl-graphics.cpp | 33 +++++++++++++ backends/graphics/sdl/sdl-graphics.h | 86 ++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 backends/graphics/sdl/sdl-graphics.cpp create mode 100644 backends/graphics/sdl/sdl-graphics.h (limited to 'backends/graphics/sdl') diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp new file mode 100644 index 0000000000..90278a99d1 --- /dev/null +++ b/backends/graphics/sdl/sdl-graphics.cpp @@ -0,0 +1,33 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "backends/graphics/sdl/sdl-graphics.h" + +#include "backends/events/sdl/sdl-events.h" + +SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source) + : _eventSource(source) { +} + +SdlGraphicsManager::~SdlGraphicsManager() { +} + diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h new file mode 100644 index 0000000000..b42eafdaa5 --- /dev/null +++ b/backends/graphics/sdl/sdl-graphics.h @@ -0,0 +1,86 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef BACKENDS_GRAPHICS_SDL_SDLGRAPHICS_H +#define BACKENDS_GRAPHICS_SDL_SDLGRAPHICS_H + +#include "common/rect.h" + +class SdlEventSource; + +/** + * Base class for a SDL based graphics manager. + * + * It features a few extra a few extra features required by SdlEventSource. + * FIXME/HACK: + * Note it does not inherit from GraphicsManager to avoid a diamon inheritance + * in the current OpenGLSdlGraphicsManager. + */ +class SdlGraphicsManager { +public: + SdlGraphicsManager(SdlEventSource *source); + virtual ~SdlGraphicsManager(); + + /** + * Notify the graphics manager that the graphics needs to be redrawn, since + * the application window was modified. + * + * This is basically called when SDL_VIDEOEXPOSE was received. + */ + virtual void notifyVideoExpose() = 0; + + /** + * Notify the graphics manager about an resize event. + * + * It is noteworthy that the requested width/height should actually be set + * up as is and not changed by the graphics manager, since else it might + * lead to odd behavior for certain window managers. + * + * It is only required to overwrite this method in case you want a + * resizable window. The default implementation just does nothing. + * + * @param width Requested window width. + * @param height Requested window height. + */ + virtual void notifyResize(const uint width, const uint height) {} + + /** + * Transforms real screen coordinates into the current active screen + * coordinates (may be either game screen or overlay). + * + * @param point Mouse coordinates to transform. + */ + virtual void transformMouseCoordinates(Common::Point &point) = 0; + + /** + * Notifies the graphics manager about a position change according to the + * real screen coordinates. + * + * @param mouse Mouse position. + */ + virtual void notifyMousePos(Common::Point mouse) = 0; + +protected: + SdlEventSource *_eventSource; +}; + +#endif -- cgit v1.2.3 From 04ab0e58b4142bf58db2180a2bac6897821d069f Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 8 Aug 2011 23:56:54 +0200 Subject: SDL: Take advantage of SdlGraphicsManager. This gets rid of the hacks, where SdlEventSource added events with custom type numbers to pass SDL_VIDEOEXPOSE and SDL_VIDEORESIZE to the graphics manager. Furthermore it get rids of the uninituitive and hard to trace way of assigning the proper mouse coordinates to mouse related events. Formerly it passed the real screen coordinates through the even dispatching api to the graphics manager (at least hopefully ;-) and let that handle creating a new event with the proper coordinates. Now instead SdlEventSource handles the proper coordinate setup itself. Since this is a behavior change and I can not test all the SDL based small devices ports this commit might break compilation for them and more serve it might also break mouse position behavior. If any of that occurs I am sorry about it. --- backends/graphics/sdl/sdl-graphics.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'backends/graphics/sdl') diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp index 90278a99d1..2eca4b8aab 100644 --- a/backends/graphics/sdl/sdl-graphics.cpp +++ b/backends/graphics/sdl/sdl-graphics.cpp @@ -26,8 +26,10 @@ SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source) : _eventSource(source) { + _eventSource->setGraphicsManager(this); } SdlGraphicsManager::~SdlGraphicsManager() { + _eventSource->setGraphicsManager(0); } -- cgit v1.2.3 From dd0ad3cba4534cb9b36dc0b6c8b412a0f1b10cf2 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 18 Aug 2011 23:18:20 +0200 Subject: SDL: Fix typo. --- backends/graphics/sdl/sdl-graphics.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/graphics/sdl') diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h index b42eafdaa5..ea9149fccb 100644 --- a/backends/graphics/sdl/sdl-graphics.h +++ b/backends/graphics/sdl/sdl-graphics.h @@ -32,7 +32,7 @@ class SdlEventSource; * * It features a few extra a few extra features required by SdlEventSource. * FIXME/HACK: - * Note it does not inherit from GraphicsManager to avoid a diamon inheritance + * Note it does not inherit from GraphicsManager to avoid a diamond inheritance * in the current OpenGLSdlGraphicsManager. */ class SdlGraphicsManager { -- cgit v1.2.3