From 3a1c15f313ef12bc2b7a5da16436715cfde06911 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Wed, 26 Jul 2023 12:24:18 +0200 Subject: [PATCH] screen concept --- src/CMakeLists.txt | 6 ++++++ src/main.cpp | 11 ++++++++++- src/main_screen.cpp | 17 +++++++++++++++++ src/main_screen.hpp | 15 +++++++++++++++ src/screen.hpp | 10 ++++++++++ src/start_screen.cpp | 23 +++++++++++++++++++++++ src/start_screen.hpp | 13 +++++++++++++ 7 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/main_screen.cpp create mode 100644 src/main_screen.hpp create mode 100644 src/screen.hpp create mode 100644 src/start_screen.cpp create mode 100644 src/start_screen.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 14b39c66..8a660753 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,6 +3,12 @@ cmake_minimum_required(VERSION 3.9 FATAL_ERROR) add_executable(tomato main.cpp icon.rc + + screen.hpp + start_screen.hpp + start_screen.cpp + main_screen.hpp + main_screen.cpp ) target_compile_features(tomato PUBLIC cxx_std_17) diff --git a/src/main.cpp b/src/main.cpp index 5ec945f1..d4472bdd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,6 +7,8 @@ #include "./theme.hpp" +#include "./start_screen.hpp" + #include #include #include @@ -50,6 +52,8 @@ int main(int argc, char** argv) { ImGui_ImplSDLRenderer3_Init(renderer.get()); auto imgui_sdlrenderer_scope = std::async(std::launch::deferred, &ImGui_ImplSDLRenderer3_Shutdown); + std::unique_ptr screen = std::make_unique(); + bool quit = false; while (!quit) { SDL_Event event; @@ -68,7 +72,12 @@ int main(int argc, char** argv) { ImGui_ImplSDL3_NewFrame(); ImGui::NewFrame(); - ImGui::ShowDemoWindow(); + //ImGui::ShowDemoWindow(); + + Screen* ret_screen = screen->poll(quit); + if (ret_screen != nullptr) { + screen.reset(ret_screen); + } ImGui::Render(); ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData()); diff --git a/src/main_screen.cpp b/src/main_screen.cpp new file mode 100644 index 00000000..5b35205d --- /dev/null +++ b/src/main_screen.cpp @@ -0,0 +1,17 @@ +#include "./main_screen.hpp" + +#include + +#include + +MainScreen::MainScreen(std::string save_path) { +} + +Screen* MainScreen::poll(bool& quit) { + bool open = !quit; + ImGui::ShowDemoWindow(&open); + quit = !open; + + return nullptr; +} + diff --git a/src/main_screen.hpp b/src/main_screen.hpp new file mode 100644 index 00000000..e4f54482 --- /dev/null +++ b/src/main_screen.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include "./screen.hpp" + +#include + +struct MainScreen final : public Screen { + MainScreen(std::string save_path); + ~MainScreen(void) = default; + + // return nullptr if not next + // sets bool quit to true if exit + Screen* poll(bool&) override; +}; + diff --git a/src/screen.hpp b/src/screen.hpp new file mode 100644 index 00000000..c48d9d1f --- /dev/null +++ b/src/screen.hpp @@ -0,0 +1,10 @@ +#pragma once + +struct Screen { + virtual ~Screen(void) = default; + + // return nullptr if not next + // sets bool quit to true if exit + virtual Screen* poll(bool& quit) = 0; +}; + diff --git a/src/start_screen.cpp b/src/start_screen.cpp new file mode 100644 index 00000000..35efbd5c --- /dev/null +++ b/src/start_screen.cpp @@ -0,0 +1,23 @@ +#include "./start_screen.hpp" + +#include "./main_screen.hpp" + +#include + +StartScreen::StartScreen(void) { +} + +Screen* StartScreen::poll(bool&) { + + // TODO: imgui tox profile selector? + // +------------------------ + // | +------+ +-------- + // | | ICON | | fileselector/dropdown? + // | | | | password input + // | +------+ +-------- + // +------------------------ + + auto new_screen = std::make_unique("tomato.tox"); + return new_screen.release(); +} + diff --git a/src/start_screen.hpp b/src/start_screen.hpp new file mode 100644 index 00000000..632feace --- /dev/null +++ b/src/start_screen.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include "./screen.hpp" + +struct StartScreen final : public Screen { + StartScreen(void); + ~StartScreen(void) = default; + + // return nullptr if not next + // sets bool quit to true if exit + Screen* poll(bool&) override; +}; +