STARK: Move cursor handling to a separate class
This commit is contained in:
parent
b7b8447945
commit
1c39348f58
7 changed files with 119 additions and 19 deletions
48
engines/stark/cursor.cpp
Normal file
48
engines/stark/cursor.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
/* ResidualVM - A 3D game interpreter
|
||||
*
|
||||
* ResidualVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the AUTHORS
|
||||
* 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 "engines/stark/cursor.h"
|
||||
|
||||
#include "engines/stark/gfx/driver.h"
|
||||
#include "engines/stark/gfx/texture.h"
|
||||
|
||||
namespace Stark {
|
||||
|
||||
Cursor::Cursor(Gfx::Driver *gfx) :
|
||||
_gfx(gfx) {
|
||||
// TODO: This is just a quick solution to get anything drawn, we will need load-code for the actual pointers.
|
||||
_cursorTexture = _gfx->createTextureFromString("X", 0xFF00FF00);
|
||||
}
|
||||
|
||||
Cursor::~Cursor() {
|
||||
delete _cursorTexture;
|
||||
}
|
||||
|
||||
void Cursor::setMousePosition(Common::Point pos) {
|
||||
_mousePos = pos;
|
||||
}
|
||||
|
||||
void Cursor::render() {
|
||||
_gfx->drawSurface(_cursorTexture, _mousePos);
|
||||
}
|
||||
|
||||
} // End of namespace Stark
|
61
engines/stark/cursor.h
Normal file
61
engines/stark/cursor.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
/* ResidualVM - A 3D game interpreter
|
||||
*
|
||||
* ResidualVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the AUTHORS
|
||||
* 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 STARK_CURSOR_H
|
||||
#define STARK_CURSOR_H
|
||||
|
||||
#include "common/rect.h"
|
||||
#include "common/scummsys.h"
|
||||
|
||||
namespace Stark {
|
||||
|
||||
namespace Gfx {
|
||||
class Driver;
|
||||
class Texture;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manager for the current game Cursor
|
||||
*/
|
||||
class Cursor {
|
||||
public:
|
||||
Cursor(Gfx::Driver *gfx);
|
||||
~Cursor();
|
||||
|
||||
/**
|
||||
* Render the Cursor
|
||||
*/
|
||||
void render();
|
||||
|
||||
/** Update the mouse position */
|
||||
void setMousePosition(Common::Point pos);
|
||||
|
||||
private:
|
||||
Gfx::Driver *_gfx;
|
||||
|
||||
Common::Point _mousePos;
|
||||
Gfx::Texture *_cursorTexture;
|
||||
};
|
||||
|
||||
} // End of namespace Stark
|
||||
|
||||
#endif // STARK_CURSOR_H
|
|
@ -3,6 +3,7 @@ MODULE := engines/stark
|
|||
MODULE_OBJS := \
|
||||
actor.o \
|
||||
console.o \
|
||||
cursor.o \
|
||||
detection.o \
|
||||
gfx/driver.o \
|
||||
gfx/opengls.o \
|
||||
|
|
|
@ -35,12 +35,9 @@ namespace Stark {
|
|||
|
||||
UserInterface::UserInterface(Gfx::Driver *driver) {
|
||||
_gfx = driver;
|
||||
// TODO: This is just a quick solution to get anything drawn, we will need load-code for the actual pointers.
|
||||
_cursorTexture = _gfx->createTextureFromString("X", 0xFF00FF00);
|
||||
}
|
||||
|
||||
UserInterface::~UserInterface() {
|
||||
delete _cursorTexture;
|
||||
}
|
||||
|
||||
void UserInterface::skipCurrentSpeeches() {
|
||||
|
@ -82,14 +79,7 @@ void UserInterface::scrollLocation(int32 dX, int32 dY) {
|
|||
location->setScrollPosition(scroll);
|
||||
}
|
||||
|
||||
void UserInterface::setMousePosition(Common::Point pos) {
|
||||
_mousePos = pos;
|
||||
}
|
||||
|
||||
void UserInterface::render() {
|
||||
if (_cursorTexture) {
|
||||
_gfx->drawSurface(_cursorTexture, _mousePos);
|
||||
}
|
||||
Common::String debugStr;
|
||||
|
||||
Global *global = StarkServices::instance().global;
|
||||
|
@ -99,7 +89,7 @@ void UserInterface::render() {
|
|||
|
||||
debugStr += Common::String::format("location: %02x %02x ", current->getLevel()->getIndex(), current->getLocation()->getIndex());
|
||||
debugStr += current->getLevel()->getName() + ", " + current->getLocation()->getName();
|
||||
debugStr += Common::String::format(" chapter: %d mouse(%d, %d)", chapter, _mousePos.x, _mousePos.y);
|
||||
debugStr += Common::String::format(" chapter: %d", chapter);
|
||||
|
||||
|
||||
Gfx::Texture *debugTexture = _gfx->createTextureFromString(debugStr, 0xF0FF0F00);
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#define STARK_SERVICES_USER_INTERFACE_H
|
||||
|
||||
#include "common/scummsys.h"
|
||||
#include "common/rect.h"
|
||||
|
||||
namespace Stark {
|
||||
|
||||
|
@ -47,14 +46,9 @@ public:
|
|||
/** Scroll the current location by an offset */
|
||||
void scrollLocation(int32 dX, int32 dY);
|
||||
|
||||
/** Update the mouse position */
|
||||
void setMousePosition(Common::Point pos);
|
||||
|
||||
/** Draw the mouse pointer, and any additional currently active UI */
|
||||
void render();
|
||||
private:
|
||||
Common::Point _mousePos;
|
||||
Gfx::Texture *_cursorTexture;
|
||||
Gfx::Driver *_gfx;
|
||||
};
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "engines/stark/stark.h"
|
||||
|
||||
#include "engines/stark/console.h"
|
||||
#include "engines/stark/cursor.h"
|
||||
#include "engines/stark/debug.h"
|
||||
#include "engines/stark/resources/level.h"
|
||||
#include "engines/stark/resources/location.h"
|
||||
|
@ -52,6 +53,7 @@ StarkEngine::StarkEngine(OSystem *syst, const ADGameDescription *gameDesc) :
|
|||
_gfx(nullptr),
|
||||
_scene(nullptr),
|
||||
_console(nullptr),
|
||||
_cursor(nullptr),
|
||||
_global(nullptr),
|
||||
_userInterface(nullptr),
|
||||
_archiveLoader(nullptr),
|
||||
|
@ -73,6 +75,7 @@ StarkEngine::StarkEngine(OSystem *syst, const ADGameDescription *gameDesc) :
|
|||
|
||||
StarkEngine::~StarkEngine() {
|
||||
delete _userInterface;
|
||||
delete _cursor;
|
||||
delete _dialogPlayer;
|
||||
delete _randomSource;
|
||||
delete _scene;
|
||||
|
@ -100,6 +103,7 @@ Common::Error StarkEngine::run() {
|
|||
_randomSource = new Common::RandomSource("stark");
|
||||
_scene = new Scene(_gfx);
|
||||
_dialogPlayer = new DialogPlayer();
|
||||
_cursor = new Cursor(_gfx);
|
||||
_userInterface = new UserInterface(_gfx);
|
||||
|
||||
// Setup the public services
|
||||
|
@ -150,7 +154,7 @@ void StarkEngine::mainLoop() {
|
|||
_userInterface->skipCurrentSpeeches();
|
||||
} else if (e.type == Common::EVENT_MOUSEMOVE) {
|
||||
_userInterface->scrollLocation(e.relMouse.x, e.relMouse.y);
|
||||
_userInterface->setMousePosition(e.mouse);
|
||||
_cursor->setMousePosition(e.mouse);
|
||||
}
|
||||
/*if (event.type == Common::EVENT_KEYDOWN || event.type == Common::EVENT_KEYUP) {
|
||||
handleControls(event.type, event.kbd.keycode, event.kbd.flags, event.kbd.ascii);
|
||||
|
@ -194,6 +198,7 @@ void StarkEngine::updateDisplayScene() {
|
|||
_dialogPlayer->renderText();
|
||||
|
||||
_userInterface->render();
|
||||
_cursor->render();
|
||||
|
||||
// Swap buffers
|
||||
_gfx->flipBuffer();
|
||||
|
|
|
@ -30,7 +30,6 @@ namespace Common {
|
|||
class RandomSource;
|
||||
}
|
||||
|
||||
|
||||
namespace Stark {
|
||||
|
||||
namespace Gfx {
|
||||
|
@ -43,6 +42,7 @@ enum StarkGameFeatures {
|
|||
|
||||
class ArchiveLoader;
|
||||
class Console;
|
||||
class Cursor;
|
||||
class DialogPlayer;
|
||||
class Global;
|
||||
class UserInterface;
|
||||
|
@ -83,6 +83,7 @@ private:
|
|||
|
||||
const ADGameDescription *_gameDescription;
|
||||
|
||||
Cursor *_cursor;
|
||||
Scene *_scene;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue