From 1ff3ba6534f0aad082d82f5fa22aeb805bd7104b Mon Sep 17 00:00:00 2001 From: StackZ <47382115+SuperSaiyajinStackZ@users.noreply.github.com> Date: Thu, 14 Jan 2021 16:18:07 +0100 Subject: [PATCH] Some more screen class things. --- include/graphics.hpp | 25 +++++++++++++++++++++++++ include/screen.hpp | 2 +- source/graphics.cpp | 21 +++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/include/graphics.hpp b/include/graphics.hpp index 80e7ec6..42d1334 100644 --- a/include/graphics.hpp +++ b/include/graphics.hpp @@ -29,6 +29,7 @@ #include "font.hpp" #include "image.hpp" +#include "screen.hpp" #include "sprite.hpp" #include @@ -83,6 +84,30 @@ namespace Graphics { * @param layer The layer to draw to */ void drawRectangle(int x, int y, int w, int h, u8 color1, u8 color2, bool top, bool layer); + + /** + * @brief Draws the setted screen + */ + void drawScreen(); + + /** + * @brief The current screen logic + * @param hDown The keysDown variable + * @param hHeld The keysHeld variable + * @param touch The TouchPosition variable + */ + void screenLogic(u32 hDown, u32 hHeld, touchPosition touch); + + /** + * @brief Set a specific Screen with the Screen class + * @param screen The screen which to set + */ + void setScreen(std::unique_ptr screen); + + /** + * @brief Goes a screen back + */ + void screenBack(); } #endif \ No newline at end of file diff --git a/include/screen.hpp b/include/screen.hpp index 65b05ff..e60e085 100644 --- a/include/screen.hpp +++ b/include/screen.hpp @@ -28,7 +28,7 @@ #define _UNIVERSAL_CORE_SCREEN_HPP #include -#include +#include class Screen { public: diff --git a/source/graphics.cpp b/source/graphics.cpp index 271bda0..eec6c9d 100644 --- a/source/graphics.cpp +++ b/source/graphics.cpp @@ -29,9 +29,11 @@ #include "tonccpy.h" #include +#include int Graphics::bg3Main, Graphics::bg2Main, Graphics::bg3Sub, Graphics::bg2Sub; bool Graphics::wideScreen = false; +static std::stack> screens; void Graphics::init(void) { // Initialize video mode @@ -89,3 +91,22 @@ void Graphics::drawRectangle(int x, int y, int w, int h, u8 color1, u8 color2, b toncset(dst + ((y + i) * 256 + x), ((i % 2) ? color1 : color2), w); } } + +void Graphics::drawScreen() { + if (!screens.empty()) + screens.top()->Draw(); +} + +void Graphics::screenLogic(u32 hDown, u32 hHeld, touchPosition touch) { + if (!screens.empty()) + screens.top()->Logic(hDown, hHeld, touch); +} + +void Graphics::setScreen(std::unique_ptr screen) { + screens.push(std::move(screen)); +} + +void Graphics::screenBack() { + if (screens.size() > 0) + screens.pop(); +} \ No newline at end of file