NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
lyt_layout.h
1#ifndef NW4R_LYT_LAYOUT_H
2#define NW4R_LYT_LAYOUT_H
3#include <nw4r/types_nw4r.h>
4
5#include <nw4r/lyt/lyt_animation.h>
6#include <nw4r/lyt/lyt_types.h>
7
8#include <nw4r/ut.h>
9
10#include <revolution/MEM.h>
11
12namespace nw4r {
13namespace lyt {
14
15// Forward declarations
17class DrawInfo;
18class GroupContainer;
19class Pane;
20
21/******************************************************************************
22 *
23 * OriginType
24 *
25 ******************************************************************************/
26enum OriginType {
27 ORIGINTYPE_TOPLEFT,
28 ORIGINTYPE_CENTER,
29
30 ORIGINTYPE_MAX
31};
32
33namespace res {
34
35/******************************************************************************
36 *
37 * LYT1 binary layout
38 *
39 ******************************************************************************/
40struct Layout {
41 static const ulong SIGNATURE = 'lyt1';
42
43 DataBlockHeader blockHeader; // at 0x0
44 u8 originType; // at 0x8
45 u8 PADDING_0x9[0xC - 0x9]; // at 0x9
46 Size layoutSize; // at 0xC
47};
48
49} // namespace res
50
51/******************************************************************************
52 *
53 * Layout
54 *
55 ******************************************************************************/
56class Layout {
57public:
58 static const ulong SIGNATURE = 'RLYT';
59 static const ulong SIGNATURE_ANIMATION = 'RLAN';
60
61public:
62 Layout();
63 virtual ~Layout(); // at 0x8
64
65 virtual bool Build(const void* pLytBinary,
66 ResourceAccessor* pAccessor); // at 0xC
67
68 virtual AnimTransform* CreateAnimTransform(); // at 0x10
69 virtual AnimTransform*
70 CreateAnimTransform(const void* pAnmBinary,
71 ResourceAccessor* pAccessor); // at 0x14
72 virtual AnimTransform*
73 CreateAnimTransform(const nw4r::lyt::AnimResource&,
74 nw4r::lyt::ResourceAccessor*); // at 0x18
75
76 virtual void BindAnimation(AnimTransform* pAnimTrans); // at 0x1C
77 virtual void UnbindAnimation(AnimTransform* pAnimTrans); // at 0x20
78 virtual void UnbindAllAnimation(); // at 0x24
79 virtual bool BindAnimationAuto(const nw4r::lyt::AnimResource&,
80 nw4r::lyt::ResourceAccessor*); // at 0x28
81 virtual void SetAnimationEnable(AnimTransform* pAnimTrans,
82 bool enable); // at 0x2C
83
84 virtual void CalculateMtx(const DrawInfo& rInfo); // at 0x30
85 virtual void Draw(const DrawInfo& rInfo); // at 0x34
86 virtual void Animate(ulong option); // at 0x38
87
88 virtual void SetTagProcessor(ut::WideTagProcessor* pProcessor); // at 0x3C
89
90 ut::Rect GetLayoutRect() const;
91
92 Pane* GetRootPane() const {
93 return mpRootPane;
94 }
95
96 GroupContainer* GetGroupContainer() const {
97 return mpGroupContainer;
98 }
99
100 static MEMAllocator* GetAllocator() {
101 return mspAllocator;
102 }
103 static void SetAllocator(MEMAllocator* pAllocator) {
104 mspAllocator = pAllocator;
105 }
106
107 static void* AllocMemory(ulong size) {
108 return MEMAllocFromAllocator(mspAllocator, size);
109 }
110 static void FreeMemory(void* pBlock) {
111 MEMFreeToAllocator(mspAllocator, pBlock);
112 }
113
114protected:
115 static const ulong SIGNATURE_TEXTURELIST = 'txl1';
116 static const ulong SIGNATURE_FONTLIST = 'fnl1';
117 static const ulong SIGNATURE_MATERIALLIST = 'mat1';
118
119 static const ulong SIGNATURE_ANIMATIONINFO = 'pai1';
120
121 static const ulong SIGNATURE_PANESTART = 'pas1';
122 static const ulong SIGNATURE_PANEEND = 'pae1';
123
124 static const ulong SIGNATURE_GROUPSTART = 'grs1';
125 static const ulong SIGNATURE_GROUPEND = 'gre1';
126
127protected:
128 static Pane* BuildPaneObj(s32 kind, const void* pBinary,
129 const ResBlockSet& rBlockSet) DECOMP_DONT_INLINE;
130
131protected:
132 AnimTransformList mAnimTransList; // at 0x4
133 Pane* mpRootPane; // at 0x10
134 GroupContainer* mpGroupContainer; // at 0x14
135 Size mLayoutSize; // at 0x18
136
137 static MEMAllocator* mspAllocator;
138};
139
140/******************************************************************************
141 *
142 * Utility functions
143 *
144 ******************************************************************************/
145namespace {
146
147template <typename TObj> TObj* CreateObject() {
148 void* pBuffer = Layout::AllocMemory(sizeof(TObj));
149
150 if (pBuffer != NULL) {
151 return new (pBuffer) TObj();
152 }
153
154 return NULL;
155}
156
157template <typename TObj, typename TParam> TObj* CreateObject(TParam param) {
158 void* pBuffer = Layout::AllocMemory(sizeof(TObj));
159
160 if (pBuffer != NULL) {
161 return new (pBuffer) TObj(param);
162 }
163
164 return NULL;
165}
166
167template <typename TObj, typename TParam1, typename TParam2>
168TObj* CreateObject(TParam1 param1, TParam2 param2) {
169
170 void* pBuffer = Layout::AllocMemory(sizeof(TObj));
171
172 if (pBuffer != NULL) {
173 return new (pBuffer) TObj(param1, param2);
174 }
175
176 return NULL;
177}
178
179} // namespace
180} // namespace lyt
181} // namespace nw4r
182
183#endif
2D graphics drawing library.