Major Screen changes. (If using the screen class, read the description!!)

Changes which are needed when using the screen class:

- Add `void callConstructor() override { }` to your screen's public header.
- Call `Gui::DrawScreen();` to draw the screen.
- Call `Gui::ScreenLogic(u32 hDown, u32 hHeld, touchPosition touch);` to call the Logic.
- Call `Gui::CallConstructor();` to call the used screen's constructor.
- call `Gui::setScreen(std::make_unique<ScreenName>(), <true/ false, depends if you like to transfer the screen to the usedScreen directly.>);` to set the screen.
- Call `Gui::transferScreen();` in case you like to set the tempScreen to the used one.
- Get rid of the `Gui::screenBack();` calls and use `Gui::setScreen(...)` directly for it.
This commit is contained in:
StackZ
2020-05-26 05:25:33 +02:00
parent f0dca7c784
commit a5f7134d1c
6 changed files with 55 additions and 31 deletions
+5
View File
@@ -0,0 +1,5 @@
{
"files.associations": {
"string": "cpp"
}
}
+27 -12
View File
@@ -36,7 +36,7 @@ C3D_RenderTarget* Bottom;
C2D_TextBuf TextBuf;
C2D_Font Font;
std::stack<std::unique_ptr<Screen>> screens;
std::unique_ptr<Screen> usedScreen, tempScreen; // tempScreen used for "fade" effects.
bool currentScreen = false;
// Clear Text.
@@ -97,6 +97,7 @@ void Gui::exit(void) {
C2D_TextBufDelete(TextBuf);
C2D_Fini();
C3D_Fini();
usedScreen = nullptr;
}
// Draw a Centered String.
@@ -238,24 +239,38 @@ bool Gui::Draw_Rect(float x, float y, float w, float h, u32 color) {
return C2D_DrawRectSolid(x, y, 0.5f, w, h, color);
}
// Mainloop the GUI.
void Gui::mainLoop(u32 hDown, u32 hHeld, touchPosition touch) {
if (!screens.empty()) {
screens.top()->Draw();
screens.top()->Logic(hDown, hHeld, touch);
}
// Draw's the current screen's draw.
void Gui::DrawScreen() {
if (usedScreen != nullptr) usedScreen->Draw();
}
// Do the current screen's logic.
void Gui::ScreenLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if (usedScreen != nullptr) usedScreen->Logic(hDown, hHeld, touch);
}
// Calls the current screen's constructor.
void Gui::CallConstructor() {
if (usedScreen != nullptr) usedScreen->callConstructor();
}
// Move's the tempScreen to the used one.
void Gui::transferScreen() {
if (tempScreen != nullptr) usedScreen = std::move(tempScreen);
}
// Set the current Screen.
void Gui::setScreen(std::unique_ptr<Screen> screen) { screens.push(std::move(screen)); }
// Go a Screen back.
void Gui::screenBack() { if (screens.size() > 0) screens.pop(); }
void Gui::setScreen(std::unique_ptr<Screen> screen, bool screenSwitch) {
tempScreen = std::move(screen);
if (screenSwitch) {
Gui::transferScreen();
}
}
// Select, on which Screen should be drawn.
void Gui::ScreenDraw(C3D_RenderTarget * screen) {
C2D_SceneBegin(screen);
currentScreen = (screen==Top || screen==TopRight) ? 1 : 0;
currentScreen = (screen == Top || screen == TopRight) ? 1 : 0;
}
void Gui::drawGrid(float xPos, float yPos, float Width, float Height, u32 color) {
+19 -10
View File
@@ -32,10 +32,8 @@
#include <3ds.h>
#include <citro2d.h>
#include <citro3d.h>
#include <stack>
namespace Gui
{
namespace Gui {
// Clear the Text Buffer.
void clearTextBufs(void);
@@ -134,20 +132,31 @@ namespace Gui
*/
bool Draw_Rect(float x, float y, float w, float h, u32 color);
/* Used for the mainLoop to display the screens. (Optional!)
// Used for the current Screen's Draw. (Optional!)
void DrawScreen();
/* Used for the current Screen's Logic. (Optional!)
* hDown: the hidKeysDown() variable.
* hHeld: the HidKeysHeld() variable.
* touch: The TouchPosition variable.
*/
void mainLoop(u32 hDown, u32 hHeld, touchPosition touch);
void ScreenLogic(u32 hDown, u32 hHeld, touchPosition touch);
/* Set a specific Screen.
* screen: unique_ptr of the screen. (Optional by using the screen class.)
/* Used for the current Screen's Constructor call. (Optional!)
* This is useful if you need to call the screen's constructor.
*/
void setScreen(std::unique_ptr<Screen> screen);
void CallConstructor();
// Go a Screen back. (Optional by using the screen class.)
void screenBack();
/* Transfer the Temp Screen to the used one. (Optional!)
* It will check, if the tempScreen variable is not nullptr, so don't worry.
*/
void transferScreen();
/* 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.
*/
void setScreen(std::unique_ptr<Screen> screen, bool screenSwitch = true);
/* Set on which screen to draw.
* screen: The render target. (Targets are inside the screenCommon.hpp file.)
+1 -2
View File
@@ -29,8 +29,7 @@
#include <cstddef>
class HID
{
class HID {
public:
/* The parameters to initialize this class.
+2 -3
View File
@@ -30,13 +30,12 @@
#include <3ds.h>
#include <memory>
class Screen
{
class Screen {
public:
virtual ~Screen() {}
virtual void Logic(u32 hDown, u32 hHeld, touchPosition touch) = 0;
virtual void Draw() const = 0;
private:
virtual void callConstructor() = 0;
};
#endif
+1 -4
View File
@@ -29,8 +29,7 @@
#include <string>
class Structs
{
class Structs {
public:
struct ButtonPos {
int x;
@@ -45,8 +44,6 @@ public:
int y;
int w;
};
private:
};
#endif