-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvorple-screen-effects.h
342 lines (281 loc) · 10.1 KB
/
vorple-screen-effects.h
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#Ifndef VORPLE_SCREEN_EFFECTS;
System_file;
Constant VORPLE_SCREEN_EFFECTS;
Include "vorple.h";
! Vorple equivalent of Basic Screen Effects by Emily Short. Waiting for a keypress, clearing the screen, aligning, styling and coloring text.
!================================
! Utilities
[ VorpleScreenHeight i screen_height ;
if (isVorpleSupported()) {
return 24;
} else {
i = 0->32;
if (screen_height == 0 or 255) screen_height = 18;
screen_height = screen_height - 7;
return screen_height;
}
];
[ VorpleScreenWidth ;
if (isVorpleSupported()) {
return 80; ! FIXME when juhana replied
} else {
return ScreenWidth();
}
];
!================================
! Aligned text
Constant STYLE_FIXED_WIDTH = STYLE_MONOSPACE;
[ VorpleCenterText str i j len;
if (isVorpleSupported()) {
VorplePlaceBlockLevelElement("center-align", str);
} else {
! Centering in Z-machine - always fixed-width, otherwise ugly
! TODO: glulx
font off;
print "^";
!i = ScreenWidth();
!print "i =",i;
!len = str-->0; ! THIS IS NOT GOOD gives the wrong length
!print "len ="; print len;
!if (len > i-2) { len = i-2; }
!j = (i-len)/2 -1;
!print "j =",j;
!!!!!!!Print__Spaces(j);
print (PrintStringOrArray) str;
font on;
}
];
[ VorpleRightAlign str ;
!should we attempt something if IsVorpleSupported() == 0?
VorplePlaceBlockLevelElement("right-aligned", str);
];
!=======================================
! Boxed quotations
! TODO: what does this do?
!
! Section 3 - Displaying boxed quotations (in place of Section SR5/1/7 - Saying - Fonts and visual effects in Standard Rules by Graham Nelson)
!
! To say bold type -- running on
! (documented at phs_bold):
! (- style bold; -).
! To say italic type -- running on
! (documented at phs_italic):
! (- style underline; -).
! To say roman type -- running on
! (documented at phs_roman):
! (- style roman; -).
! To say fixed letter spacing -- running on
! (documented at phs_fixedspacing):
! (- font off; -).
! To say variable letter spacing -- running on
! (documented at phs_varspacing):
! (- font on; -).
! To display the boxed quotation (Q - text) in Glulx
! (documented at ph_boxed):
! (- DisplayBoxedQuotation({-box-quotation-text:Q}); -).
[ VorpleBoxedQuotation text ;
if (isVorpleSupported()) {
VorplePlaceElement("blockquote", 0, text);
} else {
! TODO: support for multi-line box quotations in the glulx fallback
! note: "box text;" doesn't work!...
return ;
}
];
!=================================================
! Styles and colors
Constant STYLE_CURSIVE = 0;
Constant STYLE_EMPHASIS = 1;
Constant STYLE_FANTASY = 2;
Constant STYLE_IMPACT = 2;
Constant STYLE_MONOSPACE = 3;
Constant STYLE_NOWRAP = 4;
Constant STYLE_STRIKETHROUGH = 5;
Constant STYLE_STRONG = 6;
! Constant STYLE_TRANSIENT = 7;
Constant STYLE_UNDERLINE = 8;
Constant STYLE_XXSMALL = 9;
Constant STYLE_XSMALL = 10;
Constant STYLE_SMALL = 11;
Constant STYLE_LARGE = 12;
Constant STYLE_XLARGE = 13;
Constant STYLE_XXLARGE = 14;
Constant STYLE_BLACK_LETTERS = 15;
Constant STYLE_RED_LETTERS = 16;
Constant STYLE_GREEN_LETTERS = 17;
Constant STYLE_YELLOW_LETTERS = 18;
Constant STYLE_BLUE_LETTERS = 19;
Constant STYLE_MAGENTA_LETTERS = 20;
Constant STYLE_CYAN_LETTERS = 21;
Constant STYLE_WHITE_LETTERS = 22;
Constant STYLE_BROWN_LETTERS = 31;
Constant STYLE_DARK_GRAY_LETTERS = 32;
Constant STYLE_LIGHT_GRAY_LETTERS = 33;
Constant STYLE_LIGHT_BLUE_LETTERS = 34;
Constant STYLE_LIGHT_GREEN_LETTERS = 35;
Constant STYLE_LIGHT_CYAN_LETTERS = 36;
Constant STYLE_LIGHT_RED_LETTERS = 37;
Constant STYLE_LIGHT_MAGENTA_LETTERS = 38;
Constant STYLE_BLACK_BACKGROUND = 23;
Constant STYLE_RED_BACKGROUND = 24;
Constant STYLE_GREEN_BACKGROUND = 25;
Constant STYLE_YELLOW_BACKGROUND = 26;
Constant STYLE_BLUE_BACKGROUND = 27;
Constant STYLE_MAGENTA_BACKGROUND = 28;
Constant STYLE_CYAN_BACKGROUND = 29;
Constant STYLE_WHITE_BACKGROUND = 30;
Constant STYLE_BROWN_BACKGROUND = 39;
Constant STYLE_DARK_GRAY_BACKGROUND = 40;
Constant STYLE_LIGHT_GRAY_BACKGROUND = 41;
Constant STYLE_LIGHT_BLUE_BACKGROUND = 42;
Constant STYLE_LIGHT_GREEN_BACKGROUND = 43;
Constant STYLE_LIGHT_CYAN_BACKGROUND = 44;
Constant STYLE_LIGHT_RED_BACKGROUND = 45;
Constant STYLE_LIGHT_MAGENTA_BACKGROUND = 46;
[ StyleName sty ;
if (sty ofclass string) { return sty; }
switch(sty) {
STYLE_CURSIVE: return "cursive font";
STYLE_EMPHASIS: return "emphasized font";
STYLE_FANTASY: return "fantasy font";
STYLE_MONOSPACE: return "monospace font";
STYLE_NOWRAP: return "nowrap font";
STYLE_STRIKETHROUGH: return "strikethrough font";
STYLE_STRONG: return "strong font";
! STYLE_TRANSIENT: return "transient";
STYLE_UNDERLINE: return "underlined font";
STYLE_XXSMALL: return "xx-small font";
STYLE_XSMALL: return "x-small font";
STYLE_SMALL: return "small font";
STYLE_LARGE: return "large font";
STYLE_XLARGE: return "x-large font";
STYLE_XXLARGE: return "xx-large font";
STYLE_RED_LETTERS: return "red letters";
STYLE_GREEN_LETTERS: return "green letters";
STYLE_YELLOW_LETTERS: return "yellow letters";
STYLE_BLUE_LETTERS: return "blue letters";
STYLE_MAGENTA_LETTERS: return "magenta letters";
STYLE_CYAN_LETTERS: return "cyan letters";
STYLE_WHITE_LETTERS: return "white letters";
STYLE_BLACK_LETTERS: return "black letters";
STYLE_BROWN_LETTERS: return "brown letters";
STYLE_DARK_GRAY_LETTERS: return "dark gray letters";
STYLE_LIGHT_GRAY_LETTERS: return "light gray letters";
STYLE_LIGHT_BLUE_LETTERS: return "light blue letters";
STYLE_LIGHT_GREEN_LETTERS: return "light green letters";
STYLE_LIGHT_CYAN_LETTERS: return "light cyan letters";
STYLE_LIGHT_RED_LETTERS: return "light red letters";
STYLE_LIGHT_MAGENTA_LETTERS: return "light magenta letters";
STYLE_RED_BACKGROUND: return "red background";
STYLE_GREEN_BACKGROUND: return "green background";
STYLE_YELLOW_BACKGROUND: return "yellow background";
STYLE_BLUE_BACKGROUND: return "blue background";
STYLE_MAGENTA_BACKGROUND: return "magenta background";
STYLE_CYAN_BACKGROUND: return "cyan background";
STYLE_WHITE_BACKGROUND: return "white background";
STYLE_BLACK_BACKGROUND: return "black background";
STYLE_BROWN_BACKGROUND: return "brown background";
STYLE_DARK_GRAY_BACKGROUND: return "dark gray background";
STYLE_LIGHT_GRAY_BACKGROUND: return "light gray background";
STYLE_LIGHT_BLUE_BACKGROUND: return "light blue background";
STYLE_LIGHT_GREEN_BACKGROUND: return "light green background";
STYLE_LIGHT_CYAN_BACKGROUND: return "light cyan background";
STYLE_LIGHT_RED_BACKGROUND: return "light red background";
STYLE_LIGHT_MAGENTA_BACKGROUND: return "light magenta background";
default: return "cursive";
}
];
[ VorpleStyle style ;
VorpleExecuteJavaScriptCommand(BuildCommand("vorple.layout.openTag('span', '", StyleName(style),"'.split(' ').join('-').toLowerCase())"));
];
[ VorpleEndStyle ;
VorpleCloseHTMLTag();
];
!!!!! -- not ready yet --
[ VorpleApplyStyleToPage sty ;
return ;
! VorpleExecuteJavaScriptCommand(BuildCommand("$('#vorpleContainer')[0].className=$('#vorpleContainer')[0].className.replace(/\b[a-z]+\-foreground/,'');$('#vorpleContainer').addClass('", color, "-foreground')"));
];
! TODO: how do i make it so that when opacity is not set (i.e. by default) it should be 100 ?
[ VorpleSetElementTextColor classes red green blue opacity ;
! set the text color to RGB, + opacity in percent
return ;
];
[ VorpleSetElementsTextColor classes red green blue opacity ;
VorpleSetElementTextColor(BuildCommand(classes, ":last"), red, green, blue, opacity);
];
[ VorpleSetElementBackgroundColor classes red green blue opacity ;
! set background color to RGB, + opacity in percent
return ;
];
[ VorpleSetElementsBackgroundColor classes red green blue opacity ;
VorpleSetElementBackgroundColor(BuildCommand(classes, ":last"), red, green, blue, opacity);
];
! TODO: is there a way to have Z-machine fallback for this? Here's the old code:
!
!
![ VorpleDefaultStyle ;
! } else { @set_colour 1 1; }
!];
!
! To say red letters (letters written in red)
![ VorpleColorLetters color ;
! } else { @set_colour color 0; }
!];
!
! To say red background (background of letters from then on to the next EndStyle is red)
![ VorpleColorLettersBackground color ;
! } else { @set_colour 0 color; }
!];
!
! To turn the foreground red (the whole page has red foreground)
![ VorpleForegroundColor color ;
! } else { @set_colour color 0; }
!];
!
! To turn the background red (the whole page has red background)
![ VorpleBackgroundColor color ;
! } else { @set_colour 0 color; }
!];
!!!!
!=============================
! Headers
[ VorplePlaceHeader level text classes ;
if (classes == 0) { classes = ""; }
VorplePlaceElement(BuildCommand("h", IntToString(level)), classes, text);
];
!=============================
! Lists
[ VorpleDisplayOrderedList list classes len i ;
if (classes == 0) { classes = ""; }
! List must be a table, like page 43 of DM4
len = list-->0;
VorpleOpenHTMLTag("ol", classes);
if (isVorpleSupported()) {
for (i=1: i<=len: i++) {
VorplePlaceElement("li", 0, list-->i);
}
} else {
for (i=1: i<=len: i++) {
print " "; print (string) IntToString(i); print ". "; print (string) list-->i; print "^";
}
}
VorpleCloseHTMLTag();
];
[ VorpleDisplayUnorderedList list classes len i ;
if (classes == 0) { classes = ""; }
! List must be a table, like page 43 of DM4
len = list-->0;
VorpleOpenHTMLTag("ul", classes);
if (isVorpleSupported()) {
for (i=1: i<=len: i++) {
VorplePlaceElement("li", 0, list-->i);
}
} else {
for (i=1: i<=len: i++) {
print " * "; print (string) list-->i; print "^";
}
}
VorpleCloseHTMLTag();
];
#Endif;