NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
eggColorFader.cpp
1#include <lib/egg/core/eggColorFader.h>
2
3#include <lib/rvl/gx/GX.h>
4
5namespace EGG {
6
7ColorFader::ColorFader(float x, float y, float w, float h, nw4r::ut::Color color,
8 Fader::EStatus initialStatus)
9 : mFlag(),
10 mFrameCount(20),
11 mFrame(0),
12 mCurrColor(),
13 mDims(x, y, x + w, y + h) {
14 setColor(color);
15 setStatus(initialStatus);
16 mFlag.setBit(ColorFader::SIGNAL_ON_FADE_OUT);
17}
18
19void ColorFader::setFrame(u16 frame) {
20 EGG_ASSERT(frame != 0);
21 mFrameCount = frame;
22}
23
24void ColorFader::setColor(nw4r::ut::Color color) {
25 mCurrColor.r = color.r;
26 mCurrColor.g = color.g;
27 mCurrColor.b = color.b;
28 // Don't set alpha
29}
30
31void ColorFader::setStatus(Fader::EStatus status) {
32 if (status == Fader::OPAQUE) {
33 mStatus = Fader::OPAQUE;
34 mCurrColor.a = 255;
35 } else if (status == Fader::HIDDEN) {
36 mStatus = Fader::HIDDEN;
37 mCurrColor.a = 0;
38 }
39}
40
42 bool start = mStatus == Fader::OPAQUE;
43 if (start) {
44 mStatus = Fader::FADE_IN;
45 mFrame = 0;
46 }
47
48 return start;
49}
50
52 bool start = mStatus == Fader::HIDDEN;
53 if (start) {
54 mStatus = Fader::FADE_OUT;
55 mFrame = 0;
56 }
57
58 return start;
59}
60
62 bool result = false;
63
64 if (mStatus == Fader::HIDDEN) {
65 mCurrColor.a = 0;
66 } else if (mStatus == Fader::OPAQUE) {
67 mCurrColor.a = 255;
68 } else if (mStatus == Fader::FADE_IN) {
69 u16 endFrame = mFrameCount;
70 u16 currFrame = mFrame++;
71
72 if (currFrame > endFrame) {
73 mStatus = Fader::HIDDEN;
74 result = mFlag.onBit(ColorFader::SIGNAL_ON_FADE_IN);
75 currFrame = endFrame;
76 }
77
78 mCurrColor.a = 255 - (currFrame * 255 / mFrameCount);
79 } else if (mStatus == Fader::FADE_OUT) {
80 u16 endFrame = mFrameCount;
81 u16 currFrame = mFrame++;
82
83 if (currFrame > endFrame) {
84 if (currFrame > endFrame + 1) {
85 mStatus = Fader::OPAQUE;
86 result = mFlag.onBit(ColorFader::SIGNAL_ON_FADE_OUT);
87 }
88
89 endFrame = mFrameCount;
90 currFrame = endFrame;
91 }
92
93 mCurrColor.a = currFrame * 255 / endFrame;
94 }
95
96 return result;
97}
98
100 if (mCurrColor.a == 0) {
101 return;
102 }
103
104 Mtx44 projMtx;
105 C_MTXOrtho(&projMtx, mDims.top, mDims.bottom, mDims.left, mDims.right, 0.0f, 1.0f);
106 GXSetProjection(&projMtx, GX_ORTHOGRAPHIC);
107
108 GXSetViewport(mDims.left, mDims.top, mDims.GetWidth(), mDims.GetHeight(), 0.0f, 1.0f);
109 GXSetScissor(mDims.left, mDims.top, mDims.GetWidth(), mDims.GetHeight());
110
111 Mtx posMtx;
112 PSMTXIdentity(&posMtx);
113 GXLoadPosMtxImm(&posMtx, 0);
114 GXSetCurrentMtx(0);
115
116 GXClearVtxDesc();
117 GXInvalidateVtxCache();
118
119 GXSetVtxDesc(GX_VA_POS, GX_VA_TEX0MTXIDX);
120 GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
121
122 GXSetNumChans(1);
123 GXSetChanMatColor(GX_COLOR0A0, mCurrColor);
124 GXSetChanCtrl(GX_COLOR0A0, 0, GX_SRC_REG, GX_SRC_REG, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE);
125
126 GXSetNumTexGens(0);
127 GXSetNumIndStages(0);
128 __GXSetIndirectMask(0);
129
130 GXSetNumTevStages(1);
131 GXSetTevOp(GX_TEVSTAGE0, 4);
132 GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0);
133
134 if (mCurrColor.a == 255) {
135 GXSetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_SET);
136 } else {
137 GXSetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_SET);
138 }
139
140 GXSetColorUpdate(1);
141 GXSetAlphaUpdate(1);
142 GXSetZMode(0, GX_NEVER, 0);
143 GXSetCullMode(2);
144
145 GXBegin(GX_QUADS, GX_VTXFMT0, 4);
146
147 GXPosition3f32(mDims.left, mDims.top, 0.0f);
148 GXPosition3f32(mDims.right, mDims.top, 0.0f);
149 GXPosition3f32(mDims.right, mDims.bottom, 0.0f);
150 GXPosition3f32(mDims.left, mDims.bottom, 0.0f);
151
152 GXEnd();
153}
154
155} // namespace EGG
virtual void draw()
Calculates the fader at the current frame.
virtual bool calc()
Initiates a fade out from no-obstruction.
virtual bool fadeOut()
Initiates a fade in from pure blacked-out.
virtual bool fadeIn()
Gets the fader's status.
EStatus
The fader's status.
Definition eggFader.h:11
float Mtx44[4][4]
A 4x4 matrix.
Definition mtx.h:13
float Mtx[3][4]
A 3x4 matrix.
Definition mtx.h:12
void PSMTXIdentity(Mtx *mtx)
Sets the given matrix to the identity matrix.
A 32-bit RGBA color.
Definition Color.h:8