Move screen stuff into screen.cpp.

This commit is contained in:
StackZ
2021-01-15 15:46:28 +01:00
parent 98ab68f00d
commit 3fa981f04b
4 changed files with 73 additions and 43 deletions
-24
View File
@@ -84,30 +84,6 @@ 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> screen);
/**
* @brief Goes a screen back
*/
void screenBack();
}
#endif
+27
View File
@@ -29,12 +29,39 @@
#include <memory>
#include <nds.h>
#include <stack>
class Screen {
public:
static std::stack<std::unique_ptr<Screen>> screens;
virtual ~Screen() {}
virtual void Logic(u32 hDown, u32 hHeld, touchPosition touch) = 0;
virtual void Draw() const = 0;
/**
* @brief Draws the setted screen
*/
static void doDraw();
/**
* @brief The current screen logic
* @param hDown The keysDown variable
* @param hHeld The keysHeld variable
* @param touch The TouchPosition variable
*/
static void doLogic(u32 hDown, u32 hHeld, touchPosition touch);
/**
* @brief Set a specific Screen with the Screen class
* @param screen The screen which to set
*/
static void set(std::unique_ptr<Screen> screen);
/**
* @brief Goes a screen back
*/
static void back();
};
#endif
-19
View File
@@ -29,11 +29,9 @@
#include "tonccpy.h"
#include <nds.h>
#include <stack>
int Graphics::bg3Main, Graphics::bg2Main, Graphics::bg3Sub, Graphics::bg2Sub;
bool Graphics::wideScreen = false;
static std::stack<std::unique_ptr<Screen>> screens;
void Graphics::init(void) {
// Initialize video mode
@@ -90,21 +88,4 @@ void Graphics::drawRectangle(int x, int y, int w, int h, u8 color1, u8 color2, b
for(int i = 0; i < h; i++) {
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> screen) { screens.push(std::move(screen)); }
void Graphics::screenBack() {
if(screens.size() > 0)
screens.pop();
}
+46
View File
@@ -0,0 +1,46 @@
/*
* This file is part of Universal-Core
* Copyright (C) 2021 Universal-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "screen.hpp"
std::stack<std::unique_ptr<Screen>> Screen::screens;
void Screen::doDraw() {
if(!Screen::screens.empty())
Screen::screens.top()->Draw();
}
void Screen::doLogic(u32 hDown, u32 hHeld, touchPosition touch) {
if(!Screen::screens.empty())
Screen::screens.top()->Logic(hDown, hHeld, touch);
}
void Screen::set(std::unique_ptr<Screen> screen) { Screen::screens.push(std::move(screen)); }
void Screen::back() {
if(Screen::screens.size() > 0)
Screen::screens.pop();
}