Add Fade Effects for the Screens.

This commit is contained in:
StackZ
2020-05-26 07:07:55 +02:00
parent 796cc25007
commit f2f7c0c868
3 changed files with 55 additions and 6 deletions
+41 -3
View File
@@ -38,6 +38,10 @@ C2D_TextBuf TextBuf;
C2D_Font Font;
std::unique_ptr<Screen> usedScreen, tempScreen; // tempScreen used for "fade" effects.
bool currentScreen = false;
bool fadeout = false;
bool fadein = false;
int fadealpha = 0;
int fadecolor = 0;
// Clear Text.
void Gui::clearTextBufs(void) { C2D_TextBufClear(TextBuf); }
@@ -245,9 +249,15 @@ void Gui::DrawScreen() {
}
// Do the current screen's logic.
void Gui::ScreenLogic(u32 hDown, u32 hHeld, touchPosition touch) {
void Gui::ScreenLogic(u32 hDown, u32 hHeld, touchPosition touch, bool waitFade) {
if (waitFade) {
if (!fadein && !fadeout) {
if (usedScreen != nullptr) usedScreen->Logic(hDown, hHeld, touch);
}
} else {
if (usedScreen != nullptr) usedScreen->Logic(hDown, hHeld, touch);
}
}
// Calls the current screen's constructor.
void Gui::CallConstructor() {
@@ -260,10 +270,38 @@ void Gui::transferScreen() {
}
// Set the current Screen.
void Gui::setScreen(std::unique_ptr<Screen> screen, bool screenSwitch) {
void Gui::setScreen(std::unique_ptr<Screen> screen, bool fade) {
tempScreen = std::move(screen);
if (screenSwitch) {
// Switch screen without fade.
if (!fade) {
Gui::transferScreen();
} else {
// Fade, then switch.
fadeout = true;
}
}
// Fade's the screen in and out and transfer the screen.
// Credits goes to RocketRobz & SavvyManager.
void Gui::fadeEffects(int fadeoutFrames, int fadeinFrames) {
if (fadein) {
fadealpha -= fadeinFrames;
if (fadealpha < 0) {
fadealpha = 0;
fadecolor = 255;
fadein = false;
}
}
if (fadeout) {
fadealpha += fadeoutFrames;
if (fadealpha > 255) {
fadealpha = 255;
Gui::transferScreen(); // Transfer Temp screen to the used one.
Gui::CallConstructor(); // Here we call the constructor for the current screen.
fadein = true;
fadeout = false;
}
}
}
+9 -2
View File
@@ -139,8 +139,9 @@ namespace Gui {
* hDown: the hidKeysDown() variable.
* hHeld: the HidKeysHeld() variable.
* touch: The TouchPosition variable.
* waitFade: Wheter to wait until the fade ends.
*/
void ScreenLogic(u32 hDown, u32 hHeld, touchPosition touch);
void ScreenLogic(u32 hDown, u32 hHeld, touchPosition touch, bool waitFade = true);
/* Used for the current Screen's Constructor call. (Optional!)
* This is useful if you need to call the screen's constructor.
@@ -156,7 +157,13 @@ namespace Gui {
* screen: unique_ptr of the screen. (Optional by using the screen class.)
* screenSwitch: Wheter to switch to the current screen.
*/
void setScreen(std::unique_ptr<Screen> screen, bool screenSwitch = true);
void setScreen(std::unique_ptr<Screen> screen, bool fade = false);
/* Fades into screens and calls the constructor after it. (Optional!)
* fadeoutFrames: Amount of frames for fadeout.
* fadeinFrames: Amount of frames for fadein.
*/
void fadeEffects(int fadeoutFrames = 6, int fadeinFrames = 6);
/* Set on which screen to draw.
* screen: The render target. (Targets are inside the screenCommon.hpp file.)
+4
View File
@@ -33,5 +33,9 @@
extern C3D_RenderTarget* Top;
extern C3D_RenderTarget* TopRight;
extern C3D_RenderTarget* Bottom;
extern bool fadeout;
extern bool fadein;
extern int fadealpha;
extern int fadecolor;
#endif