From d6e916319a050070c53eb283470a3fd4833392a0 Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Fri, 27 Jan 2023 18:36:05 -0500 Subject: corner scaling --- src/layer.cpp | 55 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'src/layer.cpp') diff --git a/src/layer.cpp b/src/layer.cpp index 591487e..3686d75 100644 --- a/src/layer.cpp +++ b/src/layer.cpp @@ -370,6 +370,29 @@ Layer_TraverseForPoint(project_data *File, project_state *State, memory *Memory, return PointUV * V2(InnerWidth, InnerHeight); } +// TODO(fox): Precomps? +static bool32 +Layer_TestForPoint(memory *Memory, project_state *State, ui *UI, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, uint16 PrincipalIndex, v2 CompUV) +{ + block_composition *Comp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, PrincipalIndex); + sorted_comp_array SortedCompStart = SortedCompArray[PrincipalIndex]; + sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(SortedLayerArray, SortedCompArray, PrincipalIndex); + for (int i = SortedCompStart.LayerCount - 1; i >= 0; i--) { + sorted_layer_array SortEntry = SortedLayerStart[i]; + uint32 Index_Physical = SortEntry.Block_Layer_Index; + block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, Index_Physical); + int Width, Height; + Layer_GetDimensions(Memory, Layer, &Width, &Height); + layer_transforms T = Layer_GetTransforms(Layer); + v2 UV = T_CompUVToLayerUV(T, Comp->Width, Comp->Height, Width, Height, CompUV); + if (UV.x <= 1.0f && UV.x >= 0.0f && UV.y <= 1.0f && UV.y >= 0.0f && Layer->IsSelected) + { + return 1; + } + } + return 0; +} + // TODO(fox): Precomps? static int32 Layer_TestSelection(memory *Memory, project_state *State, ui *UI, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, uint16 PrincipalIndex) @@ -513,6 +536,8 @@ Shape_TestBoxSelect(layer_transforms T, uint32 CompWidth, uint32 CompHeight, uin P0->x = Pos0.x; P0->y = Pos0.y; } +#endif +#if 1 nvg_point *P0 = &Point[PointCount-1]; nvg_point *P1 = &Point[0]; for (int i = 0; i < PointCount; i++) { @@ -526,32 +551,8 @@ Shape_TestBoxSelect(layer_transforms T, uint32 CompWidth, uint32 CompHeight, uin return true; P0 = P1++; } - return false; -#else - v2 *P0_B = &Box[3]; - v2 *P1_B = &Box[0]; - for (int x = 0; x < 4; x++) { - nvg_point *P0 = &Point[PointCount-1]; - v2 Pos0 = TransformPoint(T, ShapeWidth, ShapeHeight, V2(P0->x, P0->y)); - if (Pos0.x > Box[0].x && Pos0.x < Box[2].x && - Pos0.y > Box[0].y && Pos0.y < Box[2].y) - return true; - P0->x = Pos0.x; - P0->y = Pos0.y; - nvg_point *P1 = &Point[0]; - for (int i = 0; i < PointCount; i++) { - v2 Pos1 = TransformPoint(T, ShapeWidth, ShapeHeight, V2(P1->x, P1->y)); - if (Pos1.x > Box[0].x && Pos1.x < Box[2].x && - Pos1.y > Box[0].y && Pos1.y < Box[2].y) - return true; - if (Line_TestIntersect(P0->x, P0->y, P1->x, P1->y, P0_B->x, P0_B->y, P1_B->x, P1_B->y)) - return true; - P0 = P1++; - } - P0_B = P1_B++; - } - return false; #endif + return false; } static void @@ -575,8 +576,8 @@ Layer_TestBoxSelect(memory *Memory, project_state *State, ui *UI, sorted_comp_ar uint32 NumberOfVerts = NVG_FlattenPath(Memory, Shape, Layer->ShapeOpt, NVGPointData, State, T, Shape->Width, Shape->Height, Comp->Width, Comp->Height, 1, &ShapeMin, &ShapeMax); v2 Box[4] = { MinPos, V2(MinPos.x, MaxPos.y), MaxPos, V2(MaxPos.x, MinPos.y) }; - if (Shape_TestBoxSelect(T, Comp->Width, Comp->Height, Shape->Height, Shape->Width, Box, NVGPointData, NumberOfVerts)) { - Layer_Select(Memory, State, i); + if (Shape_TestBoxSelect(T, Comp->Width, Comp->Height, Shape->Width, Shape->Height, Box, NVGPointData, NumberOfVerts)) { + Layer_Select(Memory, State, Index_Physical); } Memory_PopScratch(Memory, sizeof(nvg_point) * 1024); -- cgit v1.2.3