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