aboutsummaryrefslogtreecommitdiff
path: root/graphics
diff options
context:
space:
mode:
authorTorbjörn Andersson2006-05-25 22:51:42 +0000
committerTorbjörn Andersson2006-05-25 22:51:42 +0000
commit8062eb6ec33e32012da28f0cd06b8f9334c26937 (patch)
tree088c83206fbb0e4feea93ebeada0a505599572bb /graphics
parentd56c65bf4a47007dc874b70eb04be9ed7de27b01 (diff)
downloadscummvm-rg350-8062eb6ec33e32012da28f0cd06b8f9334c26937.tar.gz
scummvm-rg350-8062eb6ec33e32012da28f0cd06b8f9334c26937.tar.bz2
scummvm-rg350-8062eb6ec33e32012da28f0cd06b8f9334c26937.zip
Set and show/hide mouse cursors through a "cursor manager" (analogous to the
recently added (cursor) palette manager) so that the cursor can be properly restored after returning from the GUI. If there's any C++ magic that can keep the backend functions from being called by anything else than these managing classes, that would probably be a good idea. Also, since the cursor manager keeps a copy of the cursor image, perhaps there are at least some backends that will no longer need to? svn-id: r22639
Diffstat (limited to 'graphics')
-rw-r--r--graphics/cursorman.cpp108
-rw-r--r--graphics/cursorman.h120
-rw-r--r--graphics/module.mk1
3 files changed, 229 insertions, 0 deletions
diff --git a/graphics/cursorman.cpp b/graphics/cursorman.cpp
new file mode 100644
index 0000000000..c1b8e38a92
--- /dev/null
+++ b/graphics/cursorman.cpp
@@ -0,0 +1,108 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2006 The ScummVM project
+ *
+ * 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.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#include "graphics/cursorman.h"
+
+#include "common/system.h"
+#include "common/stack.h"
+
+DECLARE_SINGLETON(Graphics::CursorManager);
+
+namespace Graphics {
+
+static bool g_initialized = false;
+
+CursorManager::CursorManager() {
+ if (!g_initialized) {
+ g_initialized = true;
+ _cursorStack.clear();
+ }
+}
+
+bool CursorManager::isVisible() {
+ if (_cursorStack.empty())
+ return false;
+ return _cursorStack.top()->_visible;
+}
+
+bool CursorManager::showMouse(bool visible) {
+ if (_cursorStack.empty())
+ return false;
+
+ _cursorStack.top()->_visible = visible;
+ return g_system->showMouse(visible);
+}
+
+void CursorManager::pushCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int targetScale) {
+ Cursor *cur = new Cursor(buf, w, h, hotspotX, hotspotY, keycolor, targetScale);
+
+ cur->_visible = isVisible();
+ _cursorStack.push(cur);
+
+ if (buf) {
+ g_system->setMouseCursor(cur->_data, w, h, hotspotX, hotspotY, keycolor, targetScale);
+ }
+}
+
+void CursorManager::popCursor() {
+ if (_cursorStack.empty())
+ return;
+
+ Cursor *cur = _cursorStack.pop();
+ delete cur;
+
+ if (!_cursorStack.empty()) {
+ cur = _cursorStack.top();
+ g_system->setMouseCursor(cur->_data, cur->_width, cur->_height, cur->_hotspotX, cur->_hotspotY, cur->_keycolor, cur->_targetScale);
+ }
+
+ g_system->showMouse(isVisible());
+}
+
+void CursorManager::replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor, int targetScale) {
+ if (_cursorStack.empty()) {
+ pushCursor(buf, w, h, hotspotX, hotspotY, keycolor, targetScale);
+ return;
+ }
+
+ Cursor *cur = _cursorStack.top();
+ uint size = w * h;
+
+ if (cur->_size < size) {
+ delete cur->_data;
+ cur->_data = new byte[size];
+ cur->_size = size;
+ }
+
+ if (buf && cur->_data)
+ memcpy(cur->_data, buf, size);
+
+ cur->_width = w;
+ cur->_height = h;
+ cur->_hotspotX = hotspotX;
+ cur->_hotspotY = hotspotY;
+ cur->_keycolor = keycolor;
+ cur->_targetScale = targetScale;
+
+ g_system->setMouseCursor(cur->_data, w, h, hotspotX, hotspotY, keycolor, targetScale);
+}
+
+} // End of namespace Graphics
diff --git a/graphics/cursorman.h b/graphics/cursorman.h
new file mode 100644
index 0000000000..f86883f1e1
--- /dev/null
+++ b/graphics/cursorman.h
@@ -0,0 +1,120 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2006 The ScummVM project
+ *
+ * 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.
+ *
+ * $URL$
+ * $Id$
+ */
+
+#ifndef GRAPHICS_CURSORMAN_H
+#define GRAPHICS_CURSORMAN_H
+
+#include "common/stdafx.h"
+#include "common/scummsys.h"
+#include "common/stack.h"
+#include "common/singleton.h"
+
+namespace Graphics {
+
+class CursorManager : public Common::Singleton<CursorManager> {
+public:
+ bool isVisible();
+ bool showMouse(bool visible);
+
+ /**
+ * Push a new cursor onto the stack, and set it in the backend. A local
+ * copy will be made of the cursor data, so the original buffer can be
+ * safely freed afterwards.
+ *
+ * @param buf the new cursor data
+ * @param w the width
+ * @param h the height
+ * @param hotspotX the hotspot X coordinate
+ * @param hotspotY the hotspot Y coordinate
+ * @param keycolor the index for the transparent color
+ * @param targetScale the scale for which the cursor is designed
+ *
+ * @note It is ok for the buffer to be a NULL pointer. It is sometimes
+ * useful to push a "dummy" cursor and modify it later. The
+ * cursor will be added to the stack, but not to the backend.
+ */
+ void pushCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int targetScale = 1);
+
+ /**
+ * Pop a cursor from the stack, and restore the previous one to the
+ * backend. If there is no previous cursor, the cursor is hidden.
+ */
+ void popCursor();
+
+ /**
+ * Replace the current cursor on the stack. If the stack is empty, the
+ * cursor is pushed instead. It's a slightly more optimized way of
+ * popping the old cursor before pushing the new one.
+ *
+ * @param buf the new cursor data
+ * @param w the width
+ * @param h the height
+ * @param hotspotX the hotspot X coordinate
+ * @param hotspotY the hotspot Y coordinate
+ * @param keycolor the index for the transparent color
+ * @param targetScale the scale for which the cursor is designed
+ */
+ void replaceCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int targetScale = 1);
+
+private:
+ friend class Common::Singleton<SingletonBaseType>;
+ CursorManager();
+
+ struct Cursor {
+ byte *_data;
+ bool _visible;
+ uint _width;
+ uint _height;
+ int _hotspotX;
+ int _hotspotY;
+ byte _keycolor;
+ byte _targetScale;
+
+ uint _size;
+
+ Cursor(const byte *data, uint w, uint h, int hotspotX, int hotspotY, byte keycolor = 255, int targetScale = 1) {
+ _size = w * h;
+ _data = new byte[_size];
+ if (data && _data)
+ memcpy(_data, data, _size);
+ _width = w;
+ _height = h;
+ _hotspotX = hotspotX;
+ _hotspotY = hotspotY;
+ _keycolor = keycolor;
+ _targetScale = targetScale;
+ }
+
+ ~Cursor() {
+ delete [] _data;
+ }
+ };
+
+ Common::Stack<Cursor *> _cursorStack;
+};
+
+
+} // End of namespace Graphics
+
+/** Shortcut for accessing the cursor manager. */
+#define CursorMan (::Graphics::CursorManager::instance())
+
+#endif
diff --git a/graphics/module.mk b/graphics/module.mk
index 1bf6536448..d5566996d7 100644
--- a/graphics/module.mk
+++ b/graphics/module.mk
@@ -2,6 +2,7 @@ MODULE := graphics
MODULE_OBJS := \
animation.o \
+ cursorman.o \
font.o \
fontman.o \
fonts/consolefont.o \