1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "common/debug.h"
24 #include "common/rect.h"
25 #include "common/str.h"
26 #include "common/system.h"
27
28 #include "adl/display.h"
29
30 namespace Adl {
31
~Display()32 Display::~Display() {
33 delete[] _textBuf;
34 }
35
createTextBuffer(uint textWidth,uint textHeight)36 void Display::createTextBuffer(uint textWidth, uint textHeight) {
37 _textWidth = textWidth;
38 _textHeight = textHeight;
39
40 _textBuf = new byte[textWidth * textHeight];
41 memset(_textBuf, (byte)asciiToNative(' '), textWidth * textHeight);
42 }
43
setMode(Display::Mode mode)44 void Display::setMode(Display::Mode mode) {
45 _mode = mode;
46
47 if (_mode == Display::kModeText || _mode == Display::kModeMixed)
48 renderText();
49 if (_mode == Display::kModeGraphics || _mode == Display::kModeMixed)
50 renderGraphics();
51 }
52
home()53 void Display::home() {
54 memset(_textBuf, (byte)asciiToNative(' '), _textWidth * _textHeight);
55 _cursorPos = 0;
56 }
57
moveCursorForward()58 void Display::moveCursorForward() {
59 ++_cursorPos;
60
61 if (_cursorPos >= _textWidth * _textHeight)
62 scrollUp();
63 }
64
moveCursorBackward()65 void Display::moveCursorBackward() {
66 if (_cursorPos > 0)
67 --_cursorPos;
68 }
69
moveCursorTo(const Common::Point & pos)70 void Display::moveCursorTo(const Common::Point &pos) {
71 _cursorPos = pos.y * _textWidth + pos.x;
72
73 if (_cursorPos >= _textWidth * _textHeight)
74 error("Cursor position (%i, %i) out of bounds", pos.x, pos.y);
75 }
76
printString(const Common::String & str)77 void Display::printString(const Common::String &str) {
78 Common::String::const_iterator c;
79 for (c = str.begin(); c != str.end(); ++c)
80 printChar(*c);
81
82 renderText();
83 }
84
printAsciiString(const Common::String & str)85 void Display::printAsciiString(const Common::String &str) {
86 Common::String::const_iterator c;
87 for (c = str.begin(); c != str.end(); ++c)
88 printChar(asciiToNative(*c));
89
90 renderText();
91 }
92
setCharAtCursor(byte c)93 void Display::setCharAtCursor(byte c) {
94 _textBuf[_cursorPos] = c;
95 }
96
scrollUp()97 void Display::scrollUp() {
98 memmove(_textBuf, _textBuf + _textWidth, (_textHeight - 1) * _textWidth);
99 memset(_textBuf + (_textHeight - 1) * _textWidth, asciiToNative(' '), _textWidth);
100 if (_cursorPos >= _textWidth)
101 _cursorPos -= _textWidth;
102 }
103
104 } // End of namespace Adl
105