Optional: Add stack of screens.

Use this if you're relying on the screens from before.
This commit is contained in:
StackZ
2020-05-27 13:25:38 +02:00
parent 95b3161f30
commit d0d78f2bfb
3 changed files with 80 additions and 24 deletions
+60 -10
View File
@@ -28,6 +28,7 @@
#include "screenCommon.hpp"
#include <3ds.h>
#include <stack>
#include <unistd.h>
C3D_RenderTarget* Top;
@@ -37,9 +38,9 @@ C3D_RenderTarget* Bottom;
C2D_TextBuf TextBuf;
C2D_Font Font;
std::unique_ptr<Screen> usedScreen, tempScreen; // tempScreen used for "fade" effects.
std::stack<std::unique_ptr<Screen>> 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() {
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 (!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 (!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() {
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> screen, bool fade) {
void Gui::setScreen(std::unique_ptr<Screen> 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> 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,16 +305,49 @@ 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) {
+13 -5
View File
@@ -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!)
* 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> screen, bool fade = false);
void setScreen(std::unique_ptr<Screen> 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.)
+2 -4
View File
@@ -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