diff options
Diffstat (limited to 'src/imgui_ui_viewport.cpp')
-rw-r--r-- | src/imgui_ui_viewport.cpp | 172 |
1 files changed, 143 insertions, 29 deletions
diff --git a/src/imgui_ui_viewport.cpp b/src/imgui_ui_viewport.cpp index beb7c8f..eb48159 100644 --- a/src/imgui_ui_viewport.cpp +++ b/src/imgui_ui_viewport.cpp @@ -1,3 +1,7 @@ +#if SPECIAL +#include "main.h" +#endif + static void ImGui_Viewport_Toolbar(project_state *State, ImDrawList *draw_list) @@ -473,10 +477,10 @@ ImGui_Viewport_TransformUI(project_data *File, project_state *State, memory *Mem } } } else { - History_Action_Swap(Memory, F_File, sizeof(Layer->x.CurrentValue), &Layer->x.CurrentValue); - History_Action_Swap(Memory, F_File, sizeof(Layer->y.CurrentValue), &Layer->y.CurrentValue); - History_Action_Swap(Memory, F_File, sizeof(Layer->scale.CurrentValue), &Layer->scale.CurrentValue); - History_Action_Swap(Memory, F_File, sizeof(Layer->rotation.CurrentValue), &Layer->rotation.CurrentValue); + History_Action_Swap(Memory, F_Layers, sizeof(Layer->x.CurrentValue), &Layer->x.CurrentValue); + History_Action_Swap(Memory, F_Layers, sizeof(Layer->y.CurrentValue), &Layer->y.CurrentValue); + History_Action_Swap(Memory, F_Layers, sizeof(Layer->scale.CurrentValue), &Layer->scale.CurrentValue); + History_Action_Swap(Memory, F_Layers, sizeof(Layer->rotation.CurrentValue), &Layer->rotation.CurrentValue); Transform_ApplyInteractive(*(interact_transform *)&State->Interact_Offset[0], &Layer->x.CurrentValue, &Layer->y.CurrentValue, &Layer->rotation.CurrentValue, &Layer->scale.CurrentValue); } } @@ -502,7 +506,8 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImG sorted_comp_array *SortedCompStart = &SortedCompArray[CompIndex]; sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(SortedLayerArray, SortedCompArray, CompIndex); ImU32 wcol = ImGui::GetColorU32(ImGuiCol_Text); - for (int i = 0; i < SortedCompStart->LayerCount; i++) + int LayerCount = SortedCompStart->LayerCount + SortedCompStart->FakeLayerCount; + for (int i = 0; i < LayerCount; i++) { sorted_layer_array SortEntry = SortedLayerStart[i]; uint32 Index_Physical = SortEntry.Block_Layer_Index; @@ -511,7 +516,8 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImG ParentLayer[Recursions] = Layer; ImGui_Viewport_SelectedLayerUI(State, Memory, UI, io, draw_list, MainComp, Layer->Block_Source_Index, ParentLayer, Recursions + 1, SortedCompArray, SortedLayerArray); } - if (Layer->IsSelected) { + // if (Layer->IsSelected) { + if (1) { uint32 Width = 0, Height = 0; void *Data; uint32 NumberOfVerts; @@ -520,7 +526,7 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImG Width = Comp->Width; Height = Comp->Height; } else if (Layer->IsShapeLayer) { -#if DEBUG +#if 0 block_bezier *Bezier = (block_bezier *)Memory_Block_AddressAtIndex(Memory, F_Bezier, Layer->Shape.Block_Bezier_Index[0]); Data = Memory_PushScratch(Memory, sizeof(nvg_point) * 128); int L_Width = 0, L_Height = 0; @@ -528,9 +534,6 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImG v2 Min = {}, Max = {}; layer_transforms T = Layer_GetTransforms(Layer); - if (State->Interact_Active == interact_type_keyframe_move) { - NVG_FlattenPath(Memory, &Layer->Shape, (nvg_point *)Data, State, T, 0, 0, Width, Height, 0, &Min, &Max); - } NumberOfVerts = NVG_FlattenPath(Memory, &Layer->Shape, (nvg_point *)Data, State, T, Layer->Shape.Width, Layer->Shape.Height, Width, Height, 1, &Min, &Max); #endif @@ -547,12 +550,17 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImG if (State->Interact_Active == interact_type_viewport_transform && Layer->IsSelected == 1) { Transform_ApplyInteractive(*(interact_transform *)&State->Interact_Offset[0], &T.x, &T.y, &T.rotation, &T.scale); } + if (State->Interact_Active == interact_type_viewport_duplicate && SortEntry.IsFake) { + Assert(Layer->IsSelected); + T.x += State->Interact_Offset[0]; + T.y += State->Interact_Offset[1]; + } if (Layer->IsShapeLayer) { ImGui_Viewport_ShapeUI(State, Memory, UI, io, Layer, Width, Height, &Layer->Shape, MainComp, draw_list); // point visualization -#if DEBUG +#if 0 void *Data2 = Memory_PushScratch(Memory, sizeof(real32) * 3 * 256); uint32 GL_PointCount = NVG_ExpandStroke(Memory, NumberOfVerts, Layer->Shape.Opt.StrokeWidth, Layer->Shape.Opt.LineCapType, Layer->Shape.Opt.LineJoinType, Layer->Shape.IsClosed, (nvg_point *)Data, (real32 *)Data2); @@ -620,7 +628,7 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImG static void ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, ImGuiIO io, GLuint textureID, - sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, uint16 *SortedKeyframeArray) + sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, sorted_property_array *SortedPropertyStart, uint16 *SortedKeyframeArray) { bool open = true; ImGui::Begin("Viewport", &open, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse); @@ -651,9 +659,14 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, ImVec2 CompPosMax = ImVec2(UI->CompPos.x + UI->CompZoom.x, UI->CompPos.y + UI->CompZoom.y); ImDrawList* draw_list = ImGui::GetWindowDrawList(); - draw_list->AddRectFilled(ViewportMin, ViewportMax, IM_COL32(50, 50, 50, 255)); - draw_list->AddRect(ViewportMin, ViewportMax, IM_COL32(255, 255, 255, 255)); - draw_list->AddRect(CompPosMin, CompPosMax, IM_COL32(255, 255, 255, 55)); + uint32 BGCOL = IM_COL32(50, 50, 50, 255); + uint32 OUTLINE = IM_COL32(255, 255, 255, 255); + if (UI->Mode == 1) { + // BGCOL = IM_COL32(0, 0, 0, 255); + OUTLINE = IM_COL32(255,255,255, 255); + } + draw_list->AddRectFilled(ViewportMin, ViewportMax, BGCOL); + draw_list->AddRect(ViewportMin, ViewportMax, IM_COL32(255,255,255, 255)); real32 FontSize = ImGui::GetFontSize(); ImGui::SetCursorScreenPos(ImVec2(ViewportMax.x - FontSize*2, ViewportMin.y + ViewportScale.y - FontSize*3.0)); @@ -665,11 +678,20 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, // Actual composition texture draw_list->PushClipRect(ViewportMin, ViewportMax, true); - draw_list->AddImage((void *)(intptr_t)textureID, CompPosMin, CompPosMax); + if (UI->Mode == 0) { + draw_list->AddRect(CompPosMin, CompPosMax, OUTLINE); + draw_list->AddImage((void *)(intptr_t)textureID, CompPosMin, CompPosMax); + } else { + Render_UI(File, State, Memory, UI, draw_list, + SortedCompArray, SortedLayerArray, + SortedPropertyStart, SortedKeyframeArray, File->PrincipalCompIndex, State->Frame_Current); + draw_list->AddRect(CompPosMin, CompPosMax, OUTLINE); + } draw_list->PopClipRect(); + // UI+interaction for layer - if (State->MostRecentlySelectedLayer > -1) + // if (State->MostRecentlySelectedLayer > -1) { block_layer *ParentLayer[4]; ImGui_Viewport_SelectedLayerUI(State, Memory, UI, io, draw_list, MainComp, File->PrincipalCompIndex, ParentLayer, 0, SortedCompArray, SortedLayerArray); @@ -679,7 +701,7 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, } shape_layer *Shape = &UI->Shape; - if ((State->Tool == tool_pen || State->Tool == tool_square) && State->MostRecentlySelectedLayer == -1) + if ((State->Tool == tool_pen) && State->MostRecentlySelectedLayer == -1) ImGui_Viewport_ShapeUI(State, Memory, UI, io, NULL, 0, 0, Shape, MainComp, draw_list); // Interactions for dragging and zooming @@ -726,15 +748,41 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, } // Layer selection if (State->Tool == tool_default && State->Interact_Active == interact_type_none) { - int32 Selection = Layer_TestSelection(Memory, State, UI, SortedCompArray, SortedLayerArray, File->PrincipalCompIndex); - if (!io.KeyShift && State->Interact_Active == interact_type_none) - Layer_DeselectAll(File, State, Memory); - if (Selection != -1) - Layer_Select(Memory, State, Selection); + if (io.KeyAlt) { + } else { + int32 Selection = Layer_TestSelection(Memory, State, UI, SortedCompArray, SortedLayerArray, File->PrincipalCompIndex); + if (!io.KeyShift && State->Interact_Active == interact_type_none) + Layer_DeselectAll(File, State, Memory); + if (Selection != -1) + Layer_Select(Memory, State, Selection); + } } } } + if (IsActive && !ImGui::IsMouseDown(ImGuiMouseButton_Right) && !io.KeyCtrl && !io.KeyAlt) + { + v2 CompUV = State->LastClickedPoint; + ImVec2 ScreenPointStart = ImVec2(UI->CompPos.x + CompUV.x * UI->CompZoom.x, + UI->CompPos.y + CompUV.y * UI->CompZoom.y); + uint32 fcol = IM_COL32(00, 00, 255, 50); + uint32 wcol = IM_COL32(128, 128, 255, 255); + ImVec2 Vector = io.MousePos - ScreenPointStart; + ImVec2 MousePos = io.MousePos; + if (State->Tool == tool_default && State->Interact_Active == interact_type_none) { + draw_list->AddRectFilled(ScreenPointStart, MousePos, fcol, 2.0f); + draw_list->AddRect(ScreenPointStart, MousePos, wcol, 2.0f); + } + if (io.MouseDelta.x || io.MouseDelta.y) { + Layer_DeselectAll(File, State, Memory); + v2 LocalMaxUV = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, MousePos); + v2 LocalMinPos = State->LastClickedPoint * V2(MainComp->Width, MainComp->Height); + v2 LocalMaxPos = LocalMaxUV * V2(MainComp->Width, MainComp->Height); + Layer_TestBoxSelect(Memory, State, UI, SortedCompArray, SortedLayerArray, File->PrincipalCompIndex, + LocalMinPos, LocalMaxPos); + } + } + /* if (State->Interact_Active == interact_type_viewport_transform) { interact_transform *Interact = (interact_transform *)&State->Interact_Offset[0]; @@ -785,7 +833,6 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, v2 CompUV = State->LastClickedPoint; ImVec2 ScreenPoint = ImVec2(UI->CompPos.x + CompUV.x * UI->CompZoom.x, UI->CompPos.y + CompUV.y * UI->CompZoom.y); - shape_layer *Shape = &UI->Shape; if (Shape->Point_Count > 1) { ImGui::OpenPopupOnItemClick("shapecreate", ImGuiPopupFlags_MouseButtonRight); } @@ -796,9 +843,6 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, ImGui::EndPopup(); } if (!Shape->IsClosed) { - if (IsHovered && IsActivated && !ImGui::IsMouseDown(ImGuiMouseButton_Right)) - { - } ImVec2 Vector = io.MousePos - ScreenPoint; uint32 wcol = IM_COL32(00, 00, 80, 255); if (IsActive && !OtherActions) { @@ -819,6 +863,53 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, } } + if (State->Tool == tool_slide && State->Interact_Active == interact_type_none && !OtherActions) { + real32 Delta = io.MouseDelta.x + io.MouseDelta.y; + if (Delta && IsActive) { + State->Interact_Active = interact_type_viewport_slide; + } + } + + if (State->Interact_Active == interact_type_viewport_slide) { + if (IsDeactivated) { + Assert(0); + } else { + Assert(IsActive); + v2 MouseCompPos = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, io.MousePos); + v2 DragDelta = MouseCompPos - State->LastClickedPoint; + State->Interact_Offset[0] = DragDelta.x * MainComp->Width; + State->Interact_Offset[1] = DragDelta.y * MainComp->Height; + } + } + + if (State->Tool == tool_rectangle && State->Interact_Active == interact_type_none) { + v2 CompUV = State->LastClickedPoint; + ImVec2 ScreenPointStart = ImVec2(UI->CompPos.x + CompUV.x * UI->CompZoom.x, + UI->CompPos.y + CompUV.y * UI->CompZoom.y); + uint32 wcol = IM_COL32(00, 00, 255, 255); + ImVec2 Vector = io.MousePos - ScreenPointStart; + ImVec2 MousePos = io.MousePos; + if (io.KeyShift) { + MousePos = ScreenPointStart + ImVec2(Vector.x, Vector.x); + } + if (IsActive && !OtherActions) { + draw_list->AddRect(ScreenPointStart, MousePos, wcol, 2.0f); + } + if (Shape->Point_Count == 0 && IsDeactivated && !OtherActions && !ImGui::IsMouseReleased(ImGuiMouseButton_Right)) { + ImVec2 ScreenPoint[4] = { ScreenPointStart, ImVec2(ScreenPointStart.x, MousePos.y), MousePos, ImVec2(MousePos.x, ScreenPointStart.y) }; + History_Entry_Commit(Memory, "Add rectangle"); + for (int i = 0; i < 4; i++) { + v2 CompPoint = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, ScreenPoint[i]); + CompPoint = CompPoint * V2(MainComp->Width, MainComp->Height); + bezier_point PointData = { 1, { CompPoint, V2(0, 0), V2(0, 0) }, interpolation_type_linear, 0 }; + Bezier_Add(Memory, F_File, Shape->Block_Bezier_Index, &Shape->Block_Bezier_Count, &Shape->Point_Count, PointData); + } + Shape->IsClosed = true; + History_Entry_End(Memory); + State->HotkeyInput = hotkey_newlayer_shape; + } + } + if (ImGui::IsKeyDown(ImGuiKey_Z) && ImGui::IsWindowHovered()) { if (IsActive) ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeAll); @@ -833,16 +924,39 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) Distance = 200; } - if (Distance && ImGui::IsKeyDown(ImGuiKey_Z)) - { + if (Distance && ImGui::IsKeyDown(ImGuiKey_Z)) { if (io.KeyShift) Distance *= -1; UI->CompZoom.x += (Distance)*(real32)MainComp->Width/MainComp->Height; UI->CompZoom.y += (Distance); UI->CompPos.x -= ((Distance)*(real32)MainComp->Width/MainComp->Height)*State->LastClickedPoint.x; UI->CompPos.y -= Distance*State->LastClickedPoint.y; + } else if (Distance && io.KeyAlt) { + State->Interact_Active = interact_type_viewport_duplicate; + } + + if (State->Interact_Active == interact_type_viewport_duplicate) { + if (IsDeactivated) { + History_Entry_Commit(Memory, "Duplicate layers"); + State->Interact_Active = interact_type_none; + State->Interact_Modifier = 0; + v2 Offset = V2(State->Interact_Offset[0], State->Interact_Offset[1]); + Project_Layer_Duplicate(File, State, Memory, SortedCompArray, SortedLayerArray, Offset, 1); + State->Interact_Dup_Previous[0] = State->Interact_Offset[0]; + State->Interact_Dup_Previous[1] = State->Interact_Offset[1]; + State->Interact_Offset[0] = 0; + State->Interact_Offset[1] = 0; + History_Entry_End(Memory); + } else { + Assert(IsActive); + v2 MouseCompPos = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, io.MousePos); + v2 DragDelta = MouseCompPos - State->LastClickedPoint; + State->Interact_Offset[0] = DragDelta.x * MainComp->Width; + State->Interact_Offset[1] = DragDelta.y * MainComp->Height; + } } + ImGui::SetCursorScreenPos(ImVec2(ViewportMin.x, ViewportMin.y + ViewportScale.y - FontSize*1.5)); ImGui::Text("%.1f", 100.0f * (UI->CompZoom.x / MainComp->Width)); |