From 6c354bccf253118d459f92f16d8f702ae07806fb Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 22 Feb 2014 17:25:30 -0500 Subject: MADS: Implemented more logic for dialog display --- engines/mads/debugger.cpp | 49 +++++++++++++++ engines/mads/debugger.h | 45 ++++++++++++++ engines/mads/dialogs.cpp | 108 +++++++++++++++++++++++++++++++--- engines/mads/dialogs.h | 37 +++++++++--- engines/mads/events.cpp | 87 +++++++++++++++++++++++++-- engines/mads/events.h | 36 +++++++++++- engines/mads/mads.cpp | 7 ++- engines/mads/mads.h | 2 + engines/mads/module.mk | 1 + engines/mads/msurface.cpp | 39 ++++++------ engines/mads/msurface.h | 51 +++++++++------- engines/mads/nebular/game_nebular.cpp | 6 +- engines/mads/palette.cpp | 48 --------------- engines/mads/palette.h | 16 ----- 14 files changed, 403 insertions(+), 129 deletions(-) create mode 100644 engines/mads/debugger.cpp create mode 100644 engines/mads/debugger.h (limited to 'engines') diff --git a/engines/mads/debugger.cpp b/engines/mads/debugger.cpp new file mode 100644 index 0000000000..ceaeeaa5dd --- /dev/null +++ b/engines/mads/debugger.cpp @@ -0,0 +1,49 @@ +/* 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 "mads/mads.h" +#include "mads/debugger.h" + +namespace MADS { + +Debugger::Debugger(MADSEngine *vm) : GUI::Debugger(), _vm(vm) { + DCmd_Register("continue", WRAP_METHOD(Debugger, Cmd_Exit)); +} +/* +static int strToInt(const char *s) { + if (!*s) + // No string at all + return 0; + else if (toupper(s[strlen(s) - 1]) != 'H') + // Standard decimal string + return atoi(s); + + // Hexadecimal string + uint tmp = 0; + int read = sscanf(s, "%xh", &tmp); + if (read < 1) + error("strToInt failed on string \"%s\"", s); + return (int)tmp; +} +*/ + +} // End of namespace MADS diff --git a/engines/mads/debugger.h b/engines/mads/debugger.h new file mode 100644 index 0000000000..044151c0bb --- /dev/null +++ b/engines/mads/debugger.h @@ -0,0 +1,45 @@ +/* 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 MADS_DEBUGGER_H +#define MADS_DEBUGGER_H + +#include "common/scummsys.h" +#include "gui/debugger.h" + +namespace MADS { + +class MADSEngine; + +class Debugger : public GUI::Debugger { +private: + MADSEngine *_vm; +public: + Debugger(MADSEngine *vm); + virtual ~Debugger() {} + +protected: +}; + +} // End of namespace MADS + +#endif /* MADS_DEBUGGER_H */ diff --git a/engines/mads/dialogs.cpp b/engines/mads/dialogs.cpp index 4e64f08822..ebb21418b1 100644 --- a/engines/mads/dialogs.cpp +++ b/engines/mads/dialogs.cpp @@ -51,6 +51,44 @@ void Dialog::restore(MSurface *s) { _savedSurface = nullptr; } +void Dialog::draw() { + // Save the screen portion the dialog will overlap + save(_vm->_screen); + + // Draw the dialog + // Fill entire content of dialog + _vm->_screen->fillRect(Common::Rect(_position.x, _position.y, + _position.x + _width, _position.y + _height), TEXTDIALOG_BACKGROUND); + + // Draw the outer edge line + _vm->_screen->frameRect(Common::Rect(_position.x, _position.y, + _position.x + _width, _position.y + _height), TEXTDIALOG_EDGE); + + // Draw the gravelly dialog content + drawContent(Common::Rect(_position.x + 2, _position.y + 2, + _position.x + _width - 4, _position.y + _height - 4), 0, + TEXTDIALOG_CONTENT1, TEXTDIALOG_CONTENT2); +} + +void Dialog::drawContent(const Common::Rect &r, int seed, byte color1, byte color2) { + uint16 currSeed = seed ? seed : 0xB78E; + + for (int yp = 0; yp < r.height(); ++yp) { + byte *destP = _vm->_screen->getBasePtr(r.left, r.top + yp); + + for (int xp = 0; xp < r.width(); ++xp) { + uint16 seedAdjust = currSeed; + currSeed += 0x181D; + seedAdjust = (seedAdjust >> 9) | ((seedAdjust & 0x1ff) << 7); + currSeed ^= seedAdjust; + seedAdjust = (seedAdjust >> 3) | ((seedAdjust & 7) << 13); + currSeed += seedAdjust; + + *destP++ = (currSeed & 0x10) ? color1 : color2; + } + } +} + /*------------------------------------------------------------------------*/ TextDialog::TextDialog(MADSEngine *vm, const Common::String &fontName, @@ -61,7 +99,7 @@ TextDialog::TextDialog(MADSEngine *vm, const Common::String &fontName, _position = pos; _vm->_font->setFont(FONT_INTERFACE); - _vm->_font->setColors(TEXTDIALOG_FONT, TEXTDIALOG_FONT, TEXTDIALOG_FONT, TEXTDIALOG_FONT); + _vm->_font->setColors(TEXTDIALOG_BLACK, TEXTDIALOG_BLACK, TEXTDIALOG_BLACK, TEXTDIALOG_BLACK); _innerWidth = (_vm->_font->maxWidth() + 1) * maxChars; _width = _innerWidth + 10; @@ -71,16 +109,16 @@ TextDialog::TextDialog(MADSEngine *vm, const Common::String &fontName, _numLines = 0; Common::fill(&_lineXp[0], &_lineXp[TEXT_DIALOG_MAX_LINES], 0); - Common::copy(&_vm->_palette->_mainPalette[TEXTDIALOG_F8 * 3], - &_vm->_palette->_mainPalette[TEXTDIALOG_F8 * 3 + 8 * 3], + Common::copy(&_vm->_palette->_mainPalette[TEXTDIALOG_CONTENT1 * 3], + &_vm->_palette->_mainPalette[TEXTDIALOG_CONTENT1 * 3 + 8 * 3], &_savedPalette[0]); - Palette::setGradient(_vm->_palette->_mainPalette, TEXTDIALOG_F8, 2, 0x24, 0x20); - Palette::setGradient(_vm->_palette->_mainPalette, TEXTDIALOG_FA, 2, 0x27, 0x1C); + Palette::setGradient(_vm->_palette->_mainPalette, TEXTDIALOG_CONTENT1, 2, 0x24, 0x20); + Palette::setGradient(_vm->_palette->_mainPalette, TEXTDIALOG_EDGE, 2, 0x27, 0x1C); Palette::setGradient(_vm->_palette->_mainPalette, TEXTDIALOG_FC, 2, 0x24, 0x20); Palette::setGradient(_vm->_palette->_mainPalette, TEXTDIALOG_FE, 1, 0x37, 0x37); - _vm->_palette->setPalette(_vm->_palette->_mainPalette + (TEXTDIALOG_F8 * 3), - TEXTDIALOG_F8, 8); + _vm->_palette->setPalette(_vm->_palette->_mainPalette + (TEXTDIALOG_CONTENT1 * 3), + TEXTDIALOG_CONTENT1, 8); } TextDialog::~TextDialog() { @@ -179,6 +217,58 @@ void TextDialog::appendLine(const Common::String &line) { _lines[_numLines] += line; } +void TextDialog::draw() { + if (!_lineWidth) + --_numLines; + + // Figure out the size and position for the dialog + _height = (_vm->_font->getHeight() + 1) * (_numLines + 1) + 10; + if (_position.x == -1) + _position.x = 160 - (_width / 2); + if (_position.y == -1) + _position.y = 100 - (_height / 2); + + if ((_position.x + _width) > _vm->_screen->getWidth()) + _position.x = _vm->_screen->getWidth() - (_position.x + _width); + if ((_position.y + _height) > _vm->_screen->getHeight()) + _position.y = _vm->_screen->getHeight() - (_position.y + _height); + +// int askYp = (_vm->_font->getHeight() + 1) * _vm->_font->getHeight() + 3; + + // Draw the underlying dialog + Dialog::draw(); + + // Draw the text lines + int lineYp = _position.y + 5; + for (int lineNum = 0; lineNum < _numLines; ++lineNum) { + if (_lineXp[lineNum] == -1) { + // Draw a line across the entire dialog + _vm->_screen->setColor(TEXTDIALOG_BLACK); + _vm->_screen->hLine(_position.x + 2, + lineYp + (_vm->_font->getHeight() + 1) / 2, + _position.x + _width - 4); + } else { + // Draw a text line + int xp = (_lineXp[lineNum] & 0x7F) + 5; + int yp = lineYp; + if (_lineXp[lineNum] & 0x40) + ++yp; + + _vm->_font->writeString(_vm->_screen, _lines[lineNum], + Common::Point(xp, yp), 1); + + if (_lineXp[lineNum] & 0x80) { + // Draw an underline under the text + int lineWidth = _vm->_font->getWidth(_lines[lineNum]); + _vm->_screen->setColor(TEXTDIALOG_BLACK); + _vm->_screen->hLine(xp, yp + _vm->_font->getHeight(), xp + lineWidth); + } + } + + lineYp += _vm->_font->getHeight() + 1; + } +} + /*------------------------------------------------------------------------*/ MessageDialog::MessageDialog(MADSEngine *vm, int maxChars, ...): @@ -193,8 +283,10 @@ MessageDialog::MessageDialog(MADSEngine *vm, int maxChars, ...): line = va_arg(va, const char *); } va_end(va); +} + +void MessageDialog::show() { - // TODO } } // End of namespace MADS diff --git a/engines/mads/dialogs.h b/engines/mads/dialogs.h index 03710b6b82..407f6d38bf 100644 --- a/engines/mads/dialogs.h +++ b/engines/mads/dialogs.h @@ -48,6 +48,16 @@ protected: * @param s Screen surface to restore to. */ void restore(MSurface *s); + + /** + * Draws the content of a dialog with a gravelly alternating color. + */ + void drawContent(const Common::Rect &r, int seed, byte color1, byte color2); +protected: + /** + * Draw the dialog + */ + virtual void draw(); public: /** * Constructor @@ -61,14 +71,14 @@ public: }; enum { - TEXTDIALOG_F8 = 0XF8, - TEXTDIALOG_F9 = 0XF8, - TEXTDIALOG_FA = 0XF8, - TEXTDIALOG_FB = 0XF8, - TEXTDIALOG_FC = 0XF8, - TEXTDIALOG_FD = 0XF8, - TEXTDIALOG_FE = 0XF8, - TEXTDIALOG_FONT = 0 + TEXTDIALOG_CONTENT1 = 0XF8, + TEXTDIALOG_CONTENT2 = 0XF9, + TEXTDIALOG_EDGE = 0XFA, + TEXTDIALOG_BACKGROUND = 0XFB, + TEXTDIALOG_FC = 0XFC, + TEXTDIALOG_FD = 0XFD, + TEXTDIALOG_FE = 0XFE, + TEXTDIALOG_BLACK = 0 }; #define TEXT_DIALOG_MAX_LINES 20 @@ -96,6 +106,8 @@ protected: int _currentX; int _numLines; int _lineSize; + int _askXp; + int _askLineNum; Common::String _lines[TEXT_DIALOG_MAX_LINES]; int _lineXp[TEXT_DIALOG_MAX_LINES]; byte _savedPalette[8 * 3]; @@ -125,11 +137,20 @@ public: */ ~TextDialog(); + /** + * Draw the dialog + */ + virtual void draw(); }; class MessageDialog: protected TextDialog { public: MessageDialog(MADSEngine *vm, int lines, ...); + + /** + * Show the dialog, and wait until a key or mouse press. + */ + void show(); }; } // End of namespace MADS diff --git a/engines/mads/events.cpp b/engines/mads/events.cpp index bb980af7ff..3c50063c2e 100644 --- a/engines/mads/events.cpp +++ b/engines/mads/events.cpp @@ -21,16 +21,22 @@ */ #include "common/scummsys.h" +#include "graphics/cursorman.h" #include "common/events.h" #include "engines/util.h" #include "mads/mads.h" #include "mads/events.h" +#define GAME_FRAME_RATE 50 +#define GAME_FRAME_TIME (1000 / GAME_FRAME_RATE) + namespace MADS { EventsManager::EventsManager(MADSEngine *vm) { _vm = vm; _cursorSprites = nullptr; + _gameCounter = 0; + _priorFrameTime = 0; } EventsManager::~EventsManager() { @@ -38,7 +44,7 @@ EventsManager::~EventsManager() { } void EventsManager::loadCursors(const Common::String &spritesName) { - _cursorSprites = new SpriteAsset(_vm, "*CURSOR.SS", 0x4000); + _cursorSprites = new SpriteAsset(_vm, spritesName, 0x4000); } void EventsManager::setCursor(CursorType cursorId) { @@ -52,15 +58,86 @@ void EventsManager::setCursor2(CursorType cursorId) { changeCursor(); } +void EventsManager::showCursor() { + CursorMan.showMouse(true); +} + +void EventsManager::hideCursor() { + CursorMan.showMouse(false); +} + void EventsManager::changeCursor() { } -void EventsManager::handleEvents() { - Common::Event e; - while (!_vm->shouldQuit()) { - g_system->getEventManager()->pollEvent(e); +void EventsManager::pollEvents() { + checkForNextFrameCounter(); + _mouseClicked = false; + _mouseReleased = false; + _keyPressed = false; + + Common::Event event; + while (g_system->getEventManager()->pollEvent(event)) { + // Handle keypress + switch (event.type) { + case Common::EVENT_QUIT: + case Common::EVENT_RTL: + case Common::EVENT_KEYUP: + return; + + case Common::EVENT_KEYDOWN: + // Check for debugger + if (event.kbd.keycode == Common::KEYCODE_d && (event.kbd.flags & Common::KBD_CTRL)) { + // Attach to the debugger + _vm->_debugger->attach(); + _vm->_debugger->onFrame(); + } else { + _keyPressed = true; + } + return; + case Common::EVENT_LBUTTONDOWN: + case Common::EVENT_RBUTTONDOWN: + _mouseClicked = true; + return; + case Common::EVENT_LBUTTONUP: + case Common::EVENT_RBUTTONUP: + _mouseReleased = true; + return; + case Common::EVENT_MOUSEMOVE: + _mousePos = event.mouse; + break; + default: + break; + } + } +} + +void EventsManager::checkForNextFrameCounter() { + // Check for next game frame + uint32 milli = g_system->getMillis(); + if ((milli - _priorFrameTime) >= GAME_FRAME_TIME) { + ++_gameCounter; + _priorFrameTime = milli; + + // Give time to the debugger + _vm->_debugger->onFrame(); + + // Display the frame + _vm->_screen->updateScreen(); + + // Signal the ScummVM debugger + _vm->_debugger->onFrame(); + } +} + +void EventsManager::delay(int cycles) { + uint32 totalMilli = cycles * 1000 / GAME_FRAME_RATE; + uint32 delayEnd = g_system->getMillis() + totalMilli; + + while (!_vm->shouldQuit() && g_system->getMillis() < delayEnd) { g_system->delayMillis(10); + + pollEvents(); } } diff --git a/engines/mads/events.h b/engines/mads/events.h index c5cc5bf352..fefc64d630 100644 --- a/engines/mads/events.h +++ b/engines/mads/events.h @@ -39,13 +39,24 @@ private: MADSEngine *_vm; CursorType _cursorId; CursorType _newCursorId; + uint32 _gameCounter; + uint32 _priorFrameTime; + Common::Point _mousePos; /** * Updates the cursor image when the current cursor changes */ void changeCursor(); + + /** + * Checks for whether the next game frame number has been reached. + */ + void checkForNextFrameCounter(); public: SpriteAsset *_cursorSprites; + bool _mouseClicked; + bool _mouseReleased; + bool _keyPressed; public: /** * Constructor @@ -72,7 +83,30 @@ public: */ void setCursor2(CursorType cursorId); - void handleEvents(); + /** + * Show the mouse cursor + */ + void showCursor(); + + /** + * Hide the mouse cursor + */ + void hideCursor(); + + /** + * Poll any pending events + */ + void pollEvents(); + + /** + * Return the current mouse position + */ + Common::Point mousePos() const { return _mousePos; } + + /** + * Delay for a given number of frames + */ + void delay(int amount); }; } // End of namespace MADS diff --git a/engines/mads/mads.cpp b/engines/mads/mads.cpp index aa2bd55dd8..3a121d082b 100644 --- a/engines/mads/mads.cpp +++ b/engines/mads/mads.cpp @@ -42,6 +42,7 @@ MADSEngine::MADSEngine(OSystem *syst, const MADSGameDescription *gameDesc) : _invObjectStill = false; _textWindowStill = false; + _debugger = nullptr; _events = nullptr; _font = nullptr; _game = nullptr; @@ -53,6 +54,7 @@ MADSEngine::MADSEngine(OSystem *syst, const MADSGameDescription *gameDesc) : } MADSEngine::~MADSEngine() { + delete _debugger; delete _events; delete _font; delete _game; @@ -74,10 +76,11 @@ void MADSEngine::initialise() { MSprite::setVm(this); ResourcesManager::init(this); + _debugger = new Debugger(this); _events = new EventsManager(this); _palette = new Palette(this); _font = new Font(this); - _screen = MSurface::init(true); + _screen = MSurface::init(g_system->getWidth(), g_system->getHeight()); _sound = new SoundManager(this, _mixer); _userInterface = UserInterface::init(this); _game = Game::init(this); @@ -94,7 +97,7 @@ Common::Error MADSEngine::run() { _game->run(); // Dummy loop to keep application active - _events->handleEvents(); + _events->delay(9999); return Common::kNoError; } diff --git a/engines/mads/mads.h b/engines/mads/mads.h index b7598eb03d..5166b7b2b1 100644 --- a/engines/mads/mads.h +++ b/engines/mads/mads.h @@ -30,6 +30,7 @@ #include "common/util.h" #include "engines/engine.h" #include "graphics/surface.h" +#include "mads/debugger.h" #include "mads/events.h" #include "mads/font.h" #include "mads/game.h" @@ -86,6 +87,7 @@ protected: virtual Common::Error run(); virtual bool hasFeature(EngineFeature f) const; public: + Debugger *_debugger; EventsManager *_events; Font *_font; Game *_game; diff --git a/engines/mads/module.mk b/engines/mads/module.mk index ec85355abb..0b5f4c7b48 100644 --- a/engines/mads/module.mk +++ b/engines/mads/module.mk @@ -6,6 +6,7 @@ MODULE_OBJS := \ nebular/sound_nebular.o \ assets.o \ compression.o \ + debugger.o \ detection.o \ dialogs.o \ events.o \ diff --git a/engines/mads/msurface.cpp b/engines/mads/msurface.cpp index b4ee129545..0846470e60 100644 --- a/engines/mads/msurface.cpp +++ b/engines/mads/msurface.cpp @@ -32,11 +32,11 @@ namespace MADS { MADSEngine *MSurface::_vm = nullptr; -MSurface *MSurface::init(bool isScreen) { +MSurface *MSurface::init() { if (_vm->getGameID() == GType_RexNebular) { - return new MSurfaceNebular(isScreen); + return new MSurfaceNebular(); } else { - return new MSurfaceMADS(isScreen); + return new MSurfaceMADS(); } } @@ -48,16 +48,13 @@ MSurface *MSurface::init(int width, int height) { } } -MSurface::MSurface(bool isScreen) { +MSurface::MSurface() { pixels = nullptr; - setSize(g_system->getWidth(), g_system->getHeight()); - _isScreen = isScreen; } MSurface::MSurface(int width, int height) { pixels = nullptr; setSize(width, height); - _isScreen = false; } MSurface::~MSurface() { @@ -120,17 +117,24 @@ void MSurface::hLineXor(int x1, int x2, int y) { } -void MSurface::line(int x1, int y1, int x2, int y2, byte color) { - Graphics::Surface::drawLine(x1, y1, x2, y2, color); +void MSurface::line(const Common::Point &startPos, const Common::Point &endPos, byte color) { + Graphics::Surface::drawLine(startPos.x, startPos.y, endPos.x, endPos.y, color); } +void MSurface::frameRect(const Common::Rect &r) { + Graphics::Surface::frameRect(r, _color); +} -void MSurface::frameRect(int x1, int y1, int x2, int y2) { - Graphics::Surface::frameRect(Common::Rect(x1, y1, x2, y2), _color); +void MSurface::frameRect(const Common::Rect &r, byte color) { + Graphics::Surface::frameRect(r, color); } -void MSurface::fillRect(int x1, int y1, int x2, int y2) { - Graphics::Surface::fillRect(Common::Rect(x1, y1, x2, y2), _color); +void MSurface::fillRect(const Common::Rect &r) { + Graphics::Surface::fillRect(r, _color); +} + +void MSurface::fillRect(const Common::Rect &r, byte color) { + Graphics::Surface::fillRect(r, color); } int MSurface::scaleValue(int value, int scale, int err) { @@ -282,12 +286,9 @@ void MSurface::empty() { Common::fill(getBasePtr(0, 0), getBasePtr(0, h), _vm->_palette->BLACK); } -void MSurface::frameRect(const Common::Rect &r, uint8 color) { - Graphics::Surface::frameRect(r, color); -} - -void MSurface::fillRect(const Common::Rect &r, uint8 color) { - Graphics::Surface::fillRect(r, color); +void MSurface::updateScreen() { + g_system->copyRectToScreen((const byte *)pixels, pitch, 0, 0, w, h); + g_system->updateScreen(); } void MSurface::copyFrom(MSurface *src, const Common::Rect &srcBounds, diff --git a/engines/mads/msurface.h b/engines/mads/msurface.h index 940c5b5704..2e4ca7e728 100644 --- a/engines/mads/msurface.h +++ b/engines/mads/msurface.h @@ -59,10 +59,9 @@ public: static void setVm(MADSEngine *vm) { _vm = vm; } /** - * Create a new surface the same size as the screen. - * @param isScreen Set to true for the screen surface + * Create a new surface. */ - static MSurface *init(bool isScreen = false); + static MSurface *init(); /** * Create a surface @@ -70,12 +69,11 @@ public: static MSurface *init(int width, int height); private: byte _color; - bool _isScreen; protected: /** * Basic constructor */ - MSurface(bool isScreen = false); + MSurface(); /** * Constructor for a surface with fixed dimensions @@ -129,28 +127,37 @@ public: /** * Draws an arbitrary line on the screen using a specified color + * @param startPos Starting position + * @param endPos Ending position + * @param color Color to use */ - void line(int x1, int y1, int x2, int y2, byte color); + void line(const Common::Point &startPos, const Common::Point &endPos, byte color); /** * Draws a rectangular frame using the currently set color + * @param r Bounds for rectangle */ - void frameRect(int x1, int y1, int x2, int y2); + void frameRect(const Common::Rect &r); /** - * Draws a rectangular frame using a specified color + * Draws a rectangular frame using the currently set color + * @param r Bounds for rectangle + * @param color Color to use */ - void frameRect(const Common::Rect &r, uint8 color); + void frameRect(const Common::Rect &r, byte color); /** * Draws a filled in box using the currently set color + * @param r Bounds for rectangle */ - void fillRect(int x1, int y1, int x2, int y2); + void fillRect(const Common::Rect &r); /** - * Draws a filled in box using a specified color + * Draws a filled in box using the currently set color + * @param r Bounds for rectangle + * @param color Color to use */ - void fillRect(const Common::Rect &r, uint8 color); + void fillRect(const Common::Rect &r, byte color); /** * Draws a sprite @@ -170,6 +177,13 @@ public: */ int getHeight() const { return h; } + /** + * Returns the size of the surface as a Rect + */ + Common::Rect getBounds() const { + return Common::Rect(0, 0, w, h); + } + /** * Returns a pointer to the surface data */ @@ -186,14 +200,9 @@ public: void empty(); /** - * Updates the surface. If it's the screen surface, copies it to the physical screen. + * Updates the screen with the contents of the surface */ - void update() { - if (_isScreen) { - g_system->copyRectToScreen((const byte *)pixels, pitch, 0, 0, w, h); - g_system->updateScreen(); - } - } + void updateScreen(); /** * Copys a sub-section of another surface into the current one. @@ -262,7 +271,7 @@ public: class MSurfaceMADS: public MSurface { friend class MSurface; protected: - MSurfaceMADS(bool isScreen = false): MSurface(isScreen) {} + MSurfaceMADS(): MSurface() {} MSurfaceMADS(int width, int height): MSurface(width, height) {} public: virtual void loadCodes(Common::SeekableReadStream *source); @@ -274,7 +283,7 @@ public: class MSurfaceNebular: public MSurfaceMADS { friend class MSurface; protected: - MSurfaceNebular(bool isScreen = false): MSurfaceMADS(isScreen) {} + MSurfaceNebular(): MSurfaceMADS() {} MSurfaceNebular(int width, int height): MSurfaceMADS(width, height) {} private: void loadBackgroundStream(Common::SeekableReadStream *source, RGBList **palData); diff --git a/engines/mads/nebular/game_nebular.cpp b/engines/mads/nebular/game_nebular.cpp index 10c210c6eb..dc2b1450ec 100644 --- a/engines/mads/nebular/game_nebular.cpp +++ b/engines/mads/nebular/game_nebular.cpp @@ -41,7 +41,11 @@ bool GameNebular::checkCopyProtection() { if (!ConfMan.getBool("copy_protection")) return true; - CopyProtectionDialog::show(_vm); + MessageDialog *dlg = new MessageDialog(_vm, 40, "Line 1", "Line 2", nullptr); + dlg->show(); + delete dlg; + + //CopyProtectionDialog::show(_vm); return false; } diff --git a/engines/mads/palette.cpp b/engines/mads/palette.cpp index 82ffa4e43a..8ec43b90b9 100644 --- a/engines/mads/palette.cpp +++ b/engines/mads/palette.cpp @@ -118,27 +118,6 @@ void Palette::reset() { WHITE = palIndexFromRgb(255, 255, 255, palData); } -void Palette::fadeIn(int numSteps, uint delayAmount, RGBList *destPalette) { - fadeIn(numSteps, delayAmount, destPalette->data(), destPalette->size()); -} - -void Palette::fadeIn(int numSteps, uint delayAmount, byte *destPalette, int numColors) { - if (_fading_in_progress) - return; - - _fading_in_progress = true; - byte blackPalette[PALETTE_SIZE]; - Common::fill(&blackPalette[0], &blackPalette[PALETTE_SIZE], 0); - - // Initially set the black palette - _vm->_palette->setPalette(blackPalette, 0, numColors); - - // Handle the actual fading - fadeRange(blackPalette, destPalette, 0, numColors - 1, numSteps, delayAmount); - - _fading_in_progress = false; -} - void Palette::resetColorCounts() { Common::fill(&_usageCount[0], &_usageCount[PALETTE_COUNT], 0); } @@ -211,33 +190,6 @@ void Palette::deleteAllRanges() { _usageCount[colIndex] = 0; } -void Palette::fadeRange(byte *srcPal, byte *destPal, int startIndex, int endIndex, - int numSteps, uint delayAmount) { - byte tempPal[256 * 3]; - - // perform the fade - for(int stepCtr = 1; stepCtr <= numSteps; ++stepCtr) { - // Delay the specified amount - uint32 startTime = g_system->getMillis(); - while ((g_system->getMillis() - startTime) < delayAmount) { - _vm->_events->handleEvents(); - g_system->delayMillis(10); - } - - for (int i = startIndex; i <= endIndex; ++i) { - // Handle the intermediate rgb values for fading - tempPal[i * 3] = (byte) (srcPal[i * 3] + (destPal[i * 3] - srcPal[i * 3]) * stepCtr / numSteps); - tempPal[i * 3 + 1] = (byte) (srcPal[i * 3 + 1] + (destPal[i * 3 + 1] - srcPal[i * 3 + 1]) * stepCtr / numSteps); - tempPal[i * 3 + 2] = (byte) (srcPal[i * 3 + 2] + (destPal[i * 3 + 2] - srcPal[i * 3 + 2]) * stepCtr / numSteps); - } - - _vm->_palette->setPalette(&tempPal[startIndex * 3], startIndex, endIndex - startIndex + 1); - } - - // Make sure the end palette exactly matches what is wanted - _vm->_palette->setPalette(&destPal[startIndex * 3], startIndex, endIndex - startIndex + 1); -} - void Palette::setGradient(byte *palette, int start, int count, int rgbValue1, int rgbValue2) { int rgbCtr = 0; int rgbCurrent = rgbValue2; diff --git a/engines/mads/palette.h b/engines/mads/palette.h index 53620d8fff..9a4e4518f7 100644 --- a/engines/mads/palette.h +++ b/engines/mads/palette.h @@ -77,12 +77,6 @@ public: class Palette { private: - /** - * Support method used by the fading code - */ - void fadeRange(byte *srcPal, byte *destPal, int startIndex, int endIndex, - int numSteps, uint delayAmount); - /** * Initialises a stanadrd range of colours for the given palette */ @@ -127,16 +121,6 @@ public: */ uint8 palIndexFromRgb(byte r, byte g, byte b, byte *paletteData = nullptr); - /** - * Performs a fade in - */ - void fadeIn(int numSteps, uint delayAmount, byte *destPalette, int numColors); - - /** - * Performs a fade in - */ - void fadeIn(int numSteps, uint delayAmount, RGBList *destPalette); - // Methods used for reference counting color usage /** * Resets the usage counts for the palette -- cgit v1.2.3