diff options
Diffstat (limited to 'src/imgui_ui_viewport.cpp')
-rw-r--r-- | src/imgui_ui_viewport.cpp | 92 |
1 files changed, 18 insertions, 74 deletions
diff --git a/src/imgui_ui_viewport.cpp b/src/imgui_ui_viewport.cpp index fae7bd4..774b305 100644 --- a/src/imgui_ui_viewport.cpp +++ b/src/imgui_ui_viewport.cpp @@ -82,7 +82,7 @@ ImGui_Viewport_ShapeUI(project_state *State, memory *Memory, ui *UI, ImGuiIO &io if (Point_1->Type == interpolation_type_bezier) draw_list->AddLine(ScreenPoint_0[1], ScreenPoint_0[2], wcol, 2.0f); - ImU32 PointCol = (Point_1->IsSelected) ? ImColor(0.8f, 0.5f, 0.0f, 1.0f) : ImColor(0.1f, 0.1f, 0.1f, 1.0f); + ImU32 PointCol = (Point_1->IsSelected) ? ImColor(0.8f, 0.5f, 0.0f, 1.0f) : ImColor(0.1f, 0.1f, 0.1f, 0.2f); ImGui::PushID(i); for (int a = 0; a < 3; a++) { ImGui::PushID(a); @@ -100,6 +100,12 @@ ImGui_Viewport_ShapeUI(project_state *State, memory *Memory, ui *UI, ImGuiIO &io ImGui::SetMouseCursor(ImGuiMouseCursor_Hand); } if (IsItemActivated) { + if (!io.KeyShift) { + for (int p = 0; p < Shape->Point_Count; p++) { + bezier_point *Point = Bezier_LookupAddress(Memory, Shape->Block_Bezier_Index, p, 1); + Point->IsSelected = 0; + } + } Point_1->IsSelected = 1; } if (IsItemActive) { @@ -111,12 +117,12 @@ ImGui_Viewport_ShapeUI(project_state *State, memory *Memory, ui *UI, ImGuiIO &io Assert(State->Interact_Active == interact_type_keyframe_move); ImVec2 DragDelta = io.MousePos - ImVec2(State->Interact_Offset[2], State->Interact_Offset[3]); if (io.MouseDelta.x || io.MouseDelta.y) { + if (State->Interact_Active == interact_type_keyframe_move) { + State->Interact_Offset[0] = DragDelta.x * (MainComp->Width / UI->CompZoom.x); + State->Interact_Offset[1] = DragDelta.y * (MainComp->Height / UI->CompZoom.y); + } State->UpdateFrame = true; } - if (State->Interact_Active == interact_type_keyframe_move) { - State->Interact_Offset[0] = DragDelta.x * (MainComp->Width / UI->CompZoom.x); - State->Interact_Offset[1] = DragDelta.y * (MainComp->Height / UI->CompZoom.y); - } } } if (IsItemDeactivated) { @@ -126,85 +132,23 @@ ImGui_Viewport_ShapeUI(project_state *State, memory *Memory, ui *UI, ImGuiIO &io Shape->IsClosed = true; History_Entry_End(Memory); } else if (Layer != NULL) { - layer_transforms T = Layer_GetTransforms(Layer); History_Entry_Commit(Memory, "Move point"); - void *Data = Memory_PushScratch(Memory, sizeof(nvg_point) * 128); - v2 Min_Old = {}, Max_Old = {}; - NVG_FlattenPath(Memory, Shape, (nvg_point *)Data, State, T, 0, 0, Width, Height, 0, &Min_Old, &Max_Old); - v2 TestMin = Min_Old, TestMax = Max_Old; + layer_transforms T = Layer_GetTransforms(Layer); for (int p = 0; p < Shape->Point_Count; p++) { bezier_point *Point = Bezier_LookupAddress(Memory, Shape->Block_Bezier_Index, p, 1); if (Point->IsSelected) { v2 *Pos = &Point->Pos[Point->IsSelected-1]; History_Action_Swap(Memory, F_Bezier, sizeof(*Pos), Pos); + *Pos = TransformPoint(T, Shape->Width, Shape->Height, *Pos); Pos->x += State->Interact_Offset[0]; Pos->y += State->Interact_Offset[1]; - if (Pos->x < TestMin.x) { - TestMin.x = Pos->x; - } - if (Pos->y < TestMin.y) { - TestMin.y = Pos->y; - } - if (Pos->x > TestMax.x) { - TestMax.x = Pos->x; - } - if (Pos->y > TestMax.y) { - TestMax.y = Pos->y; - } + *Pos = T_CompPosToLayerPos(T, MainComp->Width, MainComp->Height, Shape->Width, Shape->Height, Pos->x, Pos->y); } } - v2 MinDiff = TestMin - Min_Old; - v2 MaxDiff = TestMax - Max_Old; - for (int p = 0; p < Shape->Point_Count; p++) { - bezier_point *Point = Bezier_LookupAddress(Memory, Shape->Block_Bezier_Index, p, 1); - v2 *Pos = &Point->Pos[0]; - History_Action_Swap(Memory, F_Bezier, sizeof(*Pos), Pos); - if (MinDiff.x) - Pos->x -= State->Interact_Offset[0]; - if (MinDiff.y) - Pos->y -= State->Interact_Offset[1]; - if (MaxDiff.x) - // Pos->x -= State->Interact_Offset[0]; - if (MaxDiff.y) - // Pos->y += State->Interact_Offset[1]; - int FU = 0; - } - State->Interact_Active = interact_type_none; - v2 Min_New = {}, Max_New = {}; - NVG_FlattenPath(Memory, Shape, (nvg_point *)Data, State, T, Shape->Width, Shape->Height, Width, Height, 1, &Min_New, &Max_New); - - Memory_PopScratch(Memory, sizeof(nvg_point) * 128); - - int Width_Old = Max_Old.x - Min_Old.x; - int Width_New = Max_New.x - Min_New.x; - int Height_New = Max_New.y - Min_New.y; - if (MinDiff.x) { - History_Action_Swap(Memory, F_Layers, sizeof(Layer->ax.CurrentValue), &Layer->ax.CurrentValue); - Layer->ax.CurrentValue -= (real32)(State->Interact_Offset[0]) * (1.0f - Layer->ax.CurrentValue) / Width_New; - } if (MinDiff.y) { - History_Action_Swap(Memory, F_Layers, sizeof(Layer->ay.CurrentValue), &Layer->ay.CurrentValue); - Layer->ay.CurrentValue -= (real32)(State->Interact_Offset[1]) * (1.0f - Layer->ay.CurrentValue) / Height_New; - } if (MaxDiff.x) { - History_Action_Swap(Memory, F_Layers, sizeof(Layer->ax.CurrentValue), &Layer->ax.CurrentValue); - Layer->ax.CurrentValue -= (real32)(State->Interact_Offset[0]) * (Layer->ax.CurrentValue) / Width_New; - } if (MaxDiff.y) { - History_Action_Swap(Memory, F_Layers, sizeof(Layer->ay.CurrentValue), &Layer->ay.CurrentValue); - Layer->ay.CurrentValue -= (real32)(State->Interact_Offset[1]) * (Layer->ay.CurrentValue) / Height_New; - } - /* - if (Min_New.y < Min_Old.y) { - Layer->y.CurrentValue += Min_New.y - Min_Old.y; - } - if (Max_New.x > Max_Old.x) { - Layer->x.CurrentValue += Max_New.x - Max_Old.x; - } - if (Max_New.y > Max_Old.y) { - Layer->y.CurrentValue += Max_New.y - Max_Old.y; - } - */ - Shape->Width = Width_New; - Shape->Height = Height_New; History_Entry_End(Memory); + State->Interact_Active = interact_type_none; + State->Interact_Offset[0] = 0; + State->Interact_Offset[1] = 0; } } draw_list->AddNgon(ScreenPoint_1[a], 4, PointCol, 8, 5.0f); @@ -735,7 +679,7 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, } shape_layer *Shape = &UI->Shape; - if (State->Tool == tool_pen && State->MostRecentlySelectedLayer == -1) + if ((State->Tool == tool_pen || State->Tool == tool_square) && State->MostRecentlySelectedLayer == -1) ImGui_Viewport_ShapeUI(State, Memory, UI, io, NULL, 0, 0, Shape, MainComp, draw_list); // Interactions for dragging and zooming |