From ffc3848d96c134e1099a169b7c797b58851d14ba Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Fri, 24 Jul 2020 17:55:39 +0900 Subject: [PATCH] Add close button to windows without one --- src/imgui_helper.hpp | 11 ++++++++++- src/state.cpp | 28 ++++++++++++++++++++++------ src/state.hpp | 6 ++++++ 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/imgui_helper.hpp b/src/imgui_helper.hpp index 57bb61a..13400ac 100644 --- a/src/imgui_helper.hpp +++ b/src/imgui_helper.hpp @@ -27,10 +27,13 @@ namespace Tri { ImGui::Text("Click anywhere to create triangles, one point at a time"); ImGui::Text("You cannot draw when a window is open"); ImGui::Text("Press \"U\" to undo. Clicking will remove all future undo history"); - ImGui::Text("Press \"R\" to undo."); + ImGui::Text("Press \"R\" to redo."); ImGui::Text("Press \"C\" to change colors"); ImGui::Text("Press \"B\" to change background color"); ImGui::Text("Press \"S\" to save what was drawn as a png image"); + if(ImGui::Button("Close")) { + state->close_help(); + } ImGui::End(); } } @@ -59,6 +62,9 @@ namespace Tri { if(state->get_flags().test(2)) { ImGui::Begin("Tri Color Picker"); ImGui::ColorPicker4("Tri Color", state->get_color()); + if(ImGui::Button("Close")) { + state->close_color_picker(); + } ImGui::End(); } } @@ -67,6 +73,9 @@ namespace Tri { if(state->get_flags().test(5)) { ImGui::Begin("BG Color Picker"); ImGui::ColorPicker3("BG Color", state->get_bg_color()); + if(ImGui::Button("Close")) { + state->close_bg_color_picker(); + } ImGui::End(); } } diff --git a/src/state.cpp b/src/state.cpp index 5ca5e32..0dad229 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -114,14 +114,16 @@ void Tri::State::handle_events() { } } } else if(event.key.code == sf::Keyboard::C) { - flags.flip(2); - if(!flags.test(2)) { - flags.set(7); + if(flags.test(2)) { + close_color_picker(); + } else { + flags.set(2); } } else if(event.key.code == sf::Keyboard::B) { - flags.flip(5); - if(!flags.test(5)) { - flags.set(7); + if(flags.test(5)) { + close_bg_color_picker(); + } else { + flags.set(5); } } else if(event.key.code == sf::Keyboard::S) { flags.flip(6); @@ -308,3 +310,17 @@ void Tri::State::close_save() { bool Tri::State::is_in_clickable_menu() const { return flags.test(0) || flags.test(2) || flags.test(5) || flags.test(6); } + +void Tri::State::close_help() { + flags.reset(0); +} + +void Tri::State::close_color_picker() { + flags.reset(2); + flags.set(7); +} + +void Tri::State::close_bg_color_picker() { + flags.reset(5); + flags.set(7); +} diff --git a/src/state.hpp b/src/state.hpp index 1942ecd..7ae25bb 100644 --- a/src/state.hpp +++ b/src/state.hpp @@ -81,6 +81,12 @@ namespace Tri { private: bool is_in_clickable_menu() const; + + public: + void close_help(); + void close_color_picker(); + void close_bg_color_picker(); + }; }