File: text_view.cpp

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (161 lines) | stat: -rw-r--r-- 4,177 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* 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 3 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, see <http://www.gnu.org/licenses/>.
 *
 */

#include "mm/mm1/globals.h"
#include "mm/mm1/gfx/gfx.h"
#include "mm/mm1/views/text_view.h"
#include "mm/mm1/mm1.h"

namespace MM {
namespace MM1 {
namespace Views {

TextView::TextView(const Common::String &name) :
		UIElement(name, g_engine) {
}

TextView::TextView(const Common::String &name, UIElement *owner) :
		UIElement(name, owner) {
}

void TextView::writeChar(unsigned char c) {
	if (c == '\r' || c == '\n') {
		_textPos.x = 0;
		_textPos.y++;
	} else {
		Graphics::ManagedSurface s = getSurface();
		g_globals->_font.drawChar(&s, c,
			_textPos.x * FONT_SIZE, _textPos.y * FONT_SIZE, _bgColor);

		if (++_textPos.x == TEXT_W) {
			_textPos.x = 0;
			++_textPos.y;
		}
	}
}

void TextView::writeChar(int x, int y, unsigned char c) {
	_textPos.x = x;
	_textPos.y = y;
	writeChar(c);
}

void TextView::writeString(const Common::String &str) {
	for (const unsigned char *s = (const unsigned char *)str.c_str(); *s; ++s) {
		writeChar(*s);

		if (*s >= ' ' && _textPos.x == 0 && (*(s + 1) == '\r' || *(s + 1) == '\n'))
			// Ignore carraige returns right after line wraps. The original didn't
			// have them and just carried on immedaitely with the next word,
			// but I wanted them to be present to cleanly identify line breaks
			++s;
	}
}

void TextView::writeString(int x, int y, const Common::String &str) {
	_textPos.x = x;
	_textPos.y = y;
	writeString(str);
}

void TextView::writeNumber(int val) {
	writeString(Common::String::format("%d", val));
}

void TextView::writeNumber(int x, int y, int val) {
	_textPos.x = x;
	_textPos.y = y;
	writeNumber(val);
}

void TextView::newLine() {
	_textPos.x = 0;
	_textPos.y++;
}

void TextView::writeSpaces(size_t count) {
	for (size_t i = 0; i < count; ++i)
		writeChar(' ');
}

void TextView::clearSurface() {
	UIElement::clearSurface();
	_textPos.x = _textPos.y = 0;
}

void TextView::clearLines(int y1, int y2) {
	Graphics::ManagedSurface s = getSurface();
	s.fillRect(getLineBounds(y1, y2), 0);
}

void TextView::drawTextBorder() {
	Graphics::ManagedSurface surf = getSurface();
	clearSurface();

	// Draw boxes in the four corners
	surf.fillRect(Common::Rect(0, 0, FONT_SIZE * 3, FONT_SIZE * 3), 255);
	surf.fillRect(Common::Rect(SCREEN_W - FONT_SIZE * 3, 0,
		SCREEN_W, FONT_SIZE * 3), 255);
	surf.fillRect(Common::Rect(0, SCREEN_H - FONT_SIZE * 3,
		FONT_SIZE * 3, SCREEN_H), 255);
	surf.fillRect(Common::Rect(SCREEN_W - FONT_SIZE * 3,
		SCREEN_H - FONT_SIZE * 3, SCREEN_W, SCREEN_H), 255);

	// Draw horizontal vertical lines
	for (int x = 3; x < TEXT_W - 3; ++x) {
		writeChar(x, 1, '-');
		writeChar(x, TEXT_H - 2, '-');
	}
	for (int y = 3; y < TEXT_H - 3; ++y) {
		writeChar(1, y, '!');
		writeChar(TEXT_W - 2, y, '!');
	}
}

void TextView::escToGoBack(int x, int y) {
	if (y == -1)
		y = (_bounds.height() / FONT_SIZE) - 1;

	writeString(x, y, STRING["dialogs.misc.go_back"]);
}

void TextView::timeout() {
	redraw();
}

bool TextView::msgDrawGraphic(const DrawGraphicMessage &msg) {
	// Refresh the background
	draw();

	// Draw the new image
	drawGraphic(msg._gfxNum);
	return true;
}

void TextView::drawGraphic(int gfxNum) {
	const Graphics::ManagedSurface img =
		g_globals->_monsters->getMonsterImage(gfxNum);
	getSurface().blitFrom(img, Common::Point(64, 16));
}

} // namespace Views
} // namespace MM1
} // namespace MM