From e89dc91182a94e48ca9220a2fe075db680ddff04 Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Tue, 16 Aug 2022 15:06:45 -0400 Subject: undo functional --- my_imgui_widgets.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 12 deletions(-) (limited to 'my_imgui_widgets.cpp') diff --git a/my_imgui_widgets.cpp b/my_imgui_widgets.cpp index d1d8d83..b924d55 100644 --- a/my_imgui_widgets.cpp +++ b/my_imgui_widgets.cpp @@ -70,6 +70,26 @@ ImGui_KeyframeDragging(project_data *File, project_state *State, ui *UI, propert } } +static void +ImGui_InteractSliderProperty(project_state *State, memory *Memory, property_channel *Property) +{ + ImGui::DragScalar(Property->Name, ImGuiDataType_Float, &Property->CurrentValue.f, + Property->ScrubVal.f, &Property->MinVal.f, &Property->MaxVal.f, "%f"); + if (ImGui::IsItemActivated()) { + Action_Entry_Begin(Memory, action_entry_default, "Tranforms interact"); + State->InteractCache[0] = Property->CurrentValue.f; + } + if (ImGui::IsItemActive()) { + State->UpdateFrame = true; + } + if (ImGui::IsItemDeactivated()) { + Action_Change_Commit(Memory, &Property->CurrentValue.f, &State->InteractCache[0], + &Property->CurrentValue.f, action_change_r32); + Action_Entry_End(Memory); + State->UpdateFrame = true; + } +} + // Returns a normalized UV position of the composition static v2 ImGui_ScreenPointToCompUV(ImVec2 ViewportMin, ImVec2 CompPos, ImVec2 CompZoom, ImVec2 MousePos) @@ -81,6 +101,19 @@ ImGui_ScreenPointToCompUV(ImVec2 ViewportMin, ImVec2 CompPos, ImVec2 CompZoom, I return V2(Result); } +static void +ImGui_DebugUndoTree(project_data *File, memory *Memory) +{ + ImGui::SetNextWindowSize(ImVec2(200, 800)); + ImGui::Begin("undotree"); + for (int i = 0; i < Memory->Action.NumberOfEntries; i++) { + action_entry Entry = Memory->Action.Entry[i]; + bool32 CurrentPos = (i < Memory->Action.Index); + ImGui::MenuItem(Entry.Name, NULL, CurrentPos); + } + ImGui::End(); +} + static void ImGui_DebugMemoryViewer(project_data *File, memory *Memory) { @@ -194,11 +227,7 @@ ImGui_PropertiesPanel(project_data *File, project_state *State, ui *UI, memory * if (ImGui::Button("K")) ManualKeyframeInsertF(Property, Memory, File->CurrentFrame, Property->CurrentValue.f); ImGui::SameLine(); - if (ImGui::DragScalar(Property->Name, ImGuiDataType_Float, &Property->CurrentValue.f, - Property->ScrubVal.f, &Property->MinVal.f, &Property->MaxVal.f, "%f")) - { - State->UpdateFrame = true; - } + ImGui_InteractSliderProperty(State, Memory, Property); ImGui::PopID(); } for (int h = 0; h < Layer->NumberOfEffects; h++) { @@ -221,9 +250,9 @@ ImGui_PropertiesPanel(project_data *File, project_state *State, ui *UI, memory * for (int i = 0; i < Effect->NumberOfProperties; i++) { property_channel *Property = &Effect->Property[i]; ImGui::PushID(Property); - if (Property->VarType == type_real) - if (ImGui::DragScalar(Property->Name, ImGuiDataType_Float, &Property->CurrentValue.f, 0.005f, &Property->MaxVal.f, &Property->MaxVal.f, "%f")) - State->UpdateFrame = true; + if (Property->VarType == type_real) { + ImGui_InteractSliderProperty(State, Memory, Property); + } if (Property->VarType == type_color) if (ImGui::ColorEdit4("color 1", &Property->CurrentValue.f, ImGuiColorEditFlags_Float)) State->UpdateFrame = true; @@ -1493,6 +1522,15 @@ ImGui_ProcessInputs(project_data *File, project_state *State, comp_buffer *CompB State->UpdateKeyframes = true; } + if (ImGui::IsKeyPressed(ImGuiKey_Z)) { + if (io.KeyCtrl && io.KeyShift) { + Action_Redo(Memory); + } else if (io.KeyCtrl) { + Action_Undo(Memory); + } + State->UpdateFrame = true; + State->UpdateKeyframes = true; + } if (ImGui::IsKeyPressed(ImGuiKey_Space)) { if (io.KeyShift) { @@ -1510,13 +1548,13 @@ ImGui_ProcessInputs(project_data *File, project_state *State, comp_buffer *CompB } if (ImGui::IsKeyPressed(ImGuiKey_R) && State->NumberOfSelectedLayers) - TransformsInteract(File, State, UI, sliding_rotation); + TransformsInteract(File, State, Memory, UI, sliding_rotation); if (ImGui::IsKeyPressed(ImGuiKey_S) && State->NumberOfSelectedLayers) - TransformsInteract(File, State, UI, sliding_scale); + TransformsInteract(File, State, Memory, UI, sliding_scale); if (ImGui::IsKeyPressed(ImGuiKey_G) && State->NumberOfSelectedLayers) - TransformsInteract(File, State, UI, sliding_position); + TransformsInteract(File, State, Memory, UI, sliding_position); if (ImGui::IsKeyPressed(ImGuiKey_A) && State->NumberOfSelectedLayers) - TransformsInteract(File, State, UI, sliding_anchorpoint); + TransformsInteract(File, State, Memory, UI, sliding_anchorpoint); if (ImGui::IsKeyPressed(ImGuiKey_1)) LoadTestFootage(File, State, Memory); -- cgit v1.2.3