coastline 0.0.4
Loading...
Searching...
No Matches
menufont.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdlib>
4#include <cstring>
5
6#include <windows.h>
7
8#include "common/fontdata.h"
9
10#undef DrawText
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
22static inline int ConvertMenuCoordinate(float value) {
23 if (!(static_cast<long double>(value) >= -0x1p63L &&
24 static_cast<long double>(value) < 0x1p63L)) {
25 return 0;
26 }
27 return static_cast<int>(static_cast<long long>(value));
28}
29#ifdef __cplusplus
30}
31#endif
32
33class MenuFont;
34
40class MenuFont {
41public:
49
55 virtual ~MenuFont();
56
63 virtual void MeasureText();
70 virtual void MeasureTextAltFont();
78 virtual void DrawMenuItemText(float x, float y);
84 virtual void DrawText();
92 virtual signed char HandleTextInput();
93
101 virtual long double ComputeCenteredX();
107 virtual void DrawTextAltFont();
108
110 const char *GetText() const {
111 return szText;
112 }
113
117 void SetText(const char *text) {
118 std::strcpy(szText, text);
119 }
120
125 void AppendText(const char *text) {
126 std::strcat(szText, text);
127 }
128
135 void CopyTextPrefix(const char *text, size_t size) {
136 std::strncpy(szText, text, size);
137 }
138
142 void SetNumber(int value) {
143 _itoa(value, szText, 10);
144 }
145
146 unsigned GetFlags() const {
147 return dwFlags;
148 }
149
154 unsigned SetFlags(unsigned value) {
155 return dwFlags = value;
156 }
157
162 unsigned char SetStyle(unsigned char value) {
163 return bStyle = value;
164 }
165
166 unsigned char GetStyle() const {
167 return bStyle;
168 }
169
170 short GetWidth() const {
171 return nWidth;
172 }
173
178 short SetWidth(short value) {
179 return nWidth = value;
180 }
181
182 short GetHeight() const {
183 return nHeight;
184 }
185
191 short SetHeight(short value) {
192 return nHeight = value;
193 }
194
199 float SetX(float value) {
200 return fX = value;
201 }
202
203 float GetX() const {
204 return fX;
205 }
206
207 float GetY() const {
208 return fY;
209 }
210
215 float SetY(float value) {
216 return fY = value;
217 }
218
223 float SetZ(float value) {
224 return fZ = value;
225 }
226
232 short SetInputMaxWidth(short value) {
233 return nInputMaxWidth = value;
234 }
235
236 int GetDrawCaret() const {
237 return bDrawCaret;
238 }
239
244 int SetDrawCaret(int value) {
245 return bDrawCaret = value;
246 }
247
249 return rcBounds.left;
250 }
251
255 const RECT &GetBounds() const {
256 return rcBounds;
257 }
258
264 return rcBounds.left = value;
265 }
266
268 return rcBounds.top;
269 }
270
276 return rcBounds.top = value;
277 }
278
280 return rcBounds.right;
281 }
282
288 return rcBounds.right = value;
289 }
290
296 return rcBounds.bottom = value;
297 }
298
299 unsigned GetItemData() const {
300 return dwItemData;
301 }
302
307 unsigned SetItemData(unsigned value) {
308 return dwItemData = value;
309 }
310
311private:
316 virtual int DrawGlyph(short nImage, float x, float y, int nStyle);
321 virtual int DrawGlyphNoOp(short nImage, float x, float y);
326 virtual int DrawGlyphAltFont(short nImage, float x, float y, int nStyle);
331 virtual void DrawThrottledMenuGlyph(float x, float y);
332
333 inline void MeasureMenuText(bool alternate);
334 inline void DrawMenuText(float x, float y, bool alternate, bool useFontY);
335
336 unsigned dwFlags;
337 unsigned char bStyle;
338 char szText[1024];
339 short nWidth;
340 short nHeight;
341 float fX;
342 float fY;
343 float fZ;
344 short nInputMaxWidth;
345 int bDrawCaret;
346 RECT rcBounds;
347 unsigned dwItemData;
348};
Menu text with a 1024-byte internal buffer, glyph metrics, drawing style, and text-entry state.
Definition menufont.h:40
unsigned GetItemData() const
Definition menufont.h:299
float SetX(float value)
Store horizontal position without updating bounds.
Definition menufont.h:199
virtual signed char HandleTextInput()
Process pending character and key input, including network-setup sound shortcuts.
void SetNumber(int value)
Replace text with a terminated signed decimal integer without measuring the result.
Definition menufont.h:142
MenuFont()
Initialise empty text, style one, zero dimensions and position, and an inactive caret.
virtual long double ComputeCenteredX()
Centre measured text between configured left and right bounds and store the horizontal position.
float SetY(float value)
Store vertical position without updating bounds.
Definition menufont.h:215
unsigned char SetStyle(unsigned char value)
Store a drawing style without changing font measurements.
Definition menufont.h:162
float GetY() const
Definition menufont.h:207
LONG GetBoundsTop() const
Definition menufont.h:267
int GetDrawCaret() const
Definition menufont.h:236
const RECT & GetBounds() const
Definition menufont.h:255
unsigned SetFlags(unsigned value)
Store text flags without measuring or drawing.
Definition menufont.h:154
unsigned GetFlags() const
Definition menufont.h:146
const char * GetText() const
Definition menufont.h:110
short GetWidth() const
Definition menufont.h:170
float SetZ(float value)
Store the legacy depth field without changing device state; text drawing does not read it.
Definition menufont.h:223
void AppendText(const char *text)
Append terminated text without checking capacity or measuring the result.
Definition menufont.h:125
unsigned SetItemData(unsigned value)
Store application-specific item data without interpreting it.
Definition menufont.h:307
int SetDrawCaret(int value)
Store caret state without resetting its shared blink timer.
Definition menufont.h:244
LONG GetBoundsLeft() const
Definition menufont.h:248
LONG SetBoundsLeft(LONG value)
Store the left bound without updating position or dimensions.
Definition menufont.h:263
short SetHeight(short value)
Store height without measuring text or updating bounds.
Definition menufont.h:191
virtual void MeasureText()
Recalculate primary-font width and raise height to the tallest recognised glyph if needed.
virtual void DrawText()
Draw primary-font text at the stored position, applying centring and an enabled caret.
LONG SetBoundsRight(LONG value)
Store the right bound without updating position or dimensions.
Definition menufont.h:287
void SetText(const char *text)
Copy terminated text without checking capacity or measuring the result.
Definition menufont.h:117
virtual ~MenuFont()
Destroy embedded text and state without releasing external resources.
virtual void DrawTextAltFont()
Draw alternate-font text at the stored position, applying centring and an enabled caret.
virtual void MeasureTextAltFont()
Recalculate alternate-font width and raise height without resetting prior height.
LONG SetBoundsTop(LONG value)
Store the top bound without updating position or dimensions.
Definition menufont.h:275
short GetHeight() const
Definition menufont.h:182
void CopyTextPrefix(const char *text, size_t size)
Copy a text prefix with strncpy() semantics, including zero padding after a source terminator.
Definition menufont.h:135
unsigned char GetStyle() const
Definition menufont.h:166
LONG GetBoundsRight() const
Definition menufont.h:279
short SetWidth(short value)
Store width without measuring text or updating bounds.
Definition menufont.h:178
LONG SetBoundsBottom(LONG value)
Store the bottom bound without updating position or dimensions.
Definition menufont.h:295
float GetX() const
Definition menufont.h:203
virtual void DrawMenuItemText(float x, float y)
Draw primary-font text at supplied coordinates, with optional centring and caret rendering.
short SetInputMaxWidth(short value)
Store the width threshold used before accepting an input character.
Definition menufont.h:232
static int ConvertMenuCoordinate(float value)
Truncate a floating-point coordinate using the native signed 64-bit conversion range.
Definition menufont.h:22
T strcat(T... args)
T strcpy(T... args)
T strncpy(T... args)
typedef LONG