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
|
/* 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;
uint16 fontSize;
uint16 palinfo1;
uint16 palinfo2;
uint16 palinfo3;
const Font *font;
MacWindowManager *wm;
MacFontRun() {
wm = nullptr;
fontId = textSlant = fontSize = 0;
palinfo1 = palinfo2 = palinfo3 = 0;
font = nullptr;
}
MacFontRun(MacWindowManager *wm_, uint16 fontId_, byte textSlant_, uint16 fontSize_,
uint16 palinfo1_, uint16 palinfo2_, uint16 palinfo3_) {
setValues(wm_, fontId_, textSlant_, fontSize_, palinfo1_, palinfo2_, palinfo3_);
}
void setValues(MacWindowManager *wm_, uint16 fontId_, byte textSlant_, uint16 fontSize_,
uint16 palinfo1_, uint16 palinfo2_, uint16 palinfo3_) {
wm = wm_;
fontId = fontId_;
textSlant = textSlant_;
fontSize = fontSize_;
palinfo1 = palinfo1_;
palinfo2 = palinfo2_;
palinfo3 = palinfo3_;
font = nullptr;
}
const Font *getFont();
const Common::String toString();
};
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();
int getInterLinear() { return _interLinear; }
void setInterLinear(int interLinear);
void setMaxWidth(int maxWidth);
void setDefaultFormatting(uint16 fontId_, byte textSlant_, uint16 fontSize_,
uint16 palinfo1_, uint16 palinfo2_, uint16 palinfo3_) {
_defaultFormatting.setValues(_defaultFormatting.wm, fontId_, textSlant_, fontSize_, palinfo1_, palinfo2_, palinfo3_);
}
void draw(ManagedSurface *g, int x, int y, int w, int h, int xoff, int yoff);
void appendText(Common::String str, int fontId = kMacFontChicago, int fontSize = 12, int fontSlant = kMacFontRegular, bool skipAdd = false);
void appendTextDefault(Common::String str, bool skipAdd = false);
void clearText();
void replaceLastLine(Common::String str);
void removeLastLine();
int getLineCount() { return _textLines.size(); }
int getTextHeight() { return _textMaxHeight; }
int getLineHeight(int line);
void render();
Graphics::ManagedSurface *getSurface() { return _surface; }
void getRowCol(int x, int y, int *sx, int *sy, int *row, int *col);
Common::String getTextChunk(int startRow, int startCol, int endRow, int endCol, bool formatted = false, bool newlines = true);
private:
void splitString(Common::String &s);
void render(int from, int to);
void recalcDims();
void reallocSurface();
int getLineWidth(int line, bool enforce = false);
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
|