1#include <lib/egg/fader/eggColorFader.hpp>
2#include <lib/rvl/gx/GX.h>
4EGG::ColorFader::ColorFader(
float x,
float y,
float w,
float h,
nw4r::ut::Color color, Fader::EStatus initialStatus) :
14 setStatus(initialStatus);
18void EGG::ColorFader::setFrame(u16 frames) {
23 mCurrColor.r = color.r;
24 mCurrColor.g = color.g;
25 mCurrColor.b = color.b;
30 if (status == Fader::OPAQUE) {
31 mStatus = Fader::OPAQUE;
33 }
else if (status == Fader::HIDDEN) {
34 mStatus = Fader::HIDDEN;
40 bool doFadeIn = mStatus == Fader::OPAQUE;
42 mStatus = Fader::FADE_IN;
50 bool doFadeIn = mStatus == Fader::HIDDEN;
52 mStatus = Fader::FADE_OUT;
62 if (mStatus == Fader::HIDDEN) {
64 }
else if (mStatus == Fader::OPAQUE) {
66 }
else if (mStatus == Fader::FADE_IN) {
67 u16 currFrame = mFrame;
68 u16 endFrame = mFrameCount;
70 if (currFrame > endFrame) {
71 mStatus = Fader::HIDDEN;
72 result = (mFlag & ColorFader::FLAG_1) != 0;
75 mCurrColor.a = 255 - (currFrame * 255 / mFrameCount);
76 }
else if (mStatus == Fader::FADE_OUT) {
77 u16 endFrame = mFrameCount;
78 u16 currFrame = mFrame;
80 if (currFrame > endFrame) {
81 if (currFrame > endFrame + 1) {
82 mStatus = Fader::OPAQUE;
83 result = (mFlag & ColorFader::FLAG_2) != 0;
85 endFrame = mFrameCount;
88 mCurrColor.a = currFrame * 255 / endFrame;
95 if (mCurrColor.a == 0) {
100 C_MTXOrtho(&projMtx, mTop, mBottom, mLeft, mRight, 0, 1);
101 GXSetProjection(&projMtx, 1);
103 GXSetViewport(mLeft, mTop, getWidth(), getHeight(), 0, 1);
104 GXSetScissor(mLeft, mTop, getWidth(), getHeight());
108 GXLoadPosMtxImm(&posMtx, 0);
112 GXInvalidateVtxCache();
114 GXSetVtxDesc(GX_VA_POS, GX_VA_TEX0MTXIDX);
115 GXSetVtxAttrFmt(0, GX_VA_POS, 1, 4, 0);
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);
122 GXSetNumIndStages(0);
123 __GXSetIndirectMask(0);
125 GXSetNumTevStages(1);
126 GXSetTevOp(GX_TEVSTAGE0, 4);
127 GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0);
129 if (mCurrColor.a == 255) {
130 GXSetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ZERO, GX_LO_SET);
132 GXSetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_SET);
137 GXSetZMode(0, GX_NEVER, 0);
140 GXBegin(GX_QUADS, GX_VTXFMT0, 4);
142 GXPosition3f32(mLeft, mTop, 0.0f);
143 GXPosition3f32(mRight, mTop, 0.0f);
144 GXPosition3f32(mRight, mBottom, 0.0f);
145 GXPosition3f32(mLeft, mBottom, 0.0f);
150EGG::ColorFader::~ColorFader() {
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.
float Mtx44[4][4]
A 4x4 matrix.
float Mtx[3][4]
A 3x4 matrix.
void PSMTXIdentity(Mtx *mtx)
Sets the given matrix to the identity matrix.