aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorFilippos Karapetis2016-10-10 04:50:35 +0300
committerFilippos Karapetis2016-10-10 04:50:35 +0300
commit375618828f5131dc3a838b51ffca7f7a6973b8f2 (patch)
treec94ff9ff1a59d5dc01c6d9829840df9fca630b22 /engines
parent684cbfa2fdee6d2927409670a22ecc571ef31a02 (diff)
downloadscummvm-rg350-375618828f5131dc3a838b51ffca7f7a6973b8f2.tar.gz
scummvm-rg350-375618828f5131dc3a838b51ffca7f7a6973b8f2.tar.bz2
scummvm-rg350-375618828f5131dc3a838b51ffca7f7a6973b8f2.zip
CHEWY: Move cursor related functions into a separate file
Diffstat (limited to 'engines')
-rw-r--r--engines/chewy/chewy.cpp9
-rw-r--r--engines/chewy/chewy.h2
-rw-r--r--engines/chewy/cursor.cpp107
-rw-r--r--engines/chewy/cursor.h54
-rw-r--r--engines/chewy/events.cpp5
-rw-r--r--engines/chewy/graphics.cpp54
-rw-r--r--engines/chewy/graphics.h10
-rw-r--r--engines/chewy/module.mk1
8 files changed, 176 insertions, 66 deletions
diff --git a/engines/chewy/chewy.cpp b/engines/chewy/chewy.cpp
index 3845bfd4d1..1172728695 100644
--- a/engines/chewy/chewy.cpp
+++ b/engines/chewy/chewy.cpp
@@ -31,6 +31,7 @@
#include "chewy/chewy.h"
#include "chewy/console.h"
+#include "chewy/cursor.h"
#include "chewy/events.h"
#include "chewy/graphics.h"
#include "chewy/resource.h"
@@ -59,12 +60,14 @@ ChewyEngine::~ChewyEngine() {
delete _events;
delete _text;
delete _sound;
+ delete _cursor;
delete _graphics;
delete _console;
}
void ChewyEngine::initialize() {
_console = new Console(this);
+ _cursor = new Cursor(this);
_graphics = new Graphics(this);
_sound = new Sound(_mixer);
_text = new Text();
@@ -92,8 +95,8 @@ Common::Error ChewyEngine::run() {
_graphics->drawSprite("det1.taf", 0, 200, 100);
_graphics->loadFont("6x8.tff");
_graphics->drawText("This is a test", 200, 80);
- _graphics->showCursor();
- _graphics->setCursor(0);
+ _cursor->showCursor();
+ _cursor->setCursor(0);
//_sound->playSpeech(1);
//_sound->playSound(1);
//_sound->playMusic(2);
@@ -106,7 +109,7 @@ Common::Error ChewyEngine::run() {
// Cursor animation
if (_elapsedFrames % 30 == 0)
- _graphics->animateCursor();
+ _cursor->animateCursor();
if (_videoNum >= 0) {
_graphics->playVideo(_videoNum);
diff --git a/engines/chewy/chewy.h b/engines/chewy/chewy.h
index 7caed6ed75..64ec3a4dce 100644
--- a/engines/chewy/chewy.h
+++ b/engines/chewy/chewy.h
@@ -38,6 +38,7 @@ namespace Chewy {
struct ChewyGameDescription;
class Console;
+class Cursor;
class Events;
class Graphics;
class Sound;
@@ -59,6 +60,7 @@ public:
void setPlayVideo(uint num) { _videoNum = num; }
Graphics *_graphics;
+ Cursor *_cursor;
Sound *_sound;
Text *_text;
diff --git a/engines/chewy/cursor.cpp b/engines/chewy/cursor.cpp
new file mode 100644
index 0000000000..18e001f05f
--- /dev/null
+++ b/engines/chewy/cursor.cpp
@@ -0,0 +1,107 @@
+/* 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 "common/system.h"
+#include "common/events.h"
+#include "graphics/cursorman.h"
+#include "graphics/palette.h"
+#include "graphics/surface.h"
+
+#include "chewy/cursor.h"
+#include "chewy/resource.h"
+
+namespace Chewy {
+
+const byte _cursorFrames[] = {
+ 4, 1, 1, 1, // walk
+ 4, 1, 1, 1, // pick up / use
+ 1, 1, 1, 1, 1,
+ 4, 1, 1, 1, // look
+ 4, 1, 1, 1, // talk
+ 4, 1, 1, 1, // open
+ 1,
+ 1, 1, 1, 1, // left, right, up, down
+ 1, // save
+ 1,
+ 5, 1, 1, 1, 1,
+ 1,
+ 1, // use (inventory)
+ 1, // look (inventory)
+ 1 // gun
+};
+
+Cursor::Cursor(ChewyEngine *vm) : _vm(vm) {
+ _curCursor = 0;
+ _curCursorFrame = 0;
+ _cursorSprites = new SpriteResource("cursor.taf");
+}
+
+Cursor::~Cursor() {
+ delete _cursorSprites;
+}
+
+void Cursor::setCursor(uint num, bool newCursor) {
+ TAFChunk *cursor = _cursorSprites->getSprite(num);
+ if (newCursor)
+ _curCursor = num;
+
+ CursorMan.replaceCursor(cursor->data, cursor->width, cursor->height, 0, 0, 0);
+
+ delete[] cursor->data;
+ delete cursor;
+}
+
+void Cursor::showCursor() {
+ CursorMan.showMouse(true);
+}
+
+void Cursor::hideCursor() {
+ CursorMan.showMouse(false);
+}
+
+void Cursor::animateCursor() {
+ if (_cursorFrames[_curCursor] > 1) {
+ _curCursorFrame++;
+
+ if (_curCursorFrame >= _cursorFrames[_curCursor])
+ _curCursorFrame = 0;
+
+ setCursor(_curCursor + _curCursorFrame, false);
+ }
+}
+
+void Cursor::nextCursor() {
+ uint maxCursors = ARRAYSIZE(_cursorFrames);
+
+ if (_cursorFrames[_curCursor] > 0)
+ _curCursor += _cursorFrames[_curCursor];
+ else
+ _curCursor++;
+
+ if (_curCursor >= maxCursors)
+ _curCursor = 0;
+
+ _curCursorFrame = 0;
+ setCursor(_curCursor);
+}
+
+} // End of namespace Chewy
diff --git a/engines/chewy/cursor.h b/engines/chewy/cursor.h
new file mode 100644
index 0000000000..1ab75d0997
--- /dev/null
+++ b/engines/chewy/cursor.h
@@ -0,0 +1,54 @@
+/* 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 CHEWY_CURSOR_H
+#define CHEWY_CURSOR_H
+
+#include "chewy/chewy.h"
+
+namespace Chewy {
+
+class SpriteResource;
+class Font;
+
+class Cursor {
+public:
+ Cursor(ChewyEngine *vm);
+ virtual ~Cursor();
+
+ void setCursor(uint num, bool newCursor = true);
+ void showCursor();
+ void hideCursor();
+ void animateCursor();
+ void nextCursor();
+
+private:
+ ChewyEngine *_vm;
+
+ uint _curCursor;
+ uint _curCursorFrame;
+ SpriteResource *_cursorSprites;
+};
+
+} // End of namespace Chewy
+
+#endif
diff --git a/engines/chewy/events.cpp b/engines/chewy/events.cpp
index cfbcb8ba1f..6675fea392 100644
--- a/engines/chewy/events.cpp
+++ b/engines/chewy/events.cpp
@@ -25,6 +25,7 @@
#include "chewy/chewy.h"
#include "chewy/console.h"
+#include "chewy/cursor.h"
#include "chewy/events.h"
#include "chewy/graphics.h"
@@ -44,7 +45,7 @@ void Events::processEvents() {
_vm->quitGame();
break;
case Common::KEYCODE_SPACE:
- _graphics->nextCursor();
+ _vm->_cursor->nextCursor();
break;
case Common::KEYCODE_d:
if (_event.kbd.flags & Common::KBD_CTRL)
@@ -54,7 +55,7 @@ void Events::processEvents() {
break;
}
} else if (_event.type == Common::EVENT_RBUTTONUP) {
- _graphics->nextCursor();
+ _vm->_cursor->nextCursor();
}
}
}
diff --git a/engines/chewy/graphics.cpp b/engines/chewy/graphics.cpp
index 0861a344ab..427d4faf9b 100644
--- a/engines/chewy/graphics.cpp
+++ b/engines/chewy/graphics.cpp
@@ -26,6 +26,7 @@
#include "graphics/palette.h"
#include "graphics/surface.h"
+#include "chewy/cursor.h"
#include "chewy/graphics.h"
#include "chewy/resource.h"
#include "chewy/text.h"
@@ -52,15 +53,11 @@ const byte _cursorFrames[] = {
};
Graphics::Graphics(ChewyEngine *vm) : _vm(vm) {
- _curCursor = 0;
- _curCursorFrame = 0;
- _cursorSprites = new SpriteResource("cursor.taf");
_font = nullptr;
}
Graphics::~Graphics() {
delete _font;
- delete _cursorSprites;
}
void Graphics::drawSprite(Common::String filename, int spriteNum, uint x, uint y) {
@@ -131,7 +128,7 @@ void Graphics::playVideo(uint num) {
byte curPalette[256 * 3];
g_system->getPaletteManager()->grabPalette(curPalette, 0, 256);
- hideCursor();
+ _vm->_cursor->hideCursor();
cfoDecoder->start();
@@ -160,52 +157,7 @@ void Graphics::playVideo(uint num) {
cfoDecoder->close();
g_system->getPaletteManager()->setPalette(curPalette, 0, 256);
- showCursor();
-}
-
-void Graphics::setCursor(uint num, bool newCursor) {
- TAFChunk *cursor = _cursorSprites->getSprite(num);
- if (newCursor)
- _curCursor = num;
-
- CursorMan.replaceCursor(cursor->data, cursor->width, cursor->height, 0, 0, 0);
-
- delete[] cursor->data;
- delete cursor;
-}
-
-void Graphics::showCursor() {
- CursorMan.showMouse(true);
-}
-
-void Graphics::hideCursor() {
- CursorMan.showMouse(false);
-}
-
-void Graphics::animateCursor() {
- if (_cursorFrames[_curCursor] > 1) {
- _curCursorFrame++;
-
- if (_curCursorFrame >= _cursorFrames[_curCursor])
- _curCursorFrame = 0;
-
- setCursor(_curCursor + _curCursorFrame, false);
- }
-}
-
-void Graphics::nextCursor() {
- uint maxCursors = ARRAYSIZE(_cursorFrames);
-
- if (_cursorFrames[_curCursor] > 0)
- _curCursor += _cursorFrames[_curCursor];
- else
- _curCursor++;
-
- if (_curCursor >= maxCursors)
- _curCursor = 0;
-
- _curCursorFrame = 0;
- setCursor(_curCursor);
+ _vm->_cursor->showCursor();
}
} // End of namespace Chewy
diff --git a/engines/chewy/graphics.h b/engines/chewy/graphics.h
index a3f6005942..a260311df5 100644
--- a/engines/chewy/graphics.h
+++ b/engines/chewy/graphics.h
@@ -41,20 +41,10 @@ public:
void loadFont(Common::String filename);
void drawText(Common::String text, uint x, uint y);
- void setCursor(uint num, bool newCursor = true);
- void showCursor();
- void hideCursor();
- void animateCursor();
- void nextCursor();
-
private:
void drawTransparent(uint16 x, uint16 y, byte *data, uint16 width, uint16 height, byte transparentColor);
ChewyEngine *_vm;
-
- uint _curCursor;
- uint _curCursorFrame;
- SpriteResource *_cursorSprites;
Font *_font;
};
diff --git a/engines/chewy/module.mk b/engines/chewy/module.mk
index 38b4265d41..e13a69abbb 100644
--- a/engines/chewy/module.mk
+++ b/engines/chewy/module.mk
@@ -2,6 +2,7 @@ MODULE := engines/chewy
MODULE_OBJS = \
chewy.o \
+ cursor.o \
console.o \
detection.o \
events.o \