PRIVATE: Simplify the cursor code

This commit is contained in:
Cameron Cawley 2021-03-07 20:36:39 +00:00 committed by neuromancer
parent 89421b8187
commit 899a679d46
3 changed files with 26 additions and 59 deletions

View File

@ -292,70 +292,45 @@ static const byte MOUSECURSOR_kPhone[] = {
}; };
static const byte cursorPalette[] = { static const byte cursorPalette[] = {
0, 0, 0, // Black / Transparent 0x00, 0x00, 0x00, // Black / Transparent
0x01, 0x01, 0x01, // Gray 0x01, 0x01, 0x01, // Gray
0xff, 0xff, 0xff, // White 0xff, 0xff, 0xff, // White
0xff, 0x00, 0x00 // Red 0xff, 0x00, 0x00 // Red
}; };
static struct CursorDataTable { struct CursorTable {
const char *name; const char *name;
const byte *cursor; const void *buf;
} cursorDataTable[] = { int w;
{ "kExit", MOUSECURSOR_kExit}, int h;
{ "kInventory", MOUSECURSOR_kInventory}, int hotspotX;
{ "kTurnLeft", MOUSECURSOR_kTurnLeft}, int hotspotY;
{ "kTurnRight", MOUSECURSOR_kTurnRight},
{ "kZoomIn", MOUSECURSOR_kZoomIn},
{ "kZoomOut", MOUSECURSOR_kZoomOut},
{ "kPhone", MOUSECURSOR_kPhone},
{ "default", MOUSECURSOR_SCI},
{ 0, 0}
}; };
static struct CursorPointTable { static const CursorTable cursorTable[] = {
const char *name; { "kExit", MOUSECURSOR_kExit, 32, 32, 9, 0 },
const int coord[2]; { "kInventory", MOUSECURSOR_kInventory, 32, 32, 15, 3 },
} cursorPointTable[] = { { "kTurnLeft", MOUSECURSOR_kTurnLeft, 32, 32, 29, 16 },
{ "kExit", {9, 0} }, { "kTurnRight", MOUSECURSOR_kTurnRight, 32, 32, 1, 15 },
{ "kInventory", {15, 3} }, { "kZoomIn", MOUSECURSOR_kZoomIn, 32, 32, 10, 8 },
{ "kTurnLeft", {29, 16} }, { "kZoomOut", MOUSECURSOR_kZoomOut, 32, 32, 13, 31 },
{ "kTurnRight", {1, 15} }, { "kPhone", MOUSECURSOR_kPhone, 32, 32, 17, 19 },
{ "kZoomIn", {10, 8} }, { "default", MOUSECURSOR_SCI, 11, 16, 0, 0 },
{ "kZoomOut", {13, 31} }, { nullptr, nullptr, 0, 0, 0, 0 }
{ "kPhone", {17, 19} },
{ "default", {0, 0} },
{ 0, {0, 0} }
}; };
void PrivateEngine::initCursors() {
for (Private::CursorDataTable *cur = Private::cursorDataTable; cur->name; cur++) {
Common::String name(cur->name);
_cursorData.setVal(name, cur->cursor);
}
for (Private::CursorPointTable *cur = Private::cursorPointTable; cur->name; cur++) {
Common::String name(cur->name);
Common::Point point = Common::Point(cur->coord[0], cur->coord[1]);
_cursorPoints.setVal(name, point);
}
CursorMan.replaceCursorPalette(cursorPalette, 0, 3);
}
void PrivateEngine::changeCursor(const Common::String &cursor) { void PrivateEngine::changeCursor(const Common::String &cursor) {
assert(_cursorData.contains(cursor)); const CursorTable *entry = cursorTable;
Common::Point p = _cursorPoints.getVal(cursor); while (entry->name) {
int x, y; if (cursor == entry->name)
break;
if (cursor == "default") { entry++;
x = 11;
y = 16;
} else {
x = 32;
y = 32;
} }
if (!entry->name)
return;
CursorMan.replaceCursor(_cursorData.getVal(cursor), x, y, p.x, p.y, 0, false); CursorMan.replaceCursor(entry->buf, entry->w, entry->h, entry->hotspotX, entry->hotspotY, 0);
CursorMan.replaceCursorPalette(cursorPalette, 0, 3);
CursorMan.showMouse(true); CursorMan.showMouse(true);
} }

View File

@ -157,7 +157,6 @@ Common::Error PrivateEngine::run() {
Settings::g_setts = new Settings::SettingMaps(); Settings::g_setts = new Settings::SettingMaps();
initFuncs(); initFuncs();
initCursors();
parse(buf); parse(buf);
free(buf); free(buf);
delete file; delete file;

View File

@ -130,8 +130,6 @@ typedef Common::Array<DossierInfo> DossierArray;
// hash tables // hash tables
typedef Common::HashMap<Common::String, bool> PlayedMediaTable; typedef Common::HashMap<Common::String, bool> PlayedMediaTable;
typedef Common::HashMap<Common::String, const byte *> CursorDataMap;
typedef Common::HashMap<Common::String, Common::Point> CursorPointMap;
class PrivateEngine : public Engine { class PrivateEngine : public Engine {
@ -201,7 +199,6 @@ public:
void drawScreenFrame(); void drawScreenFrame();
void changeCursor(const Common::String &); void changeCursor(const Common::String &);
void initCursors();
// Rendering // Rendering
Graphics::ManagedSurface *_compositeSurface; Graphics::ManagedSurface *_compositeSurface;
@ -301,10 +298,6 @@ public:
// Timers // Timers
bool installTimer(uint32, Common::String *); bool installTimer(uint32, Common::String *);
void removeTimer(); void removeTimer();
// Cursors
CursorDataMap _cursorData;
CursorPointMap _cursorPoints;
}; };
extern PrivateEngine *g_private; extern PrivateEngine *g_private;