diff --git a/gui.cpp b/gui.cpp index 46bb921..7674506 100644 --- a/gui.cpp +++ b/gui.cpp @@ -38,6 +38,10 @@ C2D_TextBuf TextBuf; C2D_Font Font; std::unique_ptr 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,8 +249,14 @@ void Gui::DrawScreen() { } // Do the current screen's logic. -void Gui::ScreenLogic(u32 hDown, u32 hHeld, touchPosition touch) { - if (usedScreen != nullptr) usedScreen->Logic(hDown, hHeld, 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. @@ -260,10 +270,38 @@ void Gui::transferScreen() { } // Set the current Screen. -void Gui::setScreen(std::unique_ptr screen, bool screenSwitch) { +void Gui::setScreen(std::unique_ptr 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; + } } } diff --git a/gui.hpp b/gui.hpp index f9f6569..bc6b9e0 100644 --- a/gui.hpp +++ b/gui.hpp @@ -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, bool screenSwitch = true); + void setScreen(std::unique_ptr 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.) diff --git a/screenCommon.hpp b/screenCommon.hpp index c95940d..827171c 100644 --- a/screenCommon.hpp +++ b/screenCommon.hpp @@ -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 \ No newline at end of file