NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
lyt_common.h
1#ifndef NW4R_LYT_COMMON_H
2#define NW4R_LYT_COMMON_H
3#include <nw4r/types_nw4r.h>
4
5#include <nw4r/math.h>
6#include <nw4r/ut.h>
7
8#include <revolution/GX.h>
9
10namespace nw4r {
11namespace lyt {
12
13// Forward declarations
15struct Size;
16
17namespace res {
18struct BinaryFileHeader;
19} // namespace res
20
21/******************************************************************************
22 *
23 * VertexColor
24 *
25 ******************************************************************************/
26enum VertexColor {
27 VERTEXCOLOR_LT,
28 VERTEXCOLOR_RT,
29 VERTEXCOLOR_LB,
30 VERTEXCOLOR_RB,
31
32 VERTEXCOLOR_MAX
33};
34
35/******************************************************************************
36 *
37 * TevColor
38 *
39 ******************************************************************************/
40enum TevColor {
41 TEVCOLOR_REG0,
42 TEVCOLOR_REG1,
43 TEVCOLOR_REG2,
44
45 TEVCOLOR_MAX
46};
47
48/******************************************************************************
49 *
50 * Text position
51 *
52 ******************************************************************************/
53enum HorizontalPosition {
54 HORIZONTALPOSITION_LEFT,
55 HORIZONTALPOSITION_CENTER,
56 HORIZONTALPOSITION_RIGHT,
57 HORIZONTALPOSITION_MAX
58};
59enum VerticalPosition {
60 VERTICALPOSITION_TOP,
61 VERTICALPOSITION_CENTER,
62 VERTICALPOSITION_BOTTOM,
63 VERTICALPOSITION_MAX
64};
65
66namespace detail {
67
68/******************************************************************************
69 *
70 * Vertex colors
71 *
72 ******************************************************************************/
73inline u8 GetVtxColorElement(const ut::Color* pColors, ulong idx) {
74 return reinterpret_cast<const u8*>(&pColors[idx / 4])[idx % 4];
75}
76inline void SetVtxColorElement(ut::Color* pColors, ulong idx, u8 value) {
77 reinterpret_cast<u8*>(&pColors[idx / 4])[idx % 4] = value;
78}
79
80/******************************************************************************
81 *
82 * Positioning
83 *
84 ******************************************************************************/
85inline u8 GetHorizontalPosition(u8 packed) {
86 return packed % HORIZONTALPOSITION_MAX;
87}
88inline u8 GetVerticalPosition(u8 packed) {
89 return packed / HORIZONTALPOSITION_MAX;
90}
91
92inline void SetHorizontalPosition(u8* pPacked, u8 value) {
93 *pPacked = GetVerticalPosition(*pPacked) * HORIZONTALPOSITION_MAX + value;
94}
95inline void SetVerticalPosition(u8* pPacked, u8 value) {
96 *pPacked = value * HORIZONTALPOSITION_MAX + GetHorizontalPosition(*pPacked);
97}
98
99/******************************************************************************
100 *
101 * TexCoordAry
102 *
103 ******************************************************************************/
104typedef math::VEC2 TexCoord[VERTEXCOLOR_MAX];
105
106class TexCoordAry {
107public:
108 TexCoordAry();
109
110 void Free();
111 void Reserve(u8 num);
112 void SetSize(u8 num);
113 void Copy(const void* pSrc, u8 num);
114
115 bool IsEmpty() const {
116 return mCap == 0;
117 }
118
119 u8 GetSize() const {
120 return mNum;
121 }
122
123 TexCoord* GetArray() const {
124 return mpData;
125 }
126
127private:
128 u8 mCap; // at 0x0
129 u8 mNum; // at 0x1
130 TexCoord* mpData;
131};
132
133/******************************************************************************
134 *
135 * Utility functions
136 *
137 ******************************************************************************/
138inline bool IsCITexelFormat(GXTexFmt format) {
139 return format == GX_TF_C4 || format == GX_TF_C8 || format == GX_TF_C14X2;
140}
141
142inline s32 GetSignatureInt(const char* pSignature) {
143 return *reinterpret_cast<const s32*>(pSignature);
144}
145
146inline const char* GetStrTableStr(const void* pTable, int index) {
147 const ulong* pOffsetTbl = static_cast<const ulong*>(pTable);
148 const char* pStringPool = static_cast<const char*>(pTable);
149 return pStringPool + pOffsetTbl[index];
150}
151
152bool TestFileHeader(const res::BinaryFileHeader& rHeader);
153bool TestFileHeader(const res::BinaryFileHeader& rHeader, ulong signature);
154
155bool EqualsResName(const char* pLhs, const char* pRhs);
156bool EqualsMaterialName(const char* pLhs, const char* pRhs);
157
158bool IsModulateVertexColor(ut::Color* pColors, u8 glbAlpha);
159
160ut::Color MultipleAlpha(ut::Color color, u8 alpha);
161void MultipleAlpha(ut::Color* pDst, const ut::Color* pSrc, u8 alpha);
162
163void SetVertexFormat(bool modulate, u8 numCoord);
164
165void DrawQuad(const math::VEC2& rBase, const Size& rSize, u8 num,
166 const TexCoord* pCoords, const ut::Color* pColors);
167void DrawQuad(const math::VEC2& rBase, const Size& rSize, u8 num,
168 const TexCoord* pCoords, const ut::Color* pColors, u8 alpha);
169
170} // namespace detail
171} // namespace lyt
172} // namespace nw4r
173
174#endif
2D graphics drawing library.