-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqttext.cpp
More file actions
288 lines (240 loc) · 6.81 KB
/
Copy pathqttext.cpp
File metadata and controls
288 lines (240 loc) · 6.81 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
* ux_text.c - Unix interface, text functions
*
* This file is part of Frotz.
*
* Frotz 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.
*
* Frotz 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include "frotz/frotz.h"
#include "qtfrotz.h"
static int current_style = 0;
static int current_zfont = TEXT_FONT;
/*
* os_font_data
*
* Return true if the given font is available. The font can be
*
* TEXT_FONT
* PICTURE_FONT
* GRAPHICS_FONT
* FIXED_WIDTH_FONT
*
* The font size should be stored in "height" and "width". If
* the given font is unavailable then these values must _not_
* be changed.
*
*/
int os_font_data(int font, int *height, int *width)
{
int ret;
QMetaObject::invokeMethod(global_qtfrotzwindow,
"getFontData",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG(int, ret),
Q_ARG(int, font),
Q_ARG(int *, height),
Q_ARG(int *, width)
);
return ret;
}
/*
* os_set_colour
*
* Set the foreground and background colours which can be:
*
* DEFAULT_COLOUR
* BLACK_COLOUR
* RED_COLOUR
* GREEN_COLOUR
* YELLOW_COLOUR
* BLUE_COLOUR
* MAGENTA_COLOUR
* CYAN_COLOUR
* WHITE_COLOUR
*
* MS-DOS 320 columns MCGA mode only:
*
* GREY_COLOUR
*
* Amiga only:
*
* LIGHTGREY_COLOUR
* MEDIUMGREY_COLOUR
* DARKGREY_COLOUR
*
* There may be more colours in the range from 16 to 255; see the
* remarks on os_peek_colour.
*
*/
void os_set_colour(int new_foreground, int new_background)
{
QMetaObject::invokeMethod(global_qtfrotzwindow,"setFgColor",Qt::BlockingQueuedConnection,Q_ARG(QColor,new_foreground));
QMetaObject::invokeMethod(global_qtfrotzwindow,"setBgColor",Qt::BlockingQueuedConnection,Q_ARG(QColor,new_background));
if (new_foreground == 1)
QMetaObject::invokeMethod(global_qtfrotzwindow,"resetFgColor",Qt::BlockingQueuedConnection);
if (new_background == 1)
QMetaObject::invokeMethod(global_qtfrotzwindow,"resetBgColor",Qt::BlockingQueuedConnection);
os_set_text_style(current_style);
}
/*
* os_set_text_style
*
* Set the current text style. Following flags can be set:
*
* REVERSE_STYLE
* BOLDFACE_STYLE
* EMPHASIS_STYLE (aka underline aka italics)
* FIXED_WIDTH_STYLE
*
*/
void os_set_text_style(int new_style)
{
QMetaObject::invokeMethod(global_qtfrotzwindow,"selectFontAndStyle",Qt::BlockingQueuedConnection,Q_ARG(int,current_zfont),Q_ARG(int,new_style));
current_style = new_style;
}
/*
* os_set_font
*
* Set the font for text output. The interpreter takes care not to
* choose fonts which aren't supported by the interface.
*
*/
void os_set_font(int new_font)
{
QMetaObject::invokeMethod(global_qtfrotzwindow,"selectFontAndStyle",Qt::BlockingQueuedConnection,Q_ARG(int,new_font),Q_ARG(int,current_style));
current_zfont = new_font;
}
/*
* os_display_char
*
* Display a character of the current font using the current colours and
* text style. The cursor moves to the next position. Printable codes are
* all ASCII values from 32 to 126, ISO Latin-1 characters from 160 to
* 255, ZC_GAP (gap between two sentences) and ZC_INDENT (paragraph
* indentation). The screen should not be scrolled after printing to the
* bottom right corner.
*
*/
void os_display_char(zchar c)
{
if (c == ZC_GAP){
QMetaObject::invokeMethod(global_qtfrotzwindow,
"writeString",
Qt::BlockingQueuedConnection,
Q_ARG(QString, " ")
);
return;
}
if (c == ZC_INDENT){
QMetaObject::invokeMethod(global_qtfrotzwindow,
"writeString",
Qt::BlockingQueuedConnection,
Q_ARG(QString, " ")
);
return;
}
QMetaObject::invokeMethod(global_qtfrotzwindow,"writeString",Qt::BlockingQueuedConnection,Q_ARG(QChar,c));
}
/*
* os_display_string
*
* Pass a string of characters to os_display_char.
*
*/
void os_display_string(const zchar *s)
{
zchar c;
QString qs;
while ((c = (unsigned char) *s++) != 0)
if (c == ZC_NEW_FONT || c == ZC_NEW_STYLE)
{
// First flush string buffer.
if (qs.length())
{
QMetaObject::invokeMethod(global_qtfrotzwindow,"writeString",Qt::BlockingQueuedConnection,Q_ARG(QString,qs));
qs = "";
}
// Set new font or style.
int arg = (unsigned char) *s++;
if (c == ZC_NEW_FONT)
os_set_font(arg);
if (c == ZC_NEW_STYLE)
os_set_text_style(arg);
}
else
qs += c;
if (qs.length())
QMetaObject::invokeMethod(global_qtfrotzwindow,"writeString",Qt::BlockingQueuedConnection,Q_ARG(QString,qs));
}
/*
* os_char_width
*
* Return the width of the character in screen units.
*
*/
int os_char_width(zchar c)
{
int ret;
QMetaObject::invokeMethod(global_qtfrotzwindow,
"charWidth",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG(int, ret),
Q_ARG(QChar, c)
);
return ret;
}
/*
* os_string_width
*
* Calculate the length of a word in screen units. Apart from letters,
* the word may contain special codes:
*
* NEW_STYLE - next character is a new text style
* NEW_FONT - next character is a new font
*
*/
int os_string_width(const zchar *s)
{
int width = 0;
zchar c;
while ((c = *s++) != 0)
if (c == ZC_NEW_STYLE || c == ZC_NEW_FONT)
s++;
else
width += os_char_width(c);
return width;
}
/*
* os_set_cursor
*
* Place the text cursor at the given coordinates. Top left is (1,1).
* y relates to rows, x to colsumns.
*
*/
void os_set_cursor(int y, int x)
{
QMetaObject::invokeMethod(global_qtfrotzwindow,"setXY",Qt::BlockingQueuedConnection,Q_ARG(int,x-1),Q_ARG(int,y-1));
}
/*
* os_more_prompt
*
* Display a MORE prompt, wait for a keypress and remove the MORE
* prompt from the screen.
*
*/
void os_more_prompt()
{
QMetaObject::invokeMethod(global_qtfrotzwindow,"morePrompt",Qt::BlockingQueuedConnection);
}