aboutsummaryrefslogtreecommitdiff
path: root/graphics/macgui/mactext.h
blob: 3870451014e343024f07f07c8557ba4f10a32bb2 (plain)
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
/* 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 GRAPHICS_MACGUI_MACTEXT_H
#define GRAPHICS_MACGUI_MACTEXT_H

#include "graphics/fontman.h"
#include "graphics/managed_surface.h"
#include "graphics/font.h"

namespace Graphics {

class MacWindowManager;

struct MacFontRun {
	Common::String text;

	uint16 fontId;
	byte textSlant;
	byte unk3f;
	uint16 fontSize;
	uint16 palinfo1;
	uint16 palinfo2;
	uint16 palinfo3;

	const Font *font;
	MacWindowManager *wm;

	MacFontRun() {
		wm = nullptr;
		fontId = textSlant = unk3f = fontSize = 0;
		palinfo1 = palinfo2  = palinfo3 = 0;
		font = nullptr;
	}

	MacFontRun(MacWindowManager *wm_, uint16 fontId_, byte textSlant_, byte unk3f_, uint16 fontSize_,
			uint16 palinfo1_, uint16 palinfo2_, uint16 palinfo3_) {
		setValues(wm_, fontId_, textSlant_, unk3f_, fontSize_, palinfo1_, palinfo2_, palinfo3_);
	}

	void setValues(MacWindowManager *wm_, uint16 fontId_, byte textSlant_, byte unk3f_, uint16 fontSize_,
			uint16 palinfo1_, uint16 palinfo2_, uint16 palinfo3_) {
		wm        = wm_;
		fontId    = fontId_;
		textSlant = textSlant_;
		unk3f     = unk3f_;
		fontSize  = fontSize_;
		palinfo1  = palinfo1_;
		palinfo2  = palinfo2_;
		palinfo3  = palinfo3_;
		font      = nullptr;
	}

	const Font *getFont();
};

struct MacTextLine {
	int width;
	int height;
	int y;

	Common::Array<MacFontRun> chunks;

	MacTextLine() {
		width = height = -1;
		y = 0;
	}
};

class MacText {
public:
	MacText(Common::String s, MacWindowManager *wm, const MacFont *font, int fgcolor, int bgcolor,
			int maxWidth = -1, TextAlign textAlignment = kTextAlignLeft, int interlinear = 0);
			// 0 pixels between the lines by default
	~MacText();

	void setInterLinear(int interLinear);

	void draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int yoff);
	void resizeAndFormatLines(uint numNewLines, MacFontRun * fontRun);
	void appendText(Common::String str, int fontId, int fontSize, int fontSlant);
	void appendTextDefault(Common::String str);
	void clearText();
	void replaceLastLine(Common::String str);
	int getLineCount() { return _textLines.size(); }

	void render();
	Graphics::ManagedSurface *getSurface() { return _surface; }

private:
	void splitString(Common::String &s);
	void render(int from, int to);
	void recalcDims();
	void reallocSurface();
	int getLineWidth(int line, bool enforce = false);
	int getLineHeight(int line);

private:
	MacWindowManager *_wm;

	Common::String _str;
	const MacFont *_macFont;
	int _fgcolor, _bgcolor;

	int _maxWidth;
	int _interLinear;

	int _textMaxWidth;
	int _textMaxHeight;

	Graphics::ManagedSurface *_surface;
	bool _fullRefresh;

	TextAlign _textAlignment;

	Common::Array<MacTextLine> _textLines;
	MacFontRun _defaultFormatting;
	MacFontRun _currentFormatting;
};

} // End of namespace Graphics

#endif