sovereignx/gflib/text.h

175 lines
5.1 KiB
C
Raw Normal View History

2017-01-14 19:53:20 +00:00
#ifndef GUARD_TEXT_H
#define GUARD_TEXT_H
2021-10-30 21:19:10 +01:00
#include "characters.h"
2021-09-24 19:30:15 +01:00
2017-03-07 13:44:41 +00:00
#define NUM_TEXT_PRINTERS 32
2017-11-19 21:48:46 +00:00
#define TEXT_SPEED_FF 0xFF
2018-11-21 20:58:35 +00:00
enum
{
2018-07-15 12:23:38 +01:00
FONTATTR_MAX_LETTER_WIDTH,
FONTATTR_MAX_LETTER_HEIGHT,
FONTATTR_LETTER_SPACING,
FONTATTR_LINE_SPACING,
FONTATTR_UNKNOWN, // dunno what this is yet
2018-07-15 12:23:38 +01:00
FONTATTR_COLOR_FOREGROUND,
FONTATTR_COLOR_BACKGROUND,
FONTATTR_COLOR_SHADOW
};
2018-11-05 20:42:12 +00:00
struct TextPrinterSubStruct
2017-09-22 04:43:13 +01:00
{
2018-11-06 16:44:48 +00:00
u8 glyphId:4; // 0x14
bool8 hasPrintBeenSpedUp:1;
2018-11-06 17:30:21 +00:00
u8 unk:3;
2018-11-06 16:44:48 +00:00
u8 downArrowDelay:5;
u8 downArrowYPosIdx:2;
bool8 hasGlyphIdBeenSet:1;
2018-11-06 17:30:21 +00:00
u8 autoScrollDelay;
2017-09-22 04:43:13 +01:00
};
2018-11-06 16:44:48 +00:00
struct TextPrinterTemplate
2017-09-26 21:39:59 +01:00
{
2018-11-06 16:44:48 +00:00
const u8* currentChar;
2017-09-23 02:26:37 +01:00
u8 windowId;
u8 fontId;
u8 x;
u8 y;
u8 currentX; // 0x8
u8 currentY;
u8 letterSpacing;
u8 lineSpacing;
u8 unk:4; // 0xC
2018-01-25 21:25:35 +00:00
u8 fgColor:4;
2017-09-23 02:26:37 +01:00
u8 bgColor:4;
u8 shadowColor:4;
};
2017-03-07 13:44:41 +00:00
struct TextPrinter
{
2018-11-06 16:44:48 +00:00
struct TextPrinterTemplate printerTemplate;
2017-09-06 16:19:08 +01:00
2018-11-06 16:44:48 +00:00
void (*callback)(struct TextPrinterTemplate *, u16); // 0x10
2017-09-06 16:19:08 +01:00
2020-05-21 03:07:49 +01:00
u8 subStructFields[7]; // always cast to struct TextPrinterSubStruct... so why bother
2018-11-05 20:42:12 +00:00
u8 active;
2017-03-07 13:44:41 +00:00
u8 state; // 0x1C
2018-11-05 20:42:12 +00:00
u8 textSpeed;
2017-03-07 13:44:41 +00:00
u8 delayCounter;
u8 scrollDistance;
u8 minLetterSpacing; // 0x20
u8 japanese;
2017-03-07 13:44:41 +00:00
};
struct FontInfo
{
u16 (*fontFunction)(struct TextPrinter *x);
u8 maxLetterWidth;
u8 maxLetterHeight;
u8 letterSpacing;
u8 lineSpacing;
u8 unk:4;
2018-01-25 21:25:35 +00:00
u8 fgColor:4;
2017-03-07 13:44:41 +00:00
u8 bgColor:4;
u8 shadowColor:4;
};
2017-09-22 04:43:13 +01:00
extern const struct FontInfo *gFonts;
2017-09-18 22:48:47 +01:00
struct GlyphWidthFunc
{
2018-11-06 17:30:21 +00:00
u32 fontId;
2017-03-28 01:30:49 +01:00
u32 (*func)(u16 glyphId, bool32 isJapanese);
};
2017-09-18 22:48:47 +01:00
struct KeypadIcon
{
2018-11-06 17:30:21 +00:00
u16 tileOffset;
2017-03-28 01:30:49 +01:00
u8 width;
u8 height;
};
2017-09-22 04:43:13 +01:00
typedef struct {
2018-11-06 17:30:21 +00:00
bool8 canABSpeedUpPrint:1;
bool8 useAlternateDownArrow:1;
bool8 autoScroll:1;
bool8 forceMidTextSpeed:1;
2017-09-22 04:43:13 +01:00
} TextFlags;
2021-03-29 17:20:00 +01:00
struct TextGlyph
2018-11-05 20:42:12 +00:00
{
2021-03-29 17:20:00 +01:00
u32 gfxBufferTop[16];
u32 gfxBufferBottom[16];
2020-10-21 09:26:45 +01:00
u8 width;
u8 height;
2018-11-05 20:42:12 +00:00
};
2017-09-22 04:43:13 +01:00
extern TextFlags gTextFlags;
2021-03-29 17:20:00 +01:00
extern u8 gDisableTextPrinters;
extern struct TextGlyph gCurGlyph;
2017-09-22 04:43:13 +01:00
2017-03-28 05:20:55 +01:00
void SetFontsPointer(const struct FontInfo *fonts);
void DeactivateAllTextPrinters(void);
2018-11-06 16:44:48 +00:00
u16 AddTextPrinterParameterized(u8 windowId, u8 fontId, const u8 *str, u8 x, u8 y, u8 speed, void (*callback)(struct TextPrinterTemplate *, u16));
bool16 AddTextPrinter(struct TextPrinterTemplate *template, u8 speed, void (*callback)(struct TextPrinterTemplate *, u16));
2017-03-28 05:20:55 +01:00
void RunTextPrinters(void);
2017-09-18 22:48:47 +01:00
bool16 IsTextPrinterActive(u8 id);
2017-03-28 05:20:55 +01:00
u32 RenderFont(struct TextPrinter *textPrinter);
void GenerateFontHalfRowLookupTable(u8 fgColor, u8 bgColor, u8 shadowColor);
void SaveTextColors(u8 *fgColor, u8 *bgColor, u8 *shadowColor);
void RestoreTextColors(u8 *fgColor, u8 *bgColor, u8 *shadowColor);
2018-11-21 22:30:04 +00:00
void DecompressGlyphTile(const void *src_, void *dest_);
2017-03-28 05:20:55 +01:00
u8 GetLastTextColor(u8 colorType);
void CopyGlyphToWindow(struct TextPrinter *x);
void ClearTextSpan(struct TextPrinter *textPrinter, u32 width);
2018-02-09 02:00:28 +00:00
u8 GetMenuCursorDimensionByFont(u8, u8);
2017-03-28 05:20:55 +01:00
u16 Font0Func(struct TextPrinter *textPrinter);
u16 Font1Func(struct TextPrinter *textPrinter);
u16 Font2Func(struct TextPrinter *textPrinter);
u16 Font3Func(struct TextPrinter *textPrinter);
u16 Font4Func(struct TextPrinter *textPrinter);
u16 Font5Func(struct TextPrinter *textPrinter);
u16 Font7Func(struct TextPrinter *textPrinter);
u16 Font8Func(struct TextPrinter *textPrinter);
void TextPrinterInitDownArrowCounters(struct TextPrinter *textPrinter);
void TextPrinterDrawDownArrow(struct TextPrinter *textPrinter);
void TextPrinterClearDownArrow(struct TextPrinter *textPrinter);
bool8 TextPrinterWaitAutoMode(struct TextPrinter *textPrinter);
2017-09-22 04:43:13 +01:00
bool16 TextPrinterWaitWithDownArrow(struct TextPrinter *textPrinter);
bool16 TextPrinterWait(struct TextPrinter *textPrinter);
2017-03-28 05:20:55 +01:00
void DrawDownArrow(u8 windowId, u16 x, u16 y, u8 bgColor, bool8 drawArrow, u8 *counter, u8 *yCoordIndex);
u16 RenderText(struct TextPrinter *textPrinter);
2017-09-18 16:26:45 +01:00
u32 GetStringWidthFixedWidthFont(const u8 *str, u8 fontId, u8 letterSpacing);
2017-03-28 05:20:55 +01:00
u32 (*GetFontWidthFunc(u8 glyphId))(u16, bool32);
2018-12-15 22:58:47 +00:00
s32 GetStringWidth(u8 fontId, const u8 *str, s16 letterSpacing);
2017-03-28 05:20:55 +01:00
u8 RenderTextFont9(u8 *pixels, u8 fontId, u8 *str);
u8 DrawKeypadIcon(u8 windowId, u8 keypadIconId, u16 x, u16 y);
u8 GetKeypadIconTileOffset(u8 keypadIconId);
u8 GetKeypadIconWidth(u8 keypadIconId);
u8 GetKeypadIconHeight(u8 keypadIconId);
void SetDefaultFontsPointer(void);
u8 GetFontAttribute(u8 fontId, u8 attributeId);
u8 GetMenuCursorDimensionByFont(u8 fontId, u8 whichDimension);
void DecompressGlyphFont0(u16 glyphId, bool32 isJapanese);
u32 GetGlyphWidthFont0(u16 glyphId, bool32 isJapanese);
void DecompressGlyphFont7(u16 glyphId, bool32 isJapanese);
u32 GetGlyphWidthFont7(u16 glyphId, bool32 isJapanese);
void DecompressGlyphFont8(u16 glyphId, bool32 isJapanese);
u32 GetGlyphWidthFont8(u16 glyphId, bool32 isJapanese);
void DecompressGlyphFont2(u16 glyphId, bool32 isJapanese);
u32 GetGlyphWidthFont2(u16 glyphId, bool32 isJapanese);
void DecompressGlyphFont1(u16 glyphId, bool32 isJapanese);
u32 GetGlyphWidthFont1(u16 glyphId, bool32 isJapanese);
void DecompressGlyphFont9(u16 glyphId);
2019-03-02 08:18:08 +00:00
// unk_text_util_2.c
u16 Font6Func(struct TextPrinter *textPrinter);
u32 GetGlyphWidthFont6(u16 glyphId, bool32 isJapanese);
2017-01-14 19:53:20 +00:00
#endif // GUARD_TEXT_H