Wing Commander II
Reconstructed Win32 source (1996)
Toggle main menu visibility
Loading...
Searching...
No Matches
textfmt.c
Go to the documentation of this file.
1
/*
2
* Formatted text output.
3
*
4
* Retail object 0x420340-0x4207AF (link order; see docs/ORDER.md).
5
*/
6
#include "
game.h
"
7
8
/* Function start: 0x420340 */
9
void
EmitTextString
(
void
(*writer)(
int
),
const
char
*text)
10
{
11
short
character;
12
13
while
((character = (
signed
char
)*text++) != 0)
14
writer((
short
)character);
15
}
16
17
/* Function start: 0x420378 */
18
void
FormatTextTokens
(
void
(*writer)(
int
),
19
const
char
*format, va_list arguments)
20
{
21
short
spec;
22
char
number[64];
23
short
ch;
24
25
if
(
g_29_pCurrentTextContext
== 0)
26
return
;
27
while
((ch = (
signed
char
)*format++) != 0) {
28
switch
(ch) {
29
case
'%'
:
30
spec = (
signed
char)*format++;
31
switch
(spec) {
32
case
'd'
:
33
EmitTextString
(writer,
34
itoa(va_arg(arguments,
short
), number, 10));
35
break
;
36
case
'u'
:
37
EmitTextString
(
38
writer,
39
ultoa(va_arg(arguments,
unsigned
short
), number, 10));
40
break
;
41
case
'D'
:
42
EmitTextString
(writer,
43
ltoa(va_arg(arguments,
long
), number, 10));
44
break
;
45
case
'U'
:
46
EmitTextString
(
47
writer,
48
ultoa(va_arg(arguments,
unsigned
long
), number, 10));
49
break
;
50
case
'x'
:
51
EmitTextString
(
52
writer,
53
strupr(ultoa(va_arg(arguments,
unsigned
short
),
54
number, 16)));
55
break
;
56
case
'c'
:
57
writer(va_arg(arguments,
short
));
58
break
;
59
case
'S'
:
60
case
's'
:
61
EmitTextString
(writer, va_arg(arguments,
char
*));
62
break
;
63
case
'X'
:
64
g_29_pCurrentTextContext
->
cursorX
=
65
va_arg(arguments,
short
);
66
break
;
67
case
'Y'
:
68
g_29_pCurrentTextContext
->
cursorY
=
69
va_arg(arguments,
short
);
70
break
;
71
case
'B'
:
72
g_29_pCurrentTextContext
->
backgroundColour
=
73
va_arg(arguments,
unsigned
char
);
74
break
;
75
case
'F'
:
76
g_29_pCurrentTextContext
->
colour
=
77
va_arg(arguments,
unsigned
char
);
78
break
;
79
case
'P'
:
80
if
(
g_9_bCinematicSpriteTextEnableStatus
== 0)
81
DrawTextString
(
g_29_pCurrentTextContext
->
text
);
82
else
83
DrawWrappedCinematicText
(
84
g_29_pCurrentTextContext
->
text
);
85
break
;
86
case
'J'
:
87
g_29_pCurrentTextContext
->
alignment
=
88
va_arg(arguments,
unsigned
char
);
89
break
;
90
default
:
91
writer(spec);
92
break
;
93
}
94
break
;
95
default
:
96
writer(ch);
97
break
;
98
}
99
}
100
}
101
102
/* Function start: 0x42067F */
103
void
DrawFormattedText
(
const
char
*format, ...)
104
{
105
va_list arguments;
106
107
va_start(arguments, format);
108
if
(
g_9_bCinematicSpriteTextEnableStatus
== 0) {
109
FormatTextTokens
((
void
(*)(
int
))
DrawTextCharacter
, format,
110
arguments);
111
}
else
{
112
FormatTextTokens
((
void
(*)(
int
))
DrawCinematicFontCharacter
,
113
format,
114
arguments);
115
}
116
va_end(arguments);
117
if
(
g_29_pCurrentTextContext
->
viewport
->
pixels
==
118
g_101_stScrViewInfo
.
pixels
)
119
MarkDibDirty
();
120
}
121
122
/* Function start: 0x4206F2 */
123
void
FormatTextBufferFromStart
(
const
char
*format, ...)
124
{
125
va_list arguments;
126
127
va_start(arguments, format);
128
if
(
g_29_pCurrentTextContext
== 0)
129
return
;
130
g_29_pCurrentTextContext
->
textCursor
=
131
g_29_pCurrentTextContext
->
text
;
132
FormatTextTokens
((
void
(*)(
int
))
AppendTextCharacter
, format,
133
arguments);
134
va_end(arguments);
135
if
(
g_29_pCurrentTextContext
->
viewport
->
pixels
==
136
g_101_stScrViewInfo
.
pixels
)
137
MarkDibDirty
();
138
}
139
140
/* Function start: 0x42075F */
141
void
AppendFormattedText
(
const
char
*format, ...)
142
{
143
va_list arguments;
144
145
va_start(arguments, format);
146
FormatTextTokens
((
void
(*)(
int
))
AppendTextCharacter
, format,
147
arguments);
148
va_end(arguments);
149
if
(
g_29_pCurrentTextContext
->
viewport
->
pixels
==
150
g_101_stScrViewInfo
.
pixels
)
151
MarkDibDirty
();
152
}
FormatTextBufferFromStart
void FormatTextBufferFromStart(const char *format,...)
Definition
textfmt.c:123
EmitTextString
void EmitTextString(void(*writer)(int), const char *text)
Definition
textfmt.c:9
DrawWrappedCinematicText
void DrawWrappedCinematicText(char *text)
Definition
text.c:40
DrawTextString
void DrawTextString(const char *text)
Definition
eventmgr.c:262
FormatTextTokens
void FormatTextTokens(void(*writer)(int), const char *format, va_list arguments)
Definition
textfmt.c:18
AppendTextCharacter
void AppendTextCharacter(char character)
Definition
eventmgr.c:375
AppendFormattedText
void AppendFormattedText(const char *format,...)
Definition
textfmt.c:141
DrawFormattedText
void DrawFormattedText(const char *format,...)
Definition
textfmt.c:103
MarkDibDirty
void MarkDibDirty(void)
Definition
dib.cpp:532
DrawCinematicFontCharacter
void DrawCinematicFontCharacter(char character)
Definition
text.c:9
DrawTextCharacter
void DrawTextCharacter(char character)
Definition
eventmgr.c:348
game.h
Shared Win32 declarations, types and library interfaces.
g_9_bCinematicSpriteTextEnableStatus
signed char g_9_bCinematicSpriteTextEnableStatus
Definition
eventmgr.c:2516
g_29_pCurrentTextContext
TextContext * g_29_pCurrentTextContext
Definition
eventmgr.c:2563
g_101_stScrViewInfo
Viewport g_101_stScrViewInfo
Definition
cockpt.c:3831
TextContext::colour
unsigned char colour
Definition
game.h:288
TextContext::cursorY
short cursorY
Definition
game.h:286
TextContext::text
char * text
Definition
game.h:290
TextContext::backgroundColour
unsigned char backgroundColour
Definition
game.h:289
TextContext::alignment
signed char alignment
Definition
game.h:292
TextContext::textCursor
char * textCursor
Definition
game.h:291
TextContext::cursorX
short cursorX
Definition
game.h:285
TextContext::viewport
Viewport * viewport
Definition
game.h:284
Viewport::pixels
unsigned char * pixels
Definition
game.h:150
src
textfmt.c
Generated by
1.18.0