Add close button to windows without one

This commit is contained in:
Stephen Seo 2020-07-24 17:55:39 +09:00
parent c278bddc27
commit ffc3848d96
3 changed files with 38 additions and 7 deletions

View file

@ -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();
}
}

View file

@ -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);
}

View file

@ -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();
};
}