From c19acda62d2a973825a362ac8846fef77d1596d7 Mon Sep 17 00:00:00 2001 From: Bruno Date: Sun, 18 Apr 2021 21:02:23 +0200 Subject: [PATCH] Added Snapshot Replace --- ActionManager.cpp | 39 +++++++++++++++++++++++++++++++++++++++ ActionManager.h | 2 ++ ImGuiToolkit.cpp | 4 ++-- UserInterfaceManager.cpp | 20 +++++++++++++++++--- 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/ActionManager.cpp b/ActionManager.cpp index f083a81..94127c9 100644 --- a/ActionManager.cpp +++ b/ActionManager.cpp @@ -177,6 +177,40 @@ void Action::snapshot(const std::string &label) #endif } +void Action::replace(uint64_t snapshotid) +{ + // ignore if locked or if no label is given + if (locked_) + return; + + // get snapshot node of target in current session + Session *se = Mixer::manager().session(); + XMLElement *sessionNode = se->snapshots()->xmlDoc_->FirstChildElement( SNAPSHOT_NODE(snapshotid) ); + + if (sessionNode) { + std::string l = sessionNode->Attribute("label"); + + se->snapshots()->xmlDoc_->DeleteChild( sessionNode ); + + // create snapshot node + sessionNode = se->snapshots()->xmlDoc_->NewElement( SNAPSHOT_NODE(snapshotid) ); + se->snapshots()->xmlDoc_->InsertEndChild(sessionNode); + + // label describes the snapshot + sessionNode->SetAttribute("label", l.c_str()); + + // save all sources using source visitor + SessionVisitor sv(se->snapshots()->xmlDoc_, sessionNode); + for (auto iter = se->begin(); iter != se->end(); ++iter, sv.setRoot(sessionNode) ) + (*iter)->accept(sv); + + // debug +#ifdef ACTION_DEBUG + Log::Info("Snapshot replaced %d '%s'", id, label.c_str()); +#endif + } +} + std::list Action::snapshots() const { @@ -241,3 +275,8 @@ void Action::restore(uint64_t snapshotid) store("Snapshot " + label(snapshotid)); } + +void Action::interpolate(uint64_t snapshotid, float val) +{ + +} diff --git a/ActionManager.h b/ActionManager.h index e936735..12bfded 100644 --- a/ActionManager.h +++ b/ActionManager.h @@ -39,7 +39,9 @@ public: void snapshot(const std::string &label); std::list snapshots() const; + void replace(uint64_t snapshotid); void restore(uint64_t snapshotid); + void interpolate(uint64_t snapshotid, float val); void remove (uint64_t snapshotid); std::string label(uint64_t snapshotid) const; diff --git a/ImGuiToolkit.cpp b/ImGuiToolkit.cpp index 58be2dd..b21e35e 100644 --- a/ImGuiToolkit.cpp +++ b/ImGuiToolkit.cpp @@ -1211,11 +1211,11 @@ static int InputTextCallback(ImGuiInputTextCallbackData* data) bool ImGuiToolkit::InputText(const char* label, std::string* str) { - ImGuiInputTextFlags flags = ImGuiInputTextFlags_CallbackResize; + ImGuiInputTextFlags flags = ImGuiInputTextFlags_CallbackResize | ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CharsNoBlank; InputTextCallback_UserData cb_user_data; cb_user_data.Str = str; - return ImGui::InputText(label, (char*)str->c_str(), str->capacity() + 1, flags, InputTextCallback, &cb_user_data); + return ImGui::InputText(label, (char*)str->c_str(), str->capacity() + 1, flags, InputTextCallback, &cb_user_data); } bool ImGuiToolkit::InputTextMultiline(const char* label, std::string* str, const ImVec2& size, int linesize) diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index f527ff9..34b5ed0 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -3153,8 +3153,8 @@ void Navigator::RenderMainPannelVimix() current_snapshot = *snapit; if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) { // trigger snapshot -// current_snapshot = snapshots.end(); Action::manager().restore(current_snapshot); + current_snapshot = 0; } } // context menu @@ -3173,11 +3173,13 @@ void Navigator::RenderMainPannelVimix() current_snapshot = 0; } if (ImGui::Selectable( ICON_FA_STAR "_ Remove", false, 0, size )) { - - Action::manager().remove(current_snapshot); current_snapshot = 0; } + if (ImGui::Selectable( ICON_FA_STAR "= Replace", false, 0, size )) { + Action::manager().replace(current_snapshot); + current_snapshot = 0; + } ImGui::TextDisabled("Rename"); ImGui::SetNextItemWidth(size.x); if ( current_snapshot > 0 ) { @@ -3196,7 +3198,11 @@ void Navigator::RenderMainPannelVimix() ImGui::SetCursorPos( ImVec2( pannel_width_ IMGUI_RIGHT_ALIGN, pos_top.y )); if ( ImGuiToolkit::IconButton( ICON_FA_STAR "+")) { Action::manager().snapshot( SystemToolkit::date_time_string() ); + current_snapshot = 0; } + if (ImGui::IsItemHovered()) + ImGuiToolkit::ToolTip("Take Snapshot ", CTRL_MOD "Y"); + // // active list element : delete snapshot button // ImGui::SetCursorPos( ImVec2( pannel_width_ IMGUI_RIGHT_ALIGN, pos_bot.y - ImGui::GetFrameHeightWithSpacing())); // if (current_snapshot != snapshots.end()) { @@ -3209,6 +3215,14 @@ void Navigator::RenderMainPannelVimix() // else // ImGui::TextDisabled( ICON_FA_STAR "_" ); + if (current_snapshot > 0) { + ImGui::SetCursorPos( pos_bot ); + static float interpolation = 0.f; + ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); + if ( ImGui::SliderFloat("Animate", &interpolation, 0.f, 1.f) ) { + + } + } }