Wing Commander II
Reconstructed Win32 source (1996)
Toggle main menu visibility
Loading...
Searching...
No Matches
text.c
Go to the documentation of this file.
1
/*
2
* Cinematic sprite-font renderer.
3
*
4
* Retail object 0x433690-0x433ACF (link order; see docs/ORDER.md).
5
*/
6
#include "
game.h
"
7
8
/* Function start: 0x433690 */
9
void
DrawCinematicFontCharacter
(
char
character)
10
{
11
ShortRect
bounds;
12
short
frame;
13
14
if
(
IsCinematicFontCharacterPrintable
((
short
)(
signed
char
)character) == 0) {
15
g_29_pCurrentTextContext
->
cursorX
=
16
(short)(
g_29_pCurrentTextContext
->
cursorX
+ 5);
17
return
;
18
}
19
frame = (short)((
signed
char
)character - 0x21);
20
GetShapeFrameBounds
(&bounds.
left
, 0, 0,
21
g_29_pCurrentTextContext
->
font
, frame);
22
DrawSpriteDefault
(
g_29_pCurrentTextContext
->
viewport
,
23
g_29_pCurrentTextContext
->
cursorX
,
24
g_29_pCurrentTextContext
->
cursorY
,
25
g_29_pCurrentTextContext
->
font
, frame);
26
g_29_pCurrentTextContext
->
cursorX
= (short)(
27
bounds.
right
- bounds.
left
+
28
g_29_pCurrentTextContext
->
cursorX
+ 2);
29
}
30
31
/* Function start: 0x43374E */
32
short
IsCinematicFontCharacterPrintable
(
short
character)
33
{
34
if
(character < 0x21)
35
return
0;
36
return
1;
37
}
38
39
/* Function start: 0x433777 */
40
void
DrawWrappedCinematicText
(
char
*text)
41
{
42
char
*lineStart;
43
char
*end;
44
short
terminator;
45
short
usedWidth;
46
short
viewportWidth;
47
short
advance
;
48
short
ch;
49
50
lineStart = text;
51
viewportWidth = (short)(
52
g_29_pCurrentTextContext
->
viewport
->
right
-
53
g_29_pCurrentTextContext
->
viewport
->
left
+ 1);
54
while
(*lineStart != 0) {
55
usedWidth = 0;
56
end = lineStart;
57
while
((ch = (
signed
char
)*end) != 0) {
58
if
(ch ==
'\n'
)
59
break
;
60
advance
=
MeasureCinematicFontCharacterWidth
(ch);
61
usedWidth = (short)(usedWidth +
advance
);
62
if
(viewportWidth <= usedWidth) {
63
if
(isalnum(ch) != 0) {
64
while
(isalpha(ch) != 0) {
65
usedWidth = (short)(usedWidth -
advance
);
66
end--;
67
ch = (
signed
char)*end;
68
advance
=
69
MeasureCinematicFontCharacterWidth
(ch);
70
}
71
}
else
{
72
usedWidth = (short)(usedWidth -
advance
);
73
}
74
break
;
75
}
76
end++;
77
}
78
terminator = ch;
79
*end = 0;
80
switch
(
g_29_pCurrentTextContext
->
alignment
) {
81
case
0:
82
g_29_pCurrentTextContext
->
cursorX
=
83
g_29_pCurrentTextContext
->
viewport
->
left
;
84
break
;
85
case
1:
86
g_29_pCurrentTextContext
->
cursorX
= (short)(
87
g_29_pCurrentTextContext
->
viewport
->
right
-
88
usedWidth + 1);
89
break
;
90
case
2:
91
g_29_pCurrentTextContext
->
cursorX
= (short)(
92
g_29_pCurrentTextContext
->
viewport
->
left
+
93
(viewportWidth - usedWidth) / 2);
94
break
;
95
}
96
while
(*lineStart != 0)
97
DrawCinematicFontCharacter
(*lineStart++);
98
*lineStart = (char)terminator;
99
if
(terminator ==
'\n'
) {
100
g_29_pCurrentTextContext
->
cursorY
= (short)(
101
g_29_pCurrentTextContext
->
cursorY
+
102
MeasureCinematicFontLineHeight
() + 1);
103
lineStart++;
104
}
105
}
106
}
107
108
/* Function start: 0x433A14 */
109
short
MeasureCinematicFontCharacterWidth
(
short
character)
110
{
111
ShortRect
bounds;
112
113
if
(
IsCinematicFontCharacterPrintable
(character) == 0)
114
return
5;
115
GetShapeFrameBounds
(&bounds.
left
, 0, 0,
116
g_29_pCurrentTextContext
->
font
,
117
(
short
)(character - 0x21));
118
return
(
short
)(bounds.
right
- bounds.
left
+ 2);
119
}
120
121
/* Function start: 0x433A75 */
122
short
MeasureCinematicFontLineHeight
(
void
)
123
{
124
ShortRect
bounds;
125
126
GetShapeFrameBounds
(&bounds.
left
, 0, 0,
127
g_29_pCurrentTextContext
->
font
, 0);
128
return
(
short
)(bounds.
bottom
- bounds.
top
+ 2);
129
}
130
131
/* Function start: 0x433AB0 */
132
void
InitializeCinematicTextRenderer
(
void
)
133
{
134
g_36_pfnRenderSceneFontCharacterHandler
=
135
DrawCinematicFontCharacter
;
136
g_3_pfnRenderSceneTextStringHandler
=
DrawWrappedCinematicText
;
137
}
MeasureCinematicFontCharacterWidth
short MeasureCinematicFontCharacterWidth(short character)
Definition
text.c:109
DrawWrappedCinematicText
void DrawWrappedCinematicText(char *text)
Definition
text.c:40
InitializeCinematicTextRenderer
void InitializeCinematicTextRenderer(void)
Definition
text.c:132
DrawSpriteDefault
void DrawSpriteDefault(Viewport *viewport, short x, short y, unsigned char *shape, short frame)
Definition
gr.c:682
GetShapeFrameBounds
short GetShapeFrameBounds(short *bounds, short x, short y, unsigned char *shape, short frame)
Definition
eventmgr.c:228
IsCinematicFontCharacterPrintable
short IsCinematicFontCharacterPrintable(short character)
Definition
text.c:32
advance
void advance(short ship)
Definition
fl.c:181
MeasureCinematicFontLineHeight
short MeasureCinematicFontLineHeight(void)
Definition
text.c:122
DrawCinematicFontCharacter
void DrawCinematicFontCharacter(char character)
Definition
text.c:9
game.h
Shared Win32 declarations, types and library interfaces.
g_29_pCurrentTextContext
TextContext * g_29_pCurrentTextContext
Definition
eventmgr.c:2563
g_3_pfnRenderSceneTextStringHandler
void(*) g_3_pfnRenderSceneTextStringHandler(char *text)
Definition
eventmgr.c:2560
g_36_pfnRenderSceneFontCharacterHandler
void(*) g_36_pfnRenderSceneFontCharacterHandler(char character)
Definition
eventmgr.c:2567
ShortRect
Definition
game_data.h:478
ShortRect::top
short top
Definition
game_data.h:480
ShortRect::left
short left
Definition
game_data.h:479
ShortRect::right
short right
Definition
game_data.h:481
ShortRect::bottom
short bottom
Definition
game_data.h:482
TextContext::cursorY
short cursorY
Definition
game.h:286
TextContext::font
unsigned char * font
Definition
game.h:287
TextContext::alignment
signed char alignment
Definition
game.h:292
TextContext::cursorX
short cursorX
Definition
game.h:285
TextContext::viewport
Viewport * viewport
Definition
game.h:284
Viewport::right
short right
Definition
game.h:154
Viewport::left
short left
Definition
game.h:152
src
text.c
Generated by
1.18.0