diff options
Diffstat (limited to 'src/imgui_ui_viewport.cpp')
-rw-r--r-- | src/imgui_ui_viewport.cpp | 354 |
1 files changed, 49 insertions, 305 deletions
diff --git a/src/imgui_ui_viewport.cpp b/src/imgui_ui_viewport.cpp index dc37225..103d325 100644 --- a/src/imgui_ui_viewport.cpp +++ b/src/imgui_ui_viewport.cpp @@ -61,6 +61,7 @@ ImGui_Viewport_ShapeUI(project_state *State, memory *Memory, ui *UI, ImGuiIO &io ImVec2 Point = (i == 0) ? IV2(Point_0->Pos[0]) : IV2(Point_0->Pos[0] + Point_0->Pos[i]); if (Layer != NULL) { layer_transforms T = Layer_GetTransforms(Layer); + Point = Point * ImVec2(Shape->Width, Shape->Height); Point = IV2(TransformPoint(T, Width, Height, *(v2 *)&Point)); } if (State->Interact_Active == interact_type_keyframe_move && Point_0->IsSelected) { @@ -74,6 +75,7 @@ ImGui_Viewport_ShapeUI(project_state *State, memory *Memory, ui *UI, ImGuiIO &io ImVec2 Point = (i == 0) ? IV2(Point_1->Pos[0]) : IV2(Point_1->Pos[0] + Point_1->Pos[i]); if (Layer != NULL) { layer_transforms T = Layer_GetTransforms(Layer); + Point = Point * ImVec2(Shape->Width, Shape->Height); Point = IV2(TransformPoint(T, Width, Height, *(v2 *)&Point)); } if (State->Interact_Active == interact_type_keyframe_move && Point_1->IsSelected) { @@ -145,8 +147,8 @@ ImGui_Viewport_ShapeUI(project_state *State, memory *Memory, ui *UI, ImGuiIO &io 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]; + Pos->x += State->Interact_Offset[0] / Shape->Width; + Pos->y += State->Interact_Offset[1] / Shape->Height; *Pos = T_CompPosToLayerPos(T, MainComp->Width, MainComp->Height, Shape->Width, Shape->Height, Pos->x, Pos->y); } } @@ -157,6 +159,7 @@ ImGui_Viewport_ShapeUI(project_state *State, memory *Memory, ui *UI, ImGuiIO &io } } draw_list->AddNgon(ScreenPoint_1[a], 4, PointCol, 8, 5.0f); + draw_list->AddNgon(ScreenPoint_1[a], 4, 0xFFFFFFFF, 8, 8.0f); ImGui::PopID(); } ImGui::PopID(); @@ -607,14 +610,16 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me } if (InBounds && !io.KeyAlt && !ImGui::IsKeyDown(ImGuiKey_Z) && !ImGui::IsKeyDown(ImGuiKey_ModShift)) { - v2 MouseLocalUV = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, io.MousePos); - bool32 LayerHovered = Layer_TestForPoint(Memory, State, UI, SortedCompArray, SortedLayerArray, File->PrincipalCompIndex, MouseLocalUV); + v2 MouseLocalPos = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, io.MousePos) * V2(CompWidth, CompHeight); + layer_transforms T = {}; + T.scale = 1.0f; + bool32 LayerHovered = Layer_TestForPoint(Memory, State, UI, SortedCompArray, SortedLayerArray, File->PrincipalCompIndex, MouseLocalPos, T); if (LayerHovered) { if (ImGui::GetMouseCursor() == ImGuiMouseCursor_None) { ImGui::SetMouseCursor(ImGuiMouseCursor_Hand); } ImGui::SetCursorScreenPos(io.MousePos - ScaleHandleSize/2); - ImGui::InvisibleButton("##mover", ScaleHandleSize); + ImGui::Button("##mover", ScaleHandleSize); if (!State->InteractTransformMode && ImGui::IsItemActivated() && !OtherActions) { State->Interact_Active = interact_type_viewport_transform_gizmo; State->InteractTransformMode = 3; @@ -691,286 +696,6 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me } } - -static void -ImGui_Viewport_TransformUI(project_data *File, project_state *State, memory *Memory, ui *UI, ImGuiIO &io, ImDrawList *draw_list, - interact_transform *Interact, ImVec2 ViewportMin, uint32 CompWidth, uint32 CompHeight, uint16 *SortedKeyframeArray) -{ - v2 InteractMin = Interact->Min + Interact->Position; - v2 InteractMax = Interact->Max + Interact->Position; - - v2 BoxLength = InteractMax - InteractMin; - v2 Center = InteractMax - (BoxLength/2); - - real32 Point0X = Center.x - InteractMin.x; - real32 Point0Y = Center.y - InteractMin.y; - - real32 Rad = Interact->Radians; - - v2 XAxis = (Point0X * Interact->Scale)*V2(cos(Rad), sin(Rad)); - v2 YAxis = (Point0Y * -Interact->Scale)*V2(sin(Rad), -cos(Rad)); - - // Points are clockwise starting from the top left. - real32 X0 = -XAxis.x - YAxis.x + Center.x; - real32 Y0 = -XAxis.y - YAxis.y + Center.y; - real32 X1 = X0 + XAxis.x*2; - real32 Y1 = Y0 + XAxis.y*2; - real32 X2 = X1 + YAxis.x*2; - real32 Y2 = Y1 + YAxis.y*2; - real32 X3 = X2 - XAxis.x*2; - real32 Y3 = Y2 - XAxis.y*2; - - // Midway points. - real32 Mid_X0 = X0 + XAxis.x; - real32 Mid_Y0 = Y0 + XAxis.y; - real32 Mid_X1 = X1 + YAxis.x; - real32 Mid_Y1 = Y1 + YAxis.y; - real32 Mid_X2 = X2 - XAxis.x; - real32 Mid_Y2 = Y2 - XAxis.y; - real32 Mid_X3 = X3 - YAxis.x; - real32 Mid_Y3 = Y3 - YAxis.y; - - ImVec2 CompScale = UI->CompZoom / ImVec2(CompWidth, CompHeight); - - ImVec2 P[4]; - P[0] = ImVec2(X0, Y0)*CompScale + UI->CompPos; - P[1] = ImVec2(X1, Y1)*CompScale + UI->CompPos; - P[2] = ImVec2(X2, Y2)*CompScale + UI->CompPos; - P[3] = ImVec2(X3, Y3)*CompScale + UI->CompPos; - - ImVec2 Mid_P[4]; - Mid_P[0] = ImVec2(Mid_X0, Mid_Y0)*CompScale + UI->CompPos; - Mid_P[1] = ImVec2(Mid_X1, Mid_Y1)*CompScale + UI->CompPos; - Mid_P[2] = ImVec2(Mid_X2, Mid_Y2)*CompScale + UI->CompPos; - Mid_P[3] = ImVec2(Mid_X3, Mid_Y3)*CompScale + UI->CompPos; - - ImU32 wcol = ImGui::GetColorU32(ImGuiCol_Text); - draw_list->AddLine(P[0], P[1], wcol, 2.0f); - draw_list->AddLine(P[1], P[2], wcol, 2.0f); - draw_list->AddLine(P[2], P[3], wcol, 2.0f); - draw_list->AddLine(P[3], P[0], wcol, 2.0f); - - v2 XAxis2 = (BoxLength*CompScale.x)*V2(cos(Rad), sin(Rad)); - v2 YAxis2 = (BoxLength*CompScale.y)*V2(sin(Rad), -cos(Rad)); - - v2 XAxisPerp = (1.0f / LengthSq(XAxis))*XAxis; - v2 YAxisPerp = (1.0f / LengthSq(YAxis))*YAxis; - - // real32 LocalX = ((io.MousePos.x - UI->CompPos.x) - Center.x) ; - // real32 LocalY = ((io.MousePos.y - UI->CompPos.y) - Center.y) ; - layer_transforms BoxTransforms = { Center.x, Center.y, 0.5, 0.5, (real32)(Interact->Radians / (PI / 180)), Interact->Scale }; - v2 LayerPoint = Transform_ScreenSpaceToLocal(BoxTransforms, CompWidth, CompHeight, BoxLength.x, BoxLength.y, UI->CompPos, UI->CompZoom, ViewportMin, io.MousePos); - - real32 U = LayerPoint.x / BoxLength.x; - real32 V = LayerPoint.y / BoxLength.y; - - ImVec2 ScaleHandleSize(50, 50); - - bool32 OtherActions = ImGui::IsKeyDown(ImGuiKey_Z); - - // First do the halfway scale points, since they don't need UVs considered: - for (int i = 0; i < 4; i++) { - ImGui::SetCursorScreenPos(Mid_P[i] - ScaleHandleSize/2); - ImGui::PushID(i); - - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::ColorConvertFloat4ToU32(ImVec4(0.6f, 0.0f, 0.3f, 1.0f))); - ImGui::Button("##ScaleMids", ScaleHandleSize); - ImGui::PopStyleColor(); - - if (ImGui::IsItemActivated() && !OtherActions) { - State->InteractTransformMode = 1; - } - - if (State->InteractTransformMode == 1 && ImGui::IsItemActive()) - { - uint32 side = i; - if (side == 0) { - Interact->Scale -= io.MouseDelta.y / BoxLength.y; - Interact->Position.y += io.MouseDelta.y / 2; - } else if (side == 1) { - Interact->Scale += io.MouseDelta.x / BoxLength.x; - Interact->Position.x += io.MouseDelta.x / 2; - } else if (side == 2) { - Interact->Scale += io.MouseDelta.y / BoxLength.y; - Interact->Position.y += io.MouseDelta.y / 2; - } else if (side == 3) { - Interact->Scale -= io.MouseDelta.x / BoxLength.x; - Interact->Position.x += io.MouseDelta.x / 2; - } - } - ImGui::PopID(); - } - - bool32 InBounds = false; - // Scale if cursor is on button within the UV, rotate if outside UV, and position if a non-button is dragged. - if (U >= 0.0f && U <= 1.0f && V >= 0.0f && V <= 1.0f) - { - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::ColorConvertFloat4ToU32(ImVec4(0.6f, 0.0f, 0.3f, 1.0f))); - InBounds = true; - } - - for (int i = 0; i < 4; i++) { - ImGui::SetCursorScreenPos(P[i] - ScaleHandleSize/2); - ImGui::PushID(i); - ImGui::Button("##ScaleRotateCorners", ScaleHandleSize); - - if (ImGui::IsItemActivated() && !OtherActions) { - if (InBounds) - State->InteractTransformMode = 1; - else - State->InteractTransformMode = 2; - } - - // Scale part - if (State->InteractTransformMode == 1 && ImGui::IsItemActive()) - { - // TODO(fox): Corner dragging scale only works in the X - // axis. Mostly feels right when dragged how you expect, - // but I'll fix it if someone complains. - uint32 side = i; - if (side == 0) { - Interact->Scale -= io.MouseDelta.x / BoxLength.x; - Interact->Position.x += io.MouseDelta.x / 2; - Interact->Position.y += io.MouseDelta.x*(BoxLength.y/BoxLength.x) / 2; - } else if (side == 1) { - Interact->Scale += io.MouseDelta.x / BoxLength.x; - Interact->Position.x += io.MouseDelta.x / 2; - Interact->Position.y -= io.MouseDelta.x*(BoxLength.y/BoxLength.x) / 2; - } else if (side == 2) { - Interact->Scale += io.MouseDelta.x / BoxLength.x; - Interact->Position.x += io.MouseDelta.x / 2; - Interact->Position.y += io.MouseDelta.x*(BoxLength.y/BoxLength.x) / 2; - } else if (side == 3) { - Interact->Scale -= io.MouseDelta.x / BoxLength.x; - Interact->Position.x += io.MouseDelta.x / 2; - Interact->Position.y -= io.MouseDelta.x*(BoxLength.y/BoxLength.x) / 2; - } - } - - // Rotation part - if (State->InteractTransformMode == 2 && ImGui::IsItemActive()) - { - real32 LocalX = (io.MousePos.x - UI->CompPos.x)/CompScale.x - InteractMin.x - (BoxLength.x/2); - real32 LocalY = (io.MousePos.y - UI->CompPos.y)/CompScale.y - InteractMin.y - (BoxLength.y/2); - - real32 Slope_Mouse = LocalY/LocalX; - real32 Slope_Corner = 0; - real32 Slope_Flipped = 0; - real32 Dot = 0; - - // TODO(fox) learn basic geometry to do this properly - - // We find the angle between the direction of whichever corner the - // mouse is grabbing (Slope_Corner) and the mouse's current - // position (Slope_Mouse) to get ExtraRadians. The calculation only - // works between -90 and 90, so I take the dot product of the - // opposite edge of the corner and add the extra degrees when it's negative. - - v2 SlopeDot = V2(BoxLength.x, BoxLength.y); - // top left clockwise - uint32 side = i; - if (side == 0) { - Slope_Corner = BoxLength.y / BoxLength.x; - Slope_Flipped = -BoxLength.x / BoxLength.y; - Dot = LocalX * -SlopeDot.x + LocalY * -SlopeDot.y; - } else if (side == 1) { - Slope_Corner = -BoxLength.y / BoxLength.x; - Slope_Flipped = BoxLength.x / BoxLength.y; - Dot = LocalX * SlopeDot.x + LocalY * -SlopeDot.y; - } else if (side == 2) { - Slope_Corner = BoxLength.y / BoxLength.x; - Slope_Flipped = -BoxLength.x / BoxLength.y; - Dot = LocalX * SlopeDot.x + LocalY * SlopeDot.y; - } else if (side == 3) { - Slope_Corner = -BoxLength.y / BoxLength.x; - Slope_Flipped = BoxLength.x / BoxLength.y; - Dot = LocalX * -SlopeDot.x + LocalY * SlopeDot.y; - } - - Interact->Radians = atan((Slope_Mouse - Slope_Corner) / (1 + Slope_Mouse * Slope_Corner)); - real32 ExtraRadians2 = atan((Slope_Mouse - Slope_Flipped) / (1 + Slope_Mouse * Slope_Flipped)); - - if (Dot < 0) { - if (Interact->Radians < 0) { - Interact->Radians = (90 * (PI / 180)) + ExtraRadians2; - } else { - Interact->Radians = (-90 * (PI / 180)) + ExtraRadians2; - } - } - } - - ImGui::PopID(); - } - - if (!State->InteractTransformMode && ImGui::IsMouseClicked(ImGuiMouseButton_Left) && InBounds && !OtherActions) - State->InteractTransformMode = 3; - - if (State->InteractTransformMode == 3) { - Interact->Position.x += (real32)io.MouseDelta.x/CompScale.x; - Interact->Position.y += (real32)io.MouseDelta.y/CompScale.y; - } - - if (State->InteractTransformMode) - { - if (io.MouseDelta.x || io.MouseDelta.y) - State->UpdateFrame = true; - if (!ImGui::IsMouseDown(ImGuiMouseButton_Left)) - State->InteractTransformMode = 0; - } - - if (ImGui::IsKeyPressed(ImGuiKey_Escape)) { - State->Interact_Active = interact_type_none; - State->Interact_Modifier = 0; - State->UpdateFrame = true; - Memory->PurgeCache = true; - } - - // Second condition so you don't have to reach for Enter. - if (ImGui::IsKeyPressed(ImGuiKey_Enter) || (ImGui::IsMouseClicked(ImGuiMouseButton_Left) && io.KeyCtrl)) { - int h = 0, c = 0, i = 0; - // if (!io.KeyCtrl) - History_Entry_Commit(Memory, "Transform layers"); - while (Block_Loop(Memory, F_Layers, File->Layer_Count, &h, &c, &i)) { - block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i); - if (Layer->IsSelected & 0x01) { - // if (io.KeyCtrl) { - // layer_transforms T = Layer_GetTransforms(Layer); - // Transform_ApplyInteractive(*(interact_transform *)&State->Interact_Offset[0], &T.x, &T.y, &T.rotation, &T.scale); - // property_channel *Property[4] = { &Layer->x, &Layer->y, &Layer->rotation, &Layer->scale }; - // real32 Val[4] = { T.x, T.y, T.rotation, T.scale }; - // for (int a = 0; a < 4; a++) { - // if (Property[a]->CurrentValue != Val[a]) { - // History_Entry_Commit(Memory, "Add keyframe"); - // bezier_point Point = { 1, {(real32)State->Frame_Current, Val[a], -1, 0, 1, 0}, interpolation_type_linear, 0, {0, 0, 0}, 0 }; - // uint16 *ArrayLocation = Property_GetSortedArray(SortedKeyframeArray, State->MostRecentlySelectedLayer, h); - // Bezier_Add(Memory, F_Layers, Property[a], Point, ArrayLocation); - // History_Entry_End(Memory); - // } - // } - // } else { - { - 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(State->Interact_Transform, &Layer->x.CurrentValue, &Layer->y.CurrentValue, &Layer->rotation.CurrentValue, &Layer->scale.CurrentValue); - } - } - } - // if (!io.KeyCtrl) - History_Entry_End(Memory); - State->Interact_Active = interact_type_none; - State->Interact_Modifier = 0; - State->UncommitedKeyframe = 1; - State->UpdateFrame = true; - } - - if (InBounds == true) { - ImGui::PopStyleColor(); - } - -} - static void ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImGuiIO &io, ImDrawList *draw_list, block_composition *MainComp, uint32 CompIndex, layer_transforms ExtraT, int *PointCount, v2 *PointData, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray) @@ -1034,7 +759,7 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImG } - if (Layer->IsShapeLayer && State->Tool == tool_default_pointmove && State->Interact_Active == interact_type_none ) { + if (Layer->IsShapeLayer && State->Tool == tool_default_pointmove && (State->Interact_Active == interact_type_none || State->Interact_Active == interact_type_keyframe_move) ) { ImGui_Viewport_ShapeUI(State, Memory, UI, io, Layer, Width, Height, &Layer->Shape, MainComp, draw_list); // point visualization @@ -1108,7 +833,7 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, bool open = true; ImGui::Begin("Viewport", &open, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse); - DebugWatchVar("Count: ", &State->PreviousSelectionCount, d_int); + // DebugWatchVar("Count: ", &State->PreviousSelectionCount, d_int); if (ImGui::IsWindowHovered(ImGuiFocusedFlags_ChildWindows)) { State->FocusedWindow = focus_viewport; @@ -1190,11 +915,7 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, int PointCount = 0; layer_transforms T = {}; ImGui_Viewport_SelectedLayerUI(State, Memory, UI, io, draw_list, MainComp, File->PrincipalCompIndex, T, &PointCount, PointData, SortedCompArray, SortedLayerArray); - if (State->Interact_Active == interact_type_viewport_transform) { - ImGui_Viewport_TransformUI(File, State, Memory, UI, io, draw_list, &State->Interact_Transform, ViewportMin, MainComp->Width, MainComp->Height, SortedKeyframeArray); - } else { - ImGui_Viewport_TransformUI2(File, State, Memory, UI, io, draw_list, &PointCount, PointData, ViewportMin, MainComp->Width, MainComp->Height, SortedCompArray, SortedLayerArray, SortedKeyframeArray); - } + ImGui_Viewport_TransformUI2(File, State, Memory, UI, io, draw_list, &PointCount, PointData, ViewportMin, MainComp->Width, MainComp->Height, SortedCompArray, SortedLayerArray, SortedKeyframeArray); Memory_PopScratch(Memory, sizeof(v2) * 512); } @@ -1340,15 +1061,13 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, State->Interact_Active = interact_type_none; } - /* if (State->Interact_Active == interact_type_viewport_transform) { - interact_transform *Interact = (interact_transform *)&State->Interact_Offset[0]; - ImVec2 DragDelta = io.MousePos - Interact->OGPos; - Interact->Position = V2(DragDelta.x, DragDelta.y); - if (io.MouseDelta.x || io.MouseDelta.y) - State->UpdateFrame = true; + if (io.MouseDelta.x || io.MouseDelta.y) + { + State->Interact_Offset[4] = io.MousePos.x; + State->Interact_Offset[5] = io.MousePos.y; + } } - */ if (IsActive && ImGui::IsMouseDragging(ImGuiMouseButton_Right, -1.0f)) { @@ -1385,6 +1104,9 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, } } + if (IsActive) + int a = 0; + if (State->Tool == tool_pen && State->Interact_Active == interact_type_none && State->MostRecentlySelectedLayer == -1) { v2 CompUV = State->LastClickedPoint; ImVec2 ScreenPoint = ImVec2(UI->CompPos.x + CompUV.x * UI->CompZoom.x, @@ -1453,17 +1175,39 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, MousePos = ScreenPointStart + ImVec2(Vector.x, Vector.x); } if (IsActive && !OtherActions) { - draw_list->AddRect(ScreenPointStart, MousePos, wcol, 2.0f); + if (State->ShapeMode == 0) { + draw_list->AddRect(ScreenPointStart, MousePos, wcol, 2.0f); + } else if (State->ShapeMode == 1) { + ImVec2 Radius = (MousePos - ScreenPointStart) / 2; + ImVec2 Center = ScreenPointStart + Radius; + real32 cx = Center.x; + real32 cy = Center.y; + real32 rx = Radius.x; + real32 ry = Radius.y; + draw_list->AddBezierCubic(ImVec2(cx-rx, cy), ImVec2(cx-rx, cy+ry*KAPPA), ImVec2(cx-rx*KAPPA, cy+ry), ImVec2(cx, cy+ry), wcol, 1.0f); + draw_list->AddBezierCubic(ImVec2(cx, cy+ry), ImVec2(cx+rx*KAPPA, cy+ry), ImVec2(cx+rx, cy+ry*KAPPA), ImVec2(cx+rx, cy), wcol, 1.0f); + draw_list->AddBezierCubic(ImVec2(cx+rx, cy), ImVec2(cx+rx, cy-ry*KAPPA), ImVec2(cx+rx*KAPPA, cy-ry), ImVec2(cx, cy-ry), wcol, 1.0f); + draw_list->AddBezierCubic(ImVec2(cx, cy-ry), ImVec2(cx-rx*KAPPA, cy-ry), ImVec2(cx-rx, cy-ry*KAPPA), ImVec2(cx-rx, cy), wcol, 1.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) }; - v2 *CompPoint = (v2 *)&State->Interact_Offset[0]; - for (int i = 0; i < 4; i++) { - CompPoint[i] = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, ScreenPoint[i]); - CompPoint[i] = CompPoint[i] * V2(MainComp->Width, MainComp->Height); + if (State->ShapeMode == 0) { + v2 *CompPoint = (v2 *)&State->Interact_Offset[0]; + for (int i = 0; i < 4; i++) { + CompPoint[i] = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, ScreenPoint[i]); + CompPoint[i] = CompPoint[i] * V2(MainComp->Width, MainComp->Height); + } + } else if (State->ShapeMode == 1) { + v2 CompMin = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, ScreenPointStart) * V2(MainComp->Width, MainComp->Height); + v2 CompMax = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, io.MousePos) * V2(MainComp->Width, MainComp->Height); + v2 Radius = (CompMax - CompMin) / 2; + v2 Center = CompMin + Radius; + *((v2 *)&State->Interact_Offset + 0) = Radius; + *((v2 *)&State->Interact_Offset + 1) = Center; } State->HotkeyInput = hotkey_newlayer_shape; - State->Interact_Modifier = 1; } } |