From 3fe3ad7ee35c8bdb4aef298e2cfa52b43b94d88e Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Mon, 28 Dec 2015 12:38:26 +0100 Subject: WAGE: Moved scene drawing calls to Gui class --- engines/wage/entities.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++----- engines/wage/entities.h | 8 ++++++-- engines/wage/gui.cpp | 31 +++++++++++++++++++++++++++++++ engines/wage/gui.h | 9 ++++++++- engines/wage/wage.cpp | 14 +++----------- 5 files changed, 90 insertions(+), 19 deletions(-) (limited to 'engines') diff --git a/engines/wage/entities.cpp b/engines/wage/entities.cpp index a70ac5eee8..d557f080d3 100644 --- a/engines/wage/entities.cpp +++ b/engines/wage/entities.cpp @@ -59,11 +59,36 @@ void Designed::setDesignBounds(Common::Rect *bounds) { _design->setBounds(bounds); } +Scene::Scene() { + _script = NULL; + _surface = NULL; + _design = NULL; + _textBounds = NULL; + _fontSize = 0; + _fontType = 0; + + for (int i = 0; i < 4; i++) + _blocked[i] = false; + + _soundFrequency = 0; + _soundType = 0; + _worldX = 0; + _worldY = 0; + + _visited = false; +} + Scene::Scene(String name, Common::SeekableReadStream *data) { _name = name; _classType = SCENE; _design = new Design(data); + _script = NULL; + _surface = NULL; + _textBounds = NULL; + _fontSize = 0; + _fontType = 0; + setDesignBounds(readRect(data)); _worldY = data->readSint16BE(); _worldX = data->readSint16BE(); @@ -83,20 +108,32 @@ Scene::Scene(String name, Common::SeekableReadStream *data) { _visited = false; } -void Scene::paint(Graphics::Surface *surface) { - surface->fillRect(Common::Rect(0, 0, _design->getBounds()->width(), _design->getBounds()->height()), kColorWhite); +Scene::~Scene() { + delete _surface; +} + +void Scene::paint(Graphics::Surface *surface, int x, int y) { + if (_surface == NULL) { + _surface = new Graphics::Surface; + _surface->create(_design->getBounds()->width(), _design->getBounds()->height(), Graphics::PixelFormat::createFormatCLUT8()); + } - _design->paint(surface, ((WageEngine *)g_engine)->_world->_patterns, false); + Common::Rect r(0, 0, _design->getBounds()->width(), _design->getBounds()->height()); + _surface->fillRect(r, kColorWhite); + + _design->paint(_surface, ((WageEngine *)g_engine)->_world->_patterns, false); for (Common::List::const_iterator it = _objs.begin(); it != _objs.end(); ++it) { debug(2, "paining Obj: %s", (*it)->_name.c_str()); - (*it)->_design->paint(surface, ((WageEngine *)g_engine)->_world->_patterns, false); + (*it)->_design->paint(_surface, ((WageEngine *)g_engine)->_world->_patterns, false); } for (Common::List::const_iterator it = _chrs.begin(); it != _chrs.end(); ++it) { debug(2, "paining Chr: %s", (*it)->_name.c_str()); - (*it)->_design->paint(surface, ((WageEngine *)g_engine)->_world->_patterns, false); + (*it)->_design->paint(_surface, ((WageEngine *)g_engine)->_world->_patterns, false); } + + surface->copyRectToSurface(*_surface, x, y, r); } // Source: Apple IIGS Technical Note #41, "Font Family Numbers" diff --git a/engines/wage/entities.h b/engines/wage/entities.h index 29f28d7173..0e20d2ef3a 100644 --- a/engines/wage/entities.h +++ b/engines/wage/entities.h @@ -394,16 +394,20 @@ public: Common::List _objs; Common::List _chrs; - Scene() {} + Scene(); Scene(String name, Common::SeekableReadStream *data); + ~Scene(); Common::Rect *getTextBounds() { return _textBounds == NULL ? NULL : new Common::Rect(*_textBounds); } - void paint(Graphics::Surface *screen); + void paint(Graphics::Surface *screen, int x, int y); const char *getFontName(); + +private: + Graphics::Surface *_surface; }; class Sound { diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp index 053abbf688..317fcc8a68 100644 --- a/engines/wage/gui.cpp +++ b/engines/wage/gui.cpp @@ -45,17 +45,48 @@ * */ +#include "common/system.h" #include "wage/wage.h" +#include "wage/design.h" +#include "wage/entities.h" #include "wage/gui.h" namespace Wage { +enum { + kMenuHeight = 19, + kMenuPadding = 6, + kMenuItemHeight = 19 +}; + Gui::Gui() { + _scene = NULL; + _sceneDirty = true; + _screen.create(g_system->getWidth(), g_system->getHeight(), Graphics::PixelFormat::createFormatCLUT8()); } Gui::~Gui() { } +void Gui::setScene(Scene *scene) { + if (_scene != scene) + _sceneDirty = true; + + _scene = scene; +} + +void Gui::draw() { + if (_scene != NULL && _sceneDirty) { + _scene->paint(&_screen, 0, kMenuHeight); + paintBorder(&_screen, 0, kMenuHeight, _scene->_design->getBounds()->width(), _scene->_design->getBounds()->height(), + true, true, true, false); + + _sceneDirty = false; + } + + g_system->copyRectToScreen(_screen.getPixels(), _screen.pitch, 0, 0, _screen.w, _screen.h); +} + void Gui::drawBox(Graphics::Surface *g, int x, int y, int w, int h) { Common::Rect r(x, y, x + w + 1, y + h + 1); diff --git a/engines/wage/gui.h b/engines/wage/gui.h index 0410686d3f..46899027d3 100644 --- a/engines/wage/gui.h +++ b/engines/wage/gui.h @@ -58,13 +58,20 @@ public: Gui(); ~Gui(); + void draw(); + void setScene(Scene *scene); + +private: void paintBorder(Graphics::Surface *g, int x, int y, int width, int height, bool active, bool scrollable, bool closeable, bool closeBoxPressed); -private: void drawBox(Graphics::Surface *g, int x, int y, int w, int h); void fillRect(Graphics::Surface *g, int x, int y, int w, int h); +private: + Graphics::Surface _screen; + Scene *_scene; + bool _sceneDirty; }; } // End of namespace Wage diff --git a/engines/wage/wage.cpp b/engines/wage/wage.cpp index b9ee574d52..9e30fe6c44 100644 --- a/engines/wage/wage.cpp +++ b/engines/wage/wage.cpp @@ -93,7 +93,7 @@ static byte palette[] = { }; Common::Error WageEngine::run() { - initGraphics(640, 480, true); + initGraphics(444, 333, true); g_system->getPaletteManager()->setPalette(palette, 0, 3); @@ -113,9 +113,6 @@ Common::Error WageEngine::run() { if (!_world->loadWorld(_resManager)) return Common::kNoGameDataFoundError; - Graphics::Surface screen; - screen.create(640, 480, Graphics::PixelFormat::createFormatCLUT8()); - _temporarilyHidden = true; performInitialSetup(); _temporarilyHidden = false; @@ -125,13 +122,8 @@ Common::Error WageEngine::run() { _world->_player->_currentScene = _world->_orderedScenes[1]; //_world->_globalScript->execute(_world, 1, &input, NULL, this); - Scene *scene = _world->_orderedScenes[1]; - - scene->paint(&screen); - _gui->paintBorder(&screen, 0, 0, scene->_design->getBounds()->width(), scene->_design->getBounds()->height(), - true, true, true, false); - - g_system->copyRectToScreen(screen.getPixels(), screen.pitch, 0, 0, screen.w, screen.h); + _gui->setScene(_world->_orderedScenes[1]); + _gui->draw(); while (true) { processEvents(); -- cgit v1.2.3