diff options
author | Paul Gilbert | 2017-11-29 19:43:06 -0500 |
---|---|---|
committer | Paul Gilbert | 2017-11-29 19:43:06 -0500 |
commit | 0a4d3a15c47118a34a47befc9bce19b6ed53fd8d (patch) | |
tree | 88bd5fcdf8c55bc81a1f6088fe4f5667ad572544 /engines/xeen | |
parent | 322a5341cf0f6ca50faa67e6b345f56e83a28489 (diff) | |
download | scummvm-rg350-0a4d3a15c47118a34a47befc9bce19b6ed53fd8d.tar.gz scummvm-rg350-0a4d3a15c47118a34a47befc9bce19b6ed53fd8d.tar.bz2 scummvm-rg350-0a4d3a15c47118a34a47befc9bce19b6ed53fd8d.zip |
XEEN: Split Window class into it's own file
Diffstat (limited to 'engines/xeen')
-rw-r--r-- | engines/xeen/module.mk | 1 | ||||
-rw-r--r-- | engines/xeen/screen.cpp | 179 | ||||
-rw-r--r-- | engines/xeen/screen.h | 75 | ||||
-rw-r--r-- | engines/xeen/window.cpp | 204 | ||||
-rw-r--r-- | engines/xeen/window.h | 101 |
5 files changed, 312 insertions, 248 deletions
diff --git a/engines/xeen/module.mk b/engines/xeen/module.mk index 553169aef0..a0e76a3045 100644 --- a/engines/xeen/module.mk +++ b/engines/xeen/module.mk @@ -44,6 +44,7 @@ MODULE_OBJS := \ spells.o \ sprites.o \ town.o \ + window.o \ xeen.o \ xsurface.o diff --git a/engines/xeen/screen.cpp b/engines/xeen/screen.cpp index 85c4df5590..bcf7f0d722 100644 --- a/engines/xeen/screen.cpp +++ b/engines/xeen/screen.cpp @@ -25,188 +25,11 @@ #include "graphics/surface.h" #include "xeen/screen.h" #include "xeen/resources.h" +#include "xeen/window.h" #include "xeen/xeen.h" namespace Xeen { -XeenEngine *Window::_vm; - -void Window::init(XeenEngine *vm) { - _vm = vm; -} - -Window::Window() : XSurface(), _enabled(false), - _a(0), _border(0), _xLo(0), _xHi(0), _ycL(0), _ycH(0) { -} - -Window::Window(const Window &src) : XSurface(), _enabled(src._enabled), - _a(src._a), _border(src._border), _xLo(src._xLo), _ycL(src._ycL), - _xHi(src._xHi), _ycH(src._ycH) { - - setBounds(src._bounds); - create(*_vm->_screen, Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)); -} - -Window::Window(const Common::Rect &bounds, int a, int border, - int xLo, int ycL, int xHi, int ycH): XSurface(), - _enabled(false), _a(a), _border(border), - _xLo(xLo), _ycL(ycL), _xHi(xHi), _ycH(ycH) { - setBounds(bounds); - create(*_vm->_screen, Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)); -} - -void Window::setBounds(const Common::Rect &r) { - _bounds = r; - _innerBounds = r; - _innerBounds.grow(-_border); -} - -void Window::open() { - if (!_enabled) { - _enabled = true; - _vm->_screen->_windowStack.push_back(this); - open2(); - } - - if (_vm->_mode == MODE_9) { - warning("TODO: copyFileToMemory"); - } -} - -void Window::open2() { - Screen &screen = *_vm->_screen; - - // Save a copy of the area under the window - _savedArea.create(_bounds.width(), _bounds.height()); - _savedArea.copyRectToSurface(screen, 0, 0, _bounds); - - // Mark the area as dirty and fill it with a default background - addDirtyRect(_bounds); - frame(); - fill(); - - screen._writePos.x = _bounds.right - 8; - screen.writeSymbol(19); - - screen._writePos.x = _innerBounds.left; - screen._writePos.y = _innerBounds.top; - screen._fontJustify = JUSTIFY_NONE; - screen._fontReduced = false; -} - -void Window::frame() { - Screen &screen = *_vm->_screen; - int xCount = (_bounds.width() - 9) / FONT_WIDTH; - int yCount = (_bounds.height() - 9) / FONT_HEIGHT; - - // Write the top line - screen._writePos = Common::Point(_bounds.left, _bounds.top); - screen.writeSymbol(0); - - if (xCount > 0) { - int symbolId = 1; - for (int i = 0; i < xCount; ++i) { - screen.writeSymbol(symbolId); - if (++symbolId == 5) - symbolId = 1; - } - } - - screen._writePos.x = _bounds.right - FONT_WIDTH; - screen.writeSymbol(5); - - // Write the vertical edges - if (yCount > 0) { - int symbolId = 6; - for (int i = 0; i < yCount; ++i) { - screen._writePos.y += 8; - - screen._writePos.x = _bounds.left; - screen.writeSymbol(symbolId); - - screen._writePos.x = _bounds.right - FONT_WIDTH; - screen.writeSymbol(symbolId + 4); - - if (++symbolId == 10) - symbolId = 6; - } - } - - // Write the bottom line - screen._writePos = Common::Point(_bounds.left, _bounds.bottom - FONT_HEIGHT); - screen.writeSymbol(14); - - if (xCount > 0) { - int symbolId = 15; - for (int i = 0; i < xCount; ++i) { - screen.writeSymbol(symbolId); - if (++symbolId == 19) - symbolId = 15; - } - } - - screen._writePos.x = _bounds.right - FONT_WIDTH; - screen.writeSymbol(19); -} - -void Window::close() { - Screen &screen = *_vm->_screen; - - if (_enabled) { - // Update the window - update(); - - // Restore the saved original content - screen.copyRectToSurface(_savedArea, _bounds.left, _bounds.top, - Common::Rect(0, 0, _bounds.width(), _bounds.height())); - addDirtyRect(_bounds); - - // Remove the window from the stack and flag it as now disabled - for (uint i = 0; i < _vm->_screen->_windowStack.size(); ++i) { - if (_vm->_screen->_windowStack[i] == this) - _vm->_screen->_windowStack.remove_at(i); - } - - _enabled = false; - } - - if (_vm->_mode == MODE_9) { - warning("TODO: copyFileToMemory"); - } -} - -void Window::update() { - // Since all window drawing is done on the screen surface anyway, - // there's nothing that needs to be updated here -} - -void Window::addDirtyRect(const Common::Rect &r) { - _vm->_screen->addDirtyRect(r); -} - -void Window::fill() { - fillRect(_innerBounds, _vm->_screen->_bgColor); -} - -const char *Window::writeString(const Common::String &s) { - return _vm->_screen->writeString(s, _innerBounds); -} - -void Window::drawList(DrawStruct *items, int count) { - for (int i = 0; i < count; ++i, ++items) { - if (items->_frame == -1 || items->_scale == -1 || items->_sprites == nullptr) - continue; - - Common::Point pt(items->_x, items->_y); - pt.x += _innerBounds.left; - pt.y += _innerBounds.top; - - items->_sprites->draw(*this, items->_frame, pt, items->_flags, items->_scale); - } -} - -/*------------------------------------------------------------------------*/ - Screen::Screen(XeenEngine *vm) : _vm(vm) { Window::init(vm); _fadeIn = false; diff --git a/engines/xeen/screen.h b/engines/xeen/screen.h index 338a231ce6..032c2654dc 100644 --- a/engines/xeen/screen.h +++ b/engines/xeen/screen.h @@ -23,14 +23,14 @@ #ifndef XEEN_SCREEN_H #define XEEN_SCREEN_H -#include "common/scummsys.h" -#include "common/system.h" -#include "common/array.h" -#include "common/keyboard.h" +//#include "common/scummsys.h" +//#include "common/system.h" +// #include "common/array.h" +//#include "common/keyboard.h" #include "common/rect.h" #include "xeen/font.h" #include "xeen/sprites.h" -#include "xeen/xsurface.h" +#include "xeen/window.h" namespace Xeen { @@ -41,71 +41,6 @@ namespace Xeen { #define GAME_WINDOW 28 class XeenEngine; -class Screen; - -struct DrawStruct { - SpriteResource *_sprites; - int _frame; - int _x; - int _y; - int _scale; - int _flags; - - DrawStruct(int frame, int x, int y, int scale = 0, int flags = 0) : - _sprites(nullptr), _frame(frame), _x(x), _y(y), _scale(scale), _flags(flags) {} - DrawStruct(): _sprites(nullptr), _frame(0), _x(0), _y(0), _scale(0), _flags(0) {} -}; - -class Window: public XSurface { -private: - static XeenEngine *_vm; - Common::Rect _bounds; - Common::Rect _innerBounds; - XSurface _savedArea; - int _a; - int _border; - int _xLo, _xHi; - int _ycL, _ycH; - - void open2(); -public: - bool _enabled; -public: - static void init(XeenEngine *vm); -public: - Window(); - Window(const Window &src); - Window(const Common::Rect &bounds, int a, int border, - int xLo, int ycL, int xHi, int ycH); - - virtual void addDirtyRect(const Common::Rect &r); - - void setBounds(const Common::Rect &r); - - const Common::Rect &getBounds() { return _bounds; } - - void open(); - - void close(); - - /** - * Update the window - */ - void update(); - - void frame(); - - /** - * Fill the content area of a window with the current background color - */ - void fill(); - - const char *writeString(const Common::String &s); - - void drawList(DrawStruct *items, int count); - - int getString(Common::String &line, uint maxLen, int maxWidth); -}; class Screen: public FontSurface { private: diff --git a/engines/xeen/window.cpp b/engines/xeen/window.cpp new file mode 100644 index 0000000000..3bb929fc88 --- /dev/null +++ b/engines/xeen/window.cpp @@ -0,0 +1,204 @@ +/* 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 "xeen/window.h" +#include "xeen/xeen.h" + +namespace Xeen { + +XeenEngine *Window::_vm; + +void Window::init(XeenEngine *vm) { + _vm = vm; +} + +Window::Window() : XSurface(), _enabled(false), + _a(0), _border(0), _xLo(0), _xHi(0), _ycL(0), _ycH(0) { +} + +Window::Window(const Window &src) : XSurface(), _enabled(src._enabled), + _a(src._a), _border(src._border), _xLo(src._xLo), _ycL(src._ycL), + _xHi(src._xHi), _ycH(src._ycH) { + + setBounds(src._bounds); + create(*_vm->_screen, Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)); +} + +Window::Window(const Common::Rect &bounds, int a, int border, + int xLo, int ycL, int xHi, int ycH): XSurface(), + _enabled(false), _a(a), _border(border), + _xLo(xLo), _ycL(ycL), _xHi(xHi), _ycH(ycH) { + setBounds(bounds); + create(*_vm->_screen, Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)); +} + +void Window::setBounds(const Common::Rect &r) { + _bounds = r; + _innerBounds = r; + _innerBounds.grow(-_border); +} + +void Window::open() { + if (!_enabled) { + _enabled = true; + _vm->_screen->_windowStack.push_back(this); + open2(); + } + + if (_vm->_mode == MODE_9) { + warning("TODO: copyFileToMemory"); + } +} + +void Window::open2() { + Screen &screen = *_vm->_screen; + + // Save a copy of the area under the window + _savedArea.create(_bounds.width(), _bounds.height()); + _savedArea.copyRectToSurface(screen, 0, 0, _bounds); + + // Mark the area as dirty and fill it with a default background + addDirtyRect(_bounds); + frame(); + fill(); + + screen._writePos.x = _bounds.right - 8; + screen.writeSymbol(19); + + screen._writePos.x = _innerBounds.left; + screen._writePos.y = _innerBounds.top; + screen._fontJustify = JUSTIFY_NONE; + screen._fontReduced = false; +} + +void Window::frame() { + Screen &screen = *_vm->_screen; + int xCount = (_bounds.width() - 9) / FONT_WIDTH; + int yCount = (_bounds.height() - 9) / FONT_HEIGHT; + + // Write the top line + screen._writePos = Common::Point(_bounds.left, _bounds.top); + screen.writeSymbol(0); + + if (xCount > 0) { + int symbolId = 1; + for (int i = 0; i < xCount; ++i) { + screen.writeSymbol(symbolId); + if (++symbolId == 5) + symbolId = 1; + } + } + + screen._writePos.x = _bounds.right - FONT_WIDTH; + screen.writeSymbol(5); + + // Write the vertical edges + if (yCount > 0) { + int symbolId = 6; + for (int i = 0; i < yCount; ++i) { + screen._writePos.y += 8; + + screen._writePos.x = _bounds.left; + screen.writeSymbol(symbolId); + + screen._writePos.x = _bounds.right - FONT_WIDTH; + screen.writeSymbol(symbolId + 4); + + if (++symbolId == 10) + symbolId = 6; + } + } + + // Write the bottom line + screen._writePos = Common::Point(_bounds.left, _bounds.bottom - FONT_HEIGHT); + screen.writeSymbol(14); + + if (xCount > 0) { + int symbolId = 15; + for (int i = 0; i < xCount; ++i) { + screen.writeSymbol(symbolId); + if (++symbolId == 19) + symbolId = 15; + } + } + + screen._writePos.x = _bounds.right - FONT_WIDTH; + screen.writeSymbol(19); +} + +void Window::close() { + Screen &screen = *_vm->_screen; + + if (_enabled) { + // Update the window + update(); + + // Restore the saved original content + screen.copyRectToSurface(_savedArea, _bounds.left, _bounds.top, + Common::Rect(0, 0, _bounds.width(), _bounds.height())); + addDirtyRect(_bounds); + + // Remove the window from the stack and flag it as now disabled + for (uint i = 0; i < _vm->_screen->_windowStack.size(); ++i) { + if (_vm->_screen->_windowStack[i] == this) + _vm->_screen->_windowStack.remove_at(i); + } + + _enabled = false; + } + + if (_vm->_mode == MODE_9) { + warning("TODO: copyFileToMemory"); + } +} + +void Window::update() { + // Since all window drawing is done on the screen surface anyway, + // there's nothing that needs to be updated here +} + +void Window::addDirtyRect(const Common::Rect &r) { + _vm->_screen->addDirtyRect(r); +} + +void Window::fill() { + fillRect(_innerBounds, _vm->_screen->_bgColor); +} + +const char *Window::writeString(const Common::String &s) { + return _vm->_screen->writeString(s, _innerBounds); +} + +void Window::drawList(DrawStruct *items, int count) { + for (int i = 0; i < count; ++i, ++items) { + if (items->_frame == -1 || items->_scale == -1 || items->_sprites == nullptr) + continue; + + Common::Point pt(items->_x, items->_y); + pt.x += _innerBounds.left; + pt.y += _innerBounds.top; + + items->_sprites->draw(*this, items->_frame, pt, items->_flags, items->_scale); + } +} + +} // End of namespace Xeen diff --git a/engines/xeen/window.h b/engines/xeen/window.h new file mode 100644 index 0000000000..72bbf30afa --- /dev/null +++ b/engines/xeen/window.h @@ -0,0 +1,101 @@ +/* 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 XEEN_WINDOW_H +#define XEEN_WINDOW_H + +#include "common/rect.h" +#include "common/str.h" +#include "xeen/sprites.h" +#include "xeen/xsurface.h" + +namespace Xeen { + +class XeenEngine; + +struct DrawStruct { + SpriteResource *_sprites; + int _frame; + int _x; + int _y; + int _scale; + int _flags; + + DrawStruct(int frame, int x, int y, int scale = 0, int flags = 0) : + _sprites(nullptr), _frame(frame), _x(x), _y(y), _scale(scale), _flags(flags) {} + DrawStruct(): _sprites(nullptr), _frame(0), _x(0), _y(0), _scale(0), _flags(0) {} +}; + +class Window: public XSurface { +private: + static XeenEngine *_vm; + Common::Rect _bounds; + Common::Rect _innerBounds; + XSurface _savedArea; + int _a; + int _border; + int _xLo, _xHi; + int _ycL, _ycH; + + void open2(); +public: + bool _enabled; +public: + static void init(XeenEngine *vm); +public: + Window(); + Window(const Window &src); + Window(const Common::Rect &bounds, int a, int border, + int xLo, int ycL, int xHi, int ycH); + + virtual void addDirtyRect(const Common::Rect &r); + + void setBounds(const Common::Rect &r); + + const Common::Rect &getBounds() { return _bounds; } + + void open(); + + void close(); + + /** + * Update the window + */ + void update(); + + void frame(); + + /** + * Fill the content area of a window with the current background color + */ + void fill(); + + const char *writeString(const Common::String &s); + + void drawList(DrawStruct *items, int count); + + int getString(Common::String &line, uint maxLen, int maxWidth); +}; + +} // End of namespace Xeen + +#endif /* XEEN_WINDOW_H */ |