From bc090bdaa82a863531fc87b14398cbff06a21c51 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Thu, 19 Oct 2023 17:21:45 +0200 Subject: [PATCH] make main window injectable + start settings window --- src/CMakeLists.txt | 3 +++ src/main_screen.cpp | 21 ++++++++++++++++++++- src/main_screen.hpp | 2 ++ src/settings_window.cpp | 35 +++++++++++++++++++++++++++++++++++ src/settings_window.hpp | 14 ++++++++++++++ 5 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/settings_window.cpp create mode 100644 src/settings_window.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 23884a7..6a36b1f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,6 +52,9 @@ add_executable(tomato ./send_image_popup.hpp ./send_image_popup.cpp + ./settings_window.hpp + ./settings_window.cpp + ./chat_gui4.hpp ./chat_gui4.cpp ) diff --git a/src/main_screen.cpp b/src/main_screen.cpp index 34d152a..b5f06ae 100644 --- a/src/main_screen.cpp +++ b/src/main_screen.cpp @@ -18,7 +18,8 @@ MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path, std::stri mmil(rmm), tam(rmm, cr, conf), sdlrtu(renderer_), - cg(conf, rmm, cr, sdlrtu) + cg(conf, rmm, cr, sdlrtu), + sw(conf) { tel.subscribeAll(tc); @@ -87,11 +88,29 @@ Screen* MainScreen::poll(bool& quit) { tam.iterate(); + // HACK: render the tomato main window first, with proper flags set. + // flags need to be set the first time begin() is called. + // and plugins are run before the main cg is run. + { + // TODO: maybe render cg earlier? or move the main window out of cg? + constexpr auto bg_window_flags = + ImGuiWindowFlags_NoDecoration | + ImGuiWindowFlags_NoMove | + ImGuiWindowFlags_NoResize | + ImGuiWindowFlags_NoSavedSettings | + ImGuiWindowFlags_MenuBar | + ImGuiWindowFlags_NoBringToFrontOnFocus; + + ImGui::Begin("tomato", nullptr, bg_window_flags); + ImGui::End(); + } + pm.tick(time_delta); mts.iterate(); cg.render(); + sw.render(); if constexpr (false) { ImGui::ShowDemoWindow(); diff --git a/src/main_screen.hpp b/src/main_screen.hpp index 2b87b51..54ab716 100644 --- a/src/main_screen.hpp +++ b/src/main_screen.hpp @@ -21,6 +21,7 @@ #include "./sdlrenderer_texture_uploader.hpp" #include "./chat_gui4.hpp" +#include "./settings_window.hpp" #include #include @@ -57,6 +58,7 @@ struct MainScreen final : public Screen { //OpenGLTextureUploader ogltu; ChatGui4 cg; + SettingsWindow sw; MainScreen(SDL_Renderer* renderer_, std::string save_path, std::string save_password, std::vector plugins); ~MainScreen(void); diff --git a/src/settings_window.cpp b/src/settings_window.cpp new file mode 100644 index 0000000..0a59978 --- /dev/null +++ b/src/settings_window.cpp @@ -0,0 +1,35 @@ +#include "./settings_window.hpp" + +#include +#include + +SettingsWindow::SettingsWindow(ConfigModelI& conf) : _conf(conf) { +} + +void SettingsWindow::render(void) { + { // main window menubar injection + // assumes the window "tomato" was rendered already by cg + if (ImGui::Begin("tomato")) { + if (ImGui::BeginMenuBar()) { + ImGui::Separator(); + if (ImGui::BeginMenu("Settings")) { + if (ImGui::MenuItem("show settings window")) { + _show_window = true; + } + ImGui::EndMenu(); + } + ImGui::EndMenuBar(); + } + + } + ImGui::End(); + } + + if (_show_window) { + if (ImGui::Begin("Settings", &_show_window)) { + ImGui::Text("Settings here sldjflsadfs"); + } + ImGui::End(); + } +} + diff --git a/src/settings_window.hpp b/src/settings_window.hpp new file mode 100644 index 0000000..9ae52e6 --- /dev/null +++ b/src/settings_window.hpp @@ -0,0 +1,14 @@ +#pragma once + +struct ConfigModelI; + +class SettingsWindow { + bool _show_window {false}; + ConfigModelI& _conf; + + public: + SettingsWindow(ConfigModelI& conf); + + void render(void); +}; +