From 8c5f06c37f3c267ecd8f867cd49765c366b5f47c Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Thu, 18 Aug 2022 23:11:29 -0400 Subject: many additions --- my_imgui_widgets.cpp | 64 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 24 deletions(-) (limited to 'my_imgui_widgets.cpp') diff --git a/my_imgui_widgets.cpp b/my_imgui_widgets.cpp index 4bf6b5e..54fa9c1 100644 --- a/my_imgui_widgets.cpp +++ b/my_imgui_widgets.cpp @@ -6,7 +6,7 @@ static void ImGui_KeyframeDragging(project_data *File, project_state *State, ui *UI, property_channel *Property, int32 b, ImGuiIO io, int16 Type) { - keyframe *Keyframe = KeyframeLookupMemory(Property, b); + keyframe *Keyframe = KeyframeLookup(Property, b); if (ImGui::IsItemActive()) { if (!Keyframe->IsSelected && ImGui::IsItemActivated()) @@ -442,7 +442,7 @@ ImGui_Viewport(project_data File, project_state *State, ui *UI, memory *Memory, ImVec2 Point1_ScreenPos = Layer_LocalToScreenSpace(Layer, UI, CompBuffer, Point1_Pos); ImVec2 Point1_ScreenPos_Left = Layer_LocalToScreenSpace(Layer, UI, CompBuffer, Point1_Pos_Left); - ImVec2 Point1_ScreenPos_Right = Layer_LocalToScreenSpace(Layer, UI, CompBuffer, Point1_Pos_Right); + // ImVec2 Point1_ScreenPos_Right = Layer_LocalToScreenSpace(Layer, UI, CompBuffer, Point1_Pos_Right); ImGui::PushID(p); @@ -450,13 +450,13 @@ ImGui_Viewport(project_data File, project_state *State, ui *UI, memory *Memory, // The handle itself - // if (Point0->IsSelected || State->Tool == tool_pen) { - col = ImGui::GetColorU32(ImGuiCol_ButtonHovered); + col = ImGui::GetColorU32(ImGuiCol_ButtonHovered); + if (Point0->HandleBezier) { draw_list->AddNgon(Point0_ScreenPos_Left, 10, col, 8, 5.0f); draw_list->AddNgon(Point0_ScreenPos_Right, 10, col, 8, 5.0f); draw_list->AddLine(Point0_ScreenPos, Point0_ScreenPos_Left, col, 2.0f); draw_list->AddLine(Point0_ScreenPos, Point0_ScreenPos_Right, col, 2.0f); - // } + } draw_list->AddNgon(Point0_ScreenPos, 10, col, 8, 5.0f); @@ -484,21 +484,20 @@ ImGui_Viewport(project_data File, project_state *State, ui *UI, memory *Memory, } if (ImGui::IsItemActivated() && b == 0) { if (p == 0 && State->Pen.IsActive) { - // TODO(fox): I think we need some alternate - // Change functions to make these types of - // value sets more easy to read... - bool32 SetFalse = false; - bool32 SetTrue = true; Action_Entry_Commit(Memory, action_entry_default, "Close mask path"); - Action_Change_Commit(Memory, &State->Pen.IsActive, - &State->Pen.IsActive, &SetFalse, action_change_i32); - Action_Change_Commit(Memory, &Mask->IsClosed, - &Mask->IsClosed, &SetTrue, action_change_i32); - Action_Entry_End(Memory); + Action_Change_Commit_SwapBool(Memory, &State->Pen.IsActive); + Action_Change_Commit_SwapBool(Memory, &Mask->IsClosed); // State->Pen.IsActive = false; // Mask->IsClosed = true; + Action_Entry_End(Memory); + } else if (io.KeyCtrl) { + // TODO(fox): Mask delete! + } else if (io.KeyAlt) { + Action_Entry_Commit(Memory, action_entry_default, "Switch handles on point"); + Action_Change_Commit_SwapBool(Memory, &Point0->HandleBezier); + Action_Entry_End(Memory); } - Point0->IsSelected = 1; + Point0->IsSelected = true; } if (ImGui::IsItemActive()) { ImVec2 MouseIncrement = io.MouseDelta * (ImVec2(CompBuffer.Width, CompBuffer.Height) / UI->CompZoom); @@ -527,8 +526,14 @@ ImGui_Viewport(project_data File, project_state *State, ui *UI, memory *Memory, ImU32 col2 = ImGui::GetColorU32(ImGuiCol_Button); - if (Point0->HandleBezier || Point1->HandleBezier) { + if (Point0->HandleBezier && Point1->HandleBezier) { + draw_list->AddBezierCubic(Point0_ScreenPos, Point0_ScreenPos_Right, + Point1_ScreenPos_Left, Point1_ScreenPos, col2, 6.0f, 0); + } else if (Point0->HandleBezier) { draw_list->AddBezierCubic(Point0_ScreenPos, Point0_ScreenPos_Right, + Point1_ScreenPos, Point1_ScreenPos, col2, 6.0f, 0); + } else if (Point1->HandleBezier) { + draw_list->AddBezierCubic(Point0_ScreenPos, Point0_ScreenPos, Point1_ScreenPos_Left, Point1_ScreenPos, col2, 6.0f, 0); } else { draw_list->AddLine(Point0_ScreenPos, Point1_ScreenPos, col2, 6.0f); @@ -547,6 +552,7 @@ ImGui_Viewport(project_data File, project_state *State, ui *UI, memory *Memory, if (ImGui::IsItemHovered()) { #if DEBUG + // Code that basically mimics Mask_AddPointToCurve but visualized in screen space, for checking bugs. v2 LayerPoint = Layer_ScreenSpaceToLocal(Layer, UI, CompBuffer, ViewportMin, io.MousePos); real32 ratio = Bezier_CubicRatioOfPoint(Point0_Pos, Point0_Pos_Right, Point1_Pos_Left, Point1_Pos, LayerPoint); draw_list->AddNgon(io.MousePos, 2, col, 8, 5.0f); @@ -597,7 +603,7 @@ ImGui_Viewport(project_data File, project_state *State, ui *UI, memory *Memory, for (int t = 0; t < tool_count; t++) { ImGui::PushID(t); bool32 Selected = (State->Tool == t); - if (ImGui::Selectable("##tool", Selected, 0, ImVec2(ButtonSize, ButtonSize))) { + if (ImGui::Selectable(ToolName[t], Selected, 0, ImVec2(ButtonSize*2, ButtonSize))) { State->Tool = (tool)t; } ImGui::PopID(); @@ -636,13 +642,19 @@ ImGui_Viewport(project_data File, project_state *State, ui *UI, memory *Memory, CurrentPoint->TangentRight = -OffsetPos; CurrentPoint->TangentLeft = OffsetPos; } - if (ImGui::IsKeyPressed(ImGuiKey_Escape) && IsActive) { + // Escape can be pressed to exit point-adding mode or to delete the + // mask if it was just created. + if (ImGui::IsKeyPressed(ImGuiKey_Escape)) { mask *Mask = &Layer->Mask[Layer->NumberOfMasks-1]; - if (Mask->NumberOfPoints == 1) { + if (IsActive && Mask->NumberOfPoints == 1) { Layer->NumberOfMasks--; Mask->NumberOfPoints = 0; + State->Pen.IsActive = false; + } else { + Action_Entry_Commit(Memory, action_entry_default, "Path adding exited"); + Action_Change_Commit_SwapBool(Memory, &State->Pen.IsActive); + Action_Entry_End(Memory); } - State->Pen.IsActive = false; IsDeactivated = false; // just in case escape and mouse release happen simultaneously } if (IsDeactivated) { @@ -1216,7 +1228,7 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, ImGui::PushID(Property); for (int b = 0; b < Layer->Property[a].NumberOfTotalKeyframes; b++) { - keyframe *Keyframe = KeyframeLookupMemory(Property, b); + keyframe *Keyframe = KeyframeLookup(Property, b); real32 KeyframeOrigin = TimelineStartingPos.x + UI->TimelineZoom*Keyframe->FrameNumber; ImVec2 KeyframePosition = ImVec2(KeyframeOrigin - FontHeight/2, InitialY); @@ -1270,7 +1282,7 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, ImU32 col = ImGui::GetColorU32(ImGuiCol_ScrollbarGrab); for (int b = 0; b < Property->NumberOfTotalKeyframes; b++) { - keyframe *Keyframe = KeyframeLookupMemory(Property, b); + keyframe *Keyframe = KeyframeLookup(Property, b); // int32 Index = KeyframeMemoryToIndex(Property, b); ImGui::PushID(Keyframe); @@ -1351,7 +1363,7 @@ ImGui_Timeline(project_data *File, project_state *State, memory *Memory, ui *UI, // TODO(fox): Reformat this so it's all done in one loop. for (int b = 0; b < Property->NumberOfTotalKeyframes; b++) { - keyframe *Keyframe = KeyframeLookupMemory(Property, b); + keyframe *Keyframe = KeyframeLookup(Property, b); real32 MinVal = Property->LocalMinVal.f; real32 MaxVal = Property->LocalMaxVal.f; @@ -1627,6 +1639,10 @@ ImGui_ProcessInputs(project_data *File, project_state *State, comp_buffer *CompB if (ImGui::IsKeyPressed(ImGuiKey_1)) LoadTestFootage(File, State, Memory); + if (ImGui::IsKeyPressed(ImGuiKey_D) && io.KeyCtrl) + { + } + if (ImGui::IsKeyPressed(ImGuiKey_Delete)) { switch (State->RecentSelectionType) -- cgit v1.2.3