NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
d_2d.cpp
1#include <game/bases/d_2d.hpp>
2#include <game/bases/d_game_com.hpp>
3#include <game/bases/d_font_manager.hpp>
4#include <game/mLib/m_allocator.hpp>
5#include <game/mLib/m_heap.hpp>
6#include <game/mLib/m_mtx.hpp>
7#include <constants/sjis_constants.h>
8
9mAllocator_c *d2d::ResAccMultLoader_c::ms_res_allocator;
10
11void d2d::init() {}
12
13void d2d::draw() {
14 m2d::draw();
15}
16
18 m2d::drawBefore(129);
19}
20
22 m2d::drawAfter(128);
23}
24
25void d2d::drawBtween(u8 after, u8 before) {
26 m2d::drawBtween(after, before);
27}
28
29DECL_WEAK
30void DUMMY_ORDERING() {
32}
33
35 u8 *pOpacity = (u8 *) opacity;
36 pane->SetAlpha(*pOpacity);
37 pane->SetGlbAlpha(*pOpacity);
38 return 0;
39}
40
41void d2d::setAlpha(m2d::Simple_c *layout, u8 opacity) {
42 layout->patrolPane(setAlpha_patrolPane_patrol, nullptr, &opacity);
43}
44
45d2d::ResAccMult_c::ResAccMult_c() {
46 creater();
47}
48
49d2d::ResAccMult_c::~ResAccMult_c() {
50}
51
52void *d2d::ResAccMult_c::getResource(unsigned long type, const char *name) {
53 return mInternalAccessor.GetResource(type, name, nullptr);
54}
55
56void d2d::ResAccMult_c::creater() {
57 setResAccessor(&mInternalAccessor);
58}
59
60void *d2d::ResAccMult_c::InternalAccessor::GetResource(ulong type, const char *name, size_t *size) {
61 if (type == RES_TYPE_FONT) {
62 return dFontMng_c::getResFontData(name);
63 }
64 return nw4r::lyt::ArcResourceAccessor::GetResource(type, name, size);
65}
66
67nw4r::ut::Font *d2d::ResAccMult_c::InternalAccessor::GetFont(const char *name) {
68 return dFontMng_c::getFont(dFontMng_c::getResFontIndex(name));
69}
70
71d2d::ResAccMultLoader_c::ResAccMultLoader_c() : mpResource(nullptr) {}
72d2d::ResAccMultLoader_c::~ResAccMultLoader_c() {}
73
74bool d2d::ResAccMultLoader_c::requestEx(const char *name, int i) {
75 if (mpResource != nullptr) {
76 return true;
77 }
78 mpResource = mLoader.request(name, i, ms_res_allocator->mpHeap);
79 if (mpResource != nullptr) {
80 attach(mpResource, "arc");
81 return true;
82 } else {
83 return false;
84 }
85}
86
87bool d2d::ResAccMultLoader_c::request(const char *name) {
88 return requestEx(name, 0);
89}
90
91bool d2d::ResAccMultLoader_c::remove() {
92 if (mpResource != nullptr) {
93 detach();
94 ms_res_allocator->free(mpResource);
95 mpResource = nullptr;
96 }
97 return mLoader.remove();
98}
99
100bool d2d::ResAccMultLoader_c::create(EGG::Heap *parent, ulong size) {
101 EGG::Heap *heap = mHeap::createExpHeap(size, parent, D2D_HEAP_NAME, 0x20, mHeap::OPT_4);
102 ms_res_allocator = new(heap, 4) mAllocator_c();
103 ms_res_allocator->attach(heap, 0x20);
104 return true;
105}
106
108 mpResAccessor = nullptr;
109 mPos.x = 0.0f;
110 mPos.y = 0.0f;
111 mFlags = 0;
112 if (dGameCom::GetAspectRatio() == EGG::Screen::TV_MODE_16_9) {
113 mDrawInfo.SetLocationAdjustScale(mVec2_c(19.0f / 26.0f, 1.0f));
114 mDrawInfo.SetLocationAdjust(true);
115 }
116 mScissorMask.mEnabled = false;
117}
118
120
122 m2d::Base_c::entry();
123}
124
126 calcBefore();
127 mMtx_c mtx;
128 PSMTXIdentity(mtx);
129 mVec3_c pos(mPos.x, mPos.y, 0.0f);
130 PSMTXTransApply(mtx, mtx, pos.x, pos.y, pos.z);
131 mDrawInfo.SetViewMtx(mtx);
132 calcAfter();
133}
134
136 ulong option = 0;
137 if (mFlags & 1) {
138 option = 1;
139 }
140 mLayout.Animate(option);
141}
142
144 mDrawInfo.SetViewRect(mLayout.GetLayoutRect());
145 mLayout.CalculateMtx(mDrawInfo);
146}
147
149 nw4r::ut::Rect rect = mLayout.GetLayoutRect();
150 float near = 0.0f;
151 float far = 500.0f;
152 EGG::Screen screen;
153 bool isWide = dGameCom::GetAspectRatio() == EGG::Screen::TV_MODE_16_9;
154 float w_16_9 = EGG::Screen::sTVModeInfo[EGG::Screen::TV_MODE_16_9].width;
155 float w_4_3 = EGG::Screen::sTVModeInfo[EGG::Screen::TV_MODE_4_3].width;
156 float left = isWide ? w_16_9 * rect.left / w_4_3 : rect.left;
157 float right = isWide ? w_16_9 * rect.right / w_4_3 : rect.right;
158 screen.mProjType = EGG::Frustum::PROJ_ORTHO;
159 screen.ResetOrthographic(rect.top, rect.bottom, left, right, near, far);
160 if (isWide) {
161 screen.mScale = nw4r::math::VEC3(w_4_3 / w_16_9, 1.0f, 1.0f);
162 }
163 screen.SetProjectionGX();
164 if (mScissorMask.mEnabled) {
165 u32 x, y, w, h;
166 GXGetScissor(&x, &y, &w, &h);
167 GXSetScissor(
168 mScissorMask.mPos.x, mScissorMask.mPos.y,
169 mScissorMask.mSize.x, mScissorMask.mSize.y
170 );
171 mLayout.Draw(mDrawInfo);
172 GXSetScissor(x, y, w, h);
173 } else {
174 mLayout.Draw(mDrawInfo);
175 }
176}
177
179 return mLayout.GetRootPane();
180}
181
182bool d2d::Multi_c::build(const char *name, ResAccMult_c *resAcc) {
183 if (mLayout.GetRootPane() != nullptr) {
184 return true;
185 }
186 if (resAcc == nullptr) {
187 resAcc = mpResAccessor;
188 if (resAcc == nullptr) {
189 return false;
190 }
191 }
192 void *lyt = resAcc->getResource(0, name);
193 if (lyt == nullptr) {
194 return false;
195 }
196 bool res = mLayout.Build(lyt, &resAcc->mInternalAccessor);
197 if (res) {
198 calc();
199 }
200 return res;
201}
202
204 return mLayout.GetRootPane()->FindPaneByName(name, true);
205}
206
208 nw4r::lyt::Pane *pane = findPaneByName(name);
209 if (pane != nullptr) {
210 nw4r::lyt::TextBox *box = nw4r::ut::DynamicCast<nw4r::lyt::TextBox *>(pane);
211 return box;
212 }
213 return nullptr;
214}
215
217 nw4r::lyt::Pane *pane = findPaneByName(name);
218 if (pane != nullptr) {
219 nw4r::lyt::Picture *picture = nw4r::ut::DynamicCast<nw4r::lyt::Picture *>(pane);
220 return picture;
221 }
222 return nullptr;
223}
224
226 nw4r::lyt::Pane *pane = findPaneByName(name);
227 if (pane != nullptr) {
228 nw4r::lyt::Window *window = nw4r::ut::DynamicCast<nw4r::lyt::Window *>(pane);
229 return window;
230 }
231 return nullptr;
232}
virtual ~Multi_c()
Destroys the layout.
Definition d_2d.cpp:119
void calcAfter()
Calculates the view rectangle and view matrix after the main calculation.
Definition d_2d.cpp:143
m2d::Layout_c mLayout
The layout instance.
Definition multi.hpp:48
ScissorMask mScissorMask
The scissor mask for the layout.
Definition multi.hpp:55
virtual void draw()
Draws the layout.
Definition d_2d.cpp:148
void entry()
Registers the layout to be drawn.
Definition d_2d.cpp:121
nw4r::lyt::Picture * findPictureByName(const char *name)
Finds a picture pane by name.
Definition d_2d.cpp:216
virtual void calc()
Applies the view matrix.
Definition d_2d.cpp:125
nw4r::lyt::DrawInfo mDrawInfo
The parameters for drawing the layout.
Definition multi.hpp:49
u32 mFlags
The flags for the layout.
Definition multi.hpp:58
nw4r::lyt::TextBox * findTextBoxByName(const char *name)
Finds a text box pane by name.
Definition d_2d.cpp:207
nw4r::lyt::Pane * getRootPane()
Gets the root pane of the layout.
Definition d_2d.cpp:178
ResAccMult_c * mpResAccessor
The resource accessor for the layout.
Definition multi.hpp:52
void calcBefore()
Calculates an animation step before the main calculation.
Definition d_2d.cpp:135
nw4r::lyt::Pane * findPaneByName(const char *name)
Finds a pane by name.
Definition d_2d.cpp:203
Multi_c()
Creates a layout.
Definition d_2d.cpp:107
virtual bool build(const char *name, ResAccMult_c *resAcc)
Builds the layout from a binary layout file.
Definition d_2d.cpp:182
mVec2_c mPos
The position of the layout.
Definition multi.hpp:53
nw4r::lyt::Window * findWindowByName(const char *name)
Finds a window pane by name.
Definition d_2d.cpp:225
An allocator class that wraps an EGG:Allocator .
A 3x4 matrix.
Definition m_mtx.hpp:9
A two-dimensional floating point vector.
Definition m_vec.hpp:9
A three-dimensional floating point vector.
Definition m_vec.hpp:100
void drawAfter()
Draws all registered foreground 2D objects.
Definition d_2d.cpp:21
void drawBefore()
Draws all registered background 2D objects.
Definition d_2d.cpp:17
void init()
Initializes the 2D engine.
Definition d_2d.cpp:11
void draw()
Draws all registered 2D objects.
Definition d_2d.cpp:13
void drawBtween(u8 after, u8 before)
Draws all registered 2D objects between the after and before draw orders.
Definition d_2d.cpp:25
int setAlpha_patrolPane_patrol(nw4r::lyt::Pane *pane, void *opacity)
Visitor function for setting the opacity of panes.
Definition d_2d.cpp:34
void setAlpha(m2d::Simple_c *layout, u8 opacity)
Sets the opacity of an entire layout.
Definition d_2d.cpp:41