From 37b27f767200b80464af160aee7d254f8da15cfa Mon Sep 17 00:00:00 2001 From: TheNumbat <mjslater@andrew.cmu.edu> Date: Sun, 25 Apr 2021 17:27:06 -0700 Subject: [PATCH] add clear button --- src/gui/animate.cpp | 11 ++++++++--- src/gui/animate.h | 2 +- src/gui/manager.cpp | 10 +++++++++- src/scene/scene.cpp | 3 ++- src/scene/undo.cpp | 2 ++ 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/gui/animate.cpp b/src/gui/animate.cpp index 3497cd1..ac23299 100644 --- a/src/gui/animate.cpp +++ b/src/gui/animate.cpp @@ -697,9 +697,14 @@ void Animate::set_max(int frames) { current_frame = std::min(current_frame, max_frame - 1); } -void Animate::set(int n_frames, int fps) { - max_frame = n_frames; - frame_rate = fps; +void Animate::set(int n_frames, int fps, bool replace) { + if(replace) { + max_frame = n_frames; + frame_rate = fps; + } else { + max_frame = std::max(n_frames, max_frame); + frame_rate = std::min(frame_rate, fps); + } current_frame = std::min(current_frame, max_frame - 1); } diff --git a/src/gui/animate.h b/src/gui/animate.h index 3cf534e..94917ac 100644 --- a/src/gui/animate.h +++ b/src/gui/animate.h @@ -57,7 +57,7 @@ public: const Anim_Camera& camera() const; Anim_Camera& camera(); Camera current_camera() const; - void set(int n_frames, int fps); + void set(int n_frames, int fps, bool replace); void set_max(int frames); void invalidate(Skeleton::IK_Handle* handle); void invalidate(Joint* handle); diff --git a/src/gui/manager.cpp b/src/gui/manager.cpp index 8c2a065..af8ea06 100644 --- a/src/gui/manager.cpp +++ b/src/gui/manager.cpp @@ -531,7 +531,14 @@ void Manager::UIsidebar(Scene& scene, Undo& undo, float menu_height, Camera& cam ImGui::Text("Edit Scene"); if(ImGui::Button("Open Scene")) load_scene(scene, undo, true); if(wrap_button("Export Scene")) write_scene(scene); - if(wrap_button("Settings")) settings_shown = true; + if(wrap_button("Clear")) { + std::vector<Scene_ID> ids; + scene.for_items([&](Scene_Item& item) { + ids.push_back(item.id()); + }); + for(auto id : ids) undo.del_obj(id); + undo.bundle_last(ids.size()); + } if(ImGui::Button("Import Objects")) { load_scene(scene, undo, false); @@ -544,6 +551,7 @@ void Manager::UIsidebar(Scene& scene, Undo& undo, float menu_height, Camera& cam new_light_window = true; new_light_focus = true; } + ImGui::Separator(); } diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index 5804a84..4acbde5 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -972,7 +972,8 @@ std::string Scene::load(Scene::Load_Opts loader, Undo& undo, Gui::Manager& gui, if(anim->mDuration > 0.0f) { gui.get_animate().set((int)std::ceil(anim->mDuration), - (int)std::round(anim->mTicksPerSecond)); + (int)std::round(anim->mTicksPerSecond), loader.new_scene); + } } gui.get_animate().refresh(*this); diff --git a/src/scene/undo.cpp b/src/scene/undo.cpp index de14b62..90df28c 100644 --- a/src/scene/undo.cpp +++ b/src/scene/undo.cpp @@ -742,6 +742,8 @@ void Undo::redo() { void Undo::bundle_last(size_t n) { + if(!n) return; + std::vector<std::unique_ptr<Action_Base>> undo_pack; for(size_t i = 0; i < n; i++) { undo_pack.push_back(std::move(undos.top())); -- GitLab