summaryrefslogtreecommitdiff
path: root/include/JSystem/JUtility/JUTFont.h
blob: b9e2b4f268e2530b658c7406af035edfe0bee699 (plain)
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
#ifndef JUTFONT_H
#define JUTFONT_H

#include "JSystem/JUtility/TColor.h"
#include "JSystem/JUtility/JUTDataHeader.h"
#include "string.h"

struct ResFONT {
    struct INF1 : JUTDataBlockHeader {
        /* 0x08 */ u16 fontType;
        /* 0x0A */ u16 ascent;
        /* 0x0C */ u16 descent;
        /* 0x0E */ u16 width;
        /* 0x10 */ u16 leading;
        /* 0x12 */ u16 defaultCode;
    };

    struct WID1 : JUTDataBlockHeader {
        /* 0x08 */ u16 startCode;
        /* 0x0A */ u16 endCode;
        /* 0x0C */ u8 mChunkNum[4];
    };

    struct MAP1 : JUTDataBlockHeader {
        /* 0x08 */ u16 mappingMethod;
        /* 0x0A */ u16 startCode;
        /* 0x0C */ u16 endCode;
        /* 0x0E */ u16 numEntries;
        /* 0x10 */ u16 mLeading;
    };

    struct GLY1 : JUTDataBlockHeader {
        /* 0x08 */ u16 startCode;
        /* 0x0A */ u16 endCode;
        /* 0x0C */ u16 cellWidth;
        /* 0x0E */ u16 cellHeight;
        /* 0x10 */ u32 textureSize;
        /* 0x14 */ u16 textureFormat;
        /* 0x16 */ u16 numRows;
        /* 0x18 */ u16 numColumns;
        /* 0x1A */ u16 textureWidth;
        /* 0x1C */ u16 textureHeight;
        /* 0x1E */ u16 padding;
        /* 0x20 */ u8 data[];
    };

    /* 0x00 */ u64 magic;
    /* 0x08 */ u32 filesize;
    /* 0x0C */ u32 numBlocks;
    /* 0x10 */ u8 padding[0x10];
    /* 0x20 */ u8 data[];
};

class JUTFont {
public:
    JUTFont();
    virtual ~JUTFont() {}

    struct TWidth {
        u8 field_0x0;
        u8 field_0x1;
    };

    /* 0x0C */ virtual void setGX() = 0;
    /* 0x10 */ virtual void setGX(JUtility::TColor col1, JUtility::TColor col2);
    /* 0x14 */ virtual f32 drawChar_scale(f32 a1, f32 a2, f32 a3, f32 a4, int a5, bool a6) = 0;
    /* 0x18 */ virtual int getLeading() const = 0;
    /* 0x1C */ virtual s32 getAscent() const = 0;
    /* 0x20 */ virtual s32 getDescent() const = 0;
    /* 0x24 */ virtual s32 getHeight() const = 0;
    /* 0x28 */ virtual s32 getWidth() const = 0;
    /* 0x2C */ virtual void getWidthEntry(int i_no, TWidth* width) const = 0;
    /* 0x30 */ virtual int getCellWidth() const;
    /* 0x34 */ virtual s32 getCellHeight() const;
    /* 0x38 */ virtual int getFontType() const = 0;
    /* 0x3C */ virtual const ResFONT* getResFont() const = 0;
    /* 0x40 */ virtual bool isLeadByte(int a1) const = 0;

    static bool isLeadByte_1Byte(int b) { return false; }
    static bool isLeadByte_2Byte(int b) { return true; }
    static bool isLeadByte_ShiftJIS(int b) { return (b >= 0x81 && b <= 0x9f) || (b >= 0xe0 && b <= 0xfc);}

    void initialize_state();
    void setCharColor(JUtility::TColor col1);
    void setGradColor(JUtility::TColor col1, JUtility::TColor col2);
    f32 drawString_size_scale(f32 posX, f32 posY, f32 width, f32 height, const char* str, u32 usz,
                              bool visible);

    void drawString(int posX, int posY, const char* str, bool visible) {
        drawString_size(posX, posY, str, strlen(str), visible);
    }

    void drawString_size(int posX, int posY, const char* str, u32 len, bool visible) {
        drawString_size_scale(posX, posY, getWidth(), getHeight(), str, len, visible);
    }

    void drawString_scale(f32 posX, f32 posY, f32 width, f32 height, const char* str,
                          bool visible) {
        drawString_size_scale(posX, posY, width, height, str, strlen(str), visible);
    }

    int getOffset(int i_no) const {
        TWidth width;
        getWidthEntry(i_no, &width);
        return width.field_0x0;
    }
    int getWidth(int i_no) const {
        TWidth width;
        getWidthEntry(i_no, &width);
        return width.field_0x1;
    }

    bool isValid() const { return mValid; }
    bool isFixed() const { return mFixed; }
    int getFixedWidth() const { return mFixedWidth; }
    void setFixedWidth(bool fixed, int width) {
        mFixed = fixed;
        mFixedWidth = width;
    }

    void drawChar(int, int, int, bool) {}

    /* 0x04 */ bool mValid;
    /* 0x05 */ bool mFixed;
    /* 0x08 */ int mFixedWidth;
    /* 0x0C */ JUtility::TColor mColor1;
    /* 0x10 */ JUtility::TColor mColor2;
    /* 0x14 */ JUtility::TColor mColor3;
    /* 0x18 */ JUtility::TColor mColor4;
};

#endif /* JUTFONT_H */