summaryrefslogtreecommitdiff
path: root/src/createcalls.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/createcalls.cpp')
-rw-r--r--src/createcalls.cpp39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/createcalls.cpp b/src/createcalls.cpp
index 4bdd6d7..cd8f3d5 100644
--- a/src/createcalls.cpp
+++ b/src/createcalls.cpp
@@ -610,7 +610,7 @@ Property_IsGraphSelected(memory *Memory, property_channel *Property, uint16 *Arr
}
static void
-Project_ShapeLayer_New(project_data *File, project_state *State, memory *Memory, v2 Point, v2 Vector)
+Project_ShapeLayer_New(project_data *File, project_state *State, memory *Memory)
{
int TopOffset = Layer_GetTopOffset(File, Memory);
block_composition *MainComp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, File->PrincipalCompIndex);
@@ -618,8 +618,6 @@ Project_ShapeLayer_New(project_data *File, project_state *State, memory *Memory,
History_Entry_Commit(Memory, "New shape layer");
block_layer *Layer = Layer_Init(File, Memory);
Layer->IsShapeLayer = true;
- Layer->x.CurrentValue = MainComp->Width / 2;
- Layer->y.CurrentValue = MainComp->Height / 2;
if (File->Layer_Count == 1) {
Layer->Vertical_Offset = 11 - 1;
} else {
@@ -629,17 +627,32 @@ Project_ShapeLayer_New(project_data *File, project_state *State, memory *Memory,
Layer->Frame_End = MainComp->Frame_End;
Layer_Select(Memory, State, Memory_Block_LazyIndexAtAddress(Memory, F_Layers, Layer));
- Layer->Shape.Block_Bezier_Index[0] = Memory_Block_AllocateNew(Memory, F_Bezier);
- block_bezier *Bezier = (block_bezier *)Memory_Block_AddressAtIndex(Memory, F_Bezier, Layer->Shape.Block_Bezier_Index[0], 0);
- Bezier->Occupied = true;
- v2 BezierPoint[3] = { Point, V2(000, 000), V2(000, 000) };
- interpolation_type Type = interpolation_type_linear;
- if (Vector.x) {
- BezierPoint[1] = Vector;
- BezierPoint[2] = Vector * -1;
- Type = interpolation_type_bezier;
+ v2 Min = V2(10000, 10000);
+ v2 Max = V2(-10000, -10000);
+ shape_layer *Shape = &File->UI.Shape;
+ for (int i = 0; i < Shape->Point_Count; i++) {
+ bezier_point *Point = Bezier_LookupAddress(Memory, Shape->Block_Bezier_Index, i, 1);
+ if (Point->Pos[0].x > Max.x)
+ Max.x = Point->Pos[0].x;
+ if (Point->Pos[0].x < Min.x)
+ Min.x = Point->Pos[0].x;
+ if (Point->Pos[0].y > Max.y)
+ Max.y = Point->Pos[0].y;
+ if (Point->Pos[0].y < Min.y)
+ Min.y = Point->Pos[0].y;
}
- Bezier->Point[0] = { 1, { BezierPoint[0], BezierPoint[1], BezierPoint[2] }, Type, 0 };
+ v2 ShapeSize = (Max - Min);
+ Layer->x.CurrentValue = Min.x + (ShapeSize.x / 2);
+ Layer->y.CurrentValue = Min.y + (ShapeSize.y / 2);
+ for (int i = 0; i < Shape->Point_Count; i++) {
+ bezier_point *Point = Bezier_LookupAddress(Memory, Shape->Block_Bezier_Index, i, 1);
+ Point->Pos[0] = Point->Pos[0] - Min;
+ }
+
+ History_Action_Swap(Memory, F_Layers, sizeof(Layer->Shape), &Layer->Shape);
+ Layer->Shape = File->UI.Shape;
+ History_Action_Swap(Memory, F_File, sizeof(File->UI.Shape), &File->UI.Shape);
+ File->UI.Shape = {};
History_Entry_End(Memory);
State->UpdateFrame = true;