diff --git a/gui.cpp b/gui.cpp index 8f7caf2..5c3912a 100644 --- a/gui.cpp +++ b/gui.cpp @@ -28,6 +28,7 @@ #include "screenCommon.hpp" #include <3ds.h> +#include #include C3D_RenderTarget* Top; @@ -37,9 +38,9 @@ C3D_RenderTarget* Bottom; C2D_TextBuf TextBuf; C2D_Font Font; std::unique_ptr usedScreen, tempScreen; // tempScreen used for "fade" effects. +std::stack> screens; bool currentScreen = false; -bool fadeout = false; -bool fadein = false; +bool fadeout = false, fadein = false, fadeout2 = false, fadein2 = false; int fadealpha = 0; int fadecolor = 0; @@ -244,32 +245,48 @@ bool Gui::Draw_Rect(float x, float y, float w, float h, u32 color) { } // Draw's the current screen's draw. -void Gui::DrawScreen() { - if (usedScreen != nullptr) usedScreen->Draw(); +void Gui::DrawScreen(bool stack) { + if (!stack) { + if (usedScreen != nullptr) usedScreen->Draw(); + } else { + if (!screens.empty()) screens.top()->Draw(); + } } // Do the current screen's logic. -void Gui::ScreenLogic(u32 hDown, u32 hHeld, touchPosition touch, bool waitFade) { +void Gui::ScreenLogic(u32 hDown, u32 hHeld, touchPosition touch, bool waitFade, bool stack) { if (waitFade) { - if (!fadein && !fadeout) { - if (usedScreen != nullptr) usedScreen->Logic(hDown, hHeld, touch); + if (!fadein && !fadeout && !fadein2 && !fadeout2) { + if (!stack) { + if (usedScreen != nullptr) usedScreen->Logic(hDown, hHeld, touch); + } else { + if (!screens.empty()) screens.top()->Logic(hDown, hHeld, touch); + } } } else { - if (usedScreen != nullptr) usedScreen->Logic(hDown, hHeld, touch); + if (!stack) { + if (usedScreen != nullptr) usedScreen->Logic(hDown, hHeld, touch); + } else { + if (!screens.empty()) screens.top()->Logic(hDown, hHeld, touch); + } } } // Move's the tempScreen to the used one. -void Gui::transferScreen() { - if (tempScreen != nullptr) usedScreen = std::move(tempScreen); +void Gui::transferScreen(bool stack) { + if (!stack) { + if (tempScreen != nullptr) usedScreen = std::move(tempScreen); + } else { + if (tempScreen != nullptr) screens.push(std::move(tempScreen)); + } } // Set the current Screen. -void Gui::setScreen(std::unique_ptr screen, bool fade) { +void Gui::setScreen(std::unique_ptr screen, bool fade, bool stack) { tempScreen = std::move(screen); // Switch screen without fade. if (!fade) { - Gui::transferScreen(); + Gui::transferScreen(stack); } else { // Fade, then switch. fadeout = true; @@ -278,7 +295,7 @@ void Gui::setScreen(std::unique_ptr screen, bool fade) { // Fade's the screen in and out and transfer the screen. // Credits goes to RocketRobz & SavvyManager. -void Gui::fadeEffects(int fadeoutFrames, int fadeinFrames) { +void Gui::fadeEffects(int fadeoutFrames, int fadeinFrames, bool stack) { if (fadein) { fadealpha -= fadeinFrames; if (fadealpha < 0) { @@ -288,17 +305,50 @@ void Gui::fadeEffects(int fadeoutFrames, int fadeinFrames) { } } + if (stack) { + if (fadein2) { + fadealpha -= fadeinFrames; + if (fadealpha < 0) { + fadealpha = 0; + fadecolor = 255; + fadein2 = false; + } + } + } + if (fadeout) { fadealpha += fadeoutFrames; if (fadealpha > 255) { fadealpha = 255; - Gui::transferScreen(); // Transfer Temp screen to the used one. + Gui::transferScreen(stack); // Transfer Temp screen to the stack / used one. fadein = true; fadeout = false; } } + + if (stack) { + if (fadeout2) { + fadealpha += fadeoutFrames; + if (fadealpha > 255) { + fadealpha = 255; + Gui::screenBack2(); // Go screen back. + fadein2 = true; + fadeout2 = false; + } + } + } } +// Go a screen back. (Stack only!) +void Gui::screenBack(bool fade) { + if (!fade) { + if (screens.size() > 0) screens.pop(); + } else { + if (screens.size() > 0) fadeout2 = true; + } +} +void Gui::screenBack2() { if (screens.size() > 0) screens.pop(); } + // Select, on which Screen should be drawn. void Gui::ScreenDraw(C3D_RenderTarget * screen) { C2D_SceneBegin(screen); diff --git a/gui.hpp b/gui.hpp index 319dc4f..77d216a 100644 --- a/gui.hpp +++ b/gui.hpp @@ -133,32 +133,40 @@ namespace Gui { bool Draw_Rect(float x, float y, float w, float h, u32 color); // Used for the current Screen's Draw. (Optional!) - void DrawScreen(); + // stack: Is it the stack variant? + void DrawScreen(bool stack = false); /* Used for the current Screen's Logic. (Optional!) * hDown: the hidKeysDown() variable. * hHeld: the HidKeysHeld() variable. * touch: The TouchPosition variable. * waitFade: Wheter to wait until the fade ends. + * stack: Is it the stack variant? */ - void ScreenLogic(u32 hDown, u32 hHeld, touchPosition touch, bool waitFade = true); + void ScreenLogic(u32 hDown, u32 hHeld, touchPosition touch, bool waitFade = true, bool stack = false); - /* Transfer the Temp Screen to the used one. (Optional!) + /* Transfer the Temp Screen to the used one. (Optional!) + * stack: Is it the stack variant? * It will check, if the tempScreen variable is not nullptr, so don't worry. */ - void transferScreen(); + void transferScreen(bool stack = false); /* Set a specific Screen with switch function. (Optional!) * screen: unique_ptr of the screen. (Optional by using the screen class.) * screenSwitch: Wheter to switch to the current screen. + * stack: Is it the stack variant? */ - void setScreen(std::unique_ptr screen, bool fade = false); + void setScreen(std::unique_ptr screen, bool fade = false, bool stack = false); /* Fades into screens and calls the constructor after it. (Optional!) * fadeoutFrames: Amount of frames for fadeout. * fadeinFrames: Amount of frames for fadein. + * stack: Is it the stack variant? */ - void fadeEffects(int fadeoutFrames = 6, int fadeinFrames = 6); + void fadeEffects(int fadeoutFrames = 6, int fadeinFrames = 6, bool stack = false); + + void screenBack(bool fade = false); // Goes a screen back. (Set!) (Stack only!) + void screenBack2(); // Goes a screen back.(Action!) (Stack only!) /* 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 827171c..3c6ecd1 100644 --- a/screenCommon.hpp +++ b/screenCommon.hpp @@ -33,9 +33,7 @@ extern C3D_RenderTarget* Top; extern C3D_RenderTarget* TopRight; extern C3D_RenderTarget* Bottom; -extern bool fadeout; -extern bool fadein; -extern int fadealpha; -extern int fadecolor; +extern bool fadeout, fadein, fadeout2, fadein2; +extern int fadealpha, fadecolor; #endif \ No newline at end of file