#if SPECIAL #include "main.h" #endif static property_channel Property_InitFloat(real32 Val, real32 ScrubVal, real32 MinVal = PROPERTY_REAL_MIN, real32 MaxVal = PROPERTY_REAL_MAX, bool32 AlwaysInteger = 0); static block_layer * Layer_Init(project_data *File, memory *Memory) { if (File->Layer_Count + 1 > MAX_LAYERS) { Assert(0); } block_layer *Layer = (block_layer *)Memory_Block_AllocateAddress(Memory, F_Layers); History_Action_Block_Swap(Memory, F_Layers, Layer); *Layer = {}; Layer->Occupied = 1; Layer->Block_String_Index = Memory_Block_AllocateNew(Memory, F_Strings); block_string *String = (block_string *)Memory_Block_AddressAtIndex(Memory, F_Strings, Layer->Block_String_Index, 0); sprintf(String->Char, "Layer %i", File->Layer_Count + 1); // CSbros... History_Action_Swap(Memory, F_Strings, sizeof(String->Occupied), &String->Occupied); String->Occupied = 1; Layer->x = Property_InitFloat(0.0f, 1.0f); Layer->y = Property_InitFloat(0.0f, 1.0f); Layer->ax = Property_InitFloat(0.5f, 0.005f); Layer->ay = Property_InitFloat(0.5f, 0.005f); Layer->scale = Property_InitFloat(1.0f, 0.005f); Layer->rotation = Property_InitFloat(0.0f, 1.0f); Layer->opacity = Property_InitFloat(1.0f, 0.005f, 0.0f, 1.0f); Layer->time = Property_InitFloat(0.0f, 1.0f, 0, 100000, 1); Layer->IsVisible = 1; History_Action_Swap(Memory, F_File, sizeof(File->Layer_Count), &File->Layer_Count); File->Layer_Count++; return Layer; } // lots of cleanup... static void Layer_Delete(project_data *File, project_state *State, memory *Memory, uint32 Index) { block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, Index); History_Action_Block_Swap(Memory, F_Layers, Layer); Layer->Occupied = 0; block_string *String = (block_string *)Memory_Block_AddressAtIndex(Memory, F_Strings, Layer->Block_String_Index, 0); History_Action_Block_Swap(Memory, F_Strings, String); String->Occupied = 0; for (int i = 0; i < Layer->Block_Effect_Count; i++) { block_effect *Effect = (block_effect *)Memory_Block_AddressAtIndex(Memory, F_Effects, Layer->Block_Effect_Index[i]); header_effect *EffectHeader = Effect_EntryFromID(State, Effect->ID); for (int h = 0; h < EffectHeader->Property_Count; h++) { header_property ChannelHeader = State->Property[EffectHeader->PropertyStartIndex + h]; property_channel *Property = (property_channel *)Memory_Block_AddressAtIndex(Memory, F_Properties, Effect->Block_Property_Index[h]); if (Property->Block_Bezier_Count) { block_bezier *Bezier = (block_bezier *)Memory_Block_AddressAtIndex(Memory, F_Bezier, Property->Block_Bezier_Index[i], 0); History_Action_Block_Swap(Memory, F_Bezier, Bezier); Bezier->Occupied = 0; } History_Action_Block_Swap(Memory, F_Properties, Property); Property->Occupied = 0; } History_Action_Block_Swap(Memory, F_Effects, Effect); Effect->Occupied = 0; } History_Action_Swap(Memory, F_File, sizeof(File->Layer_Count), &File->Layer_Count); File->Layer_Count--; } static layer_transforms Layer_GetTransforms(block_layer *Layer) { return { Layer->x.CurrentValue, Layer->y.CurrentValue, Layer->ax.CurrentValue, Layer->ay.CurrentValue, Layer->rotation.CurrentValue, Layer->scale.CurrentValue }; } static int Layer_GetTopOffset(project_data *File, memory *Memory) { if (File->Layer_Count == 0) return 11; int TopOffset = 9999; int h = 0, c = 0, i = 0; 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->Block_Composition_Index == File->PrincipalCompIndex) { TopOffset = (Layer->Vertical_Offset < TopOffset) ? Layer->Vertical_Offset : TopOffset; } } return TopOffset; } static void Layer_UpdateMasksEffects(project_state *State, block_layer *Layer, memory *Memory, void *EffectBitmapAddress, int Width, int Height, int BytesPerPixel) { uint64 Size = Width*Height*BytesPerPixel; // We need two of these: one with multisampling enabled and a // non-multisampled one that we can blit to. gl_effect_layer TestL = {}; gl_effect_layer TestM = {}; GL_UpdateTexture(&TestL, EffectBitmapAddress, Width, Height, BytesPerPixel, 0); GL_UpdateTexture(&TestM, EffectBitmapAddress, Width, Height, BytesPerPixel, 1); if (Layer->IsShapeLayer) { shape_layer *Shape = &Layer->Shape; void *Data = Memory_PushScratch(Memory, sizeof(nvg_point) * 128); Arbitrary_Zero((uint8 *)Data, sizeof(nvg_point) * 128); layer_transforms T = Layer_GetTransforms(Layer); v2 Min = {}, Max = {}; uint32 NumberOfVerts = NVG_FlattenPath(Memory, Shape, (nvg_point *)Data, State, T, Shape->Width, Shape->Height, Width, Height, 1, &Min, &Max); void *Data_Stroke = Memory_PushScratch(Memory, sizeof(real32) * 4 * 256); uint32 StrokeCount = NVG_ExpandStroke(Memory, NumberOfVerts, Shape->Opt.StrokeWidth, Shape->Opt.LineCapType, Shape->Opt.LineJoinType, Shape->IsClosed, (nvg_point *)Data, (real32 *)Data_Stroke); void *Data_Fill = Memory_PushScratch(Memory, sizeof(real32) * 4 * NumberOfVerts); NVG_ExpandFill(Memory, NumberOfVerts, (nvg_point *)Data, (real32 *)Data_Fill); Assert(0); // GL_RasterizeShape(&TestL, &TestM, Data_Stroke, Data_Fill, StrokeCount, NumberOfVerts, T, // Width, Height, BytesPerPixel, EffectBitmapAddress, Shape->Width, Shape->Height, // Shape->Opt.StrokeCol, Shape->Opt.FillCol, Shape->Opt.Visibility); Memory_PopScratch(Memory, sizeof(real32) * 4 * NumberOfVerts); Memory_PopScratch(Memory, sizeof(real32) * 4 * 256); Memory_PopScratch(Memory, sizeof(nvg_point) * 128); // Bitmap_StencilAlpha(SourceBitmapAddress, EffectBitmapAddress, Source->BytesPerPixel, Size); } for (int i = 0; i < Layer->Block_Effect_Count; i++) { block_effect Effect = *(block_effect *)Memory_Block_AddressAtIndex(Memory, F_Effects, Layer->Block_Effect_Index[i]); header_effect *EffectEntry = Effect_EntryFromID(State, Effect.ID); if (Effect.IsToggled) { uint64 Size = (sizeof(real32) * MAX_PROPERTIES_PER_EFFECT) + (sizeof(real32) * 10); real32 *Data; if (EffectEntry->DisplayType == effect_display_type_curves) { Data = (real32 *)Memory_PushScratch(Memory, Size); uint16 SortedPointIndex[MAX_PROPERTIES_PER_EFFECT]; v2 *SortedPointValues = (v2 *)(Data + 5); for (int c = 0; c < 5; c++) { *(Data + c) = Effect.ExtraData[c]; uint32 Shift = MAX_PROPERTIES_PER_EFFECT / 5 * c; uint16 *SortedPointIndexPlayhead = SortedPointIndex + Shift; v2 *SortedPointValuesPlayhead = SortedPointValues + Shift; Effect_Curves_Sort(Memory, &Effect, SortedPointIndexPlayhead, c); for (int a = 0; a < Effect.ExtraData[c]; a++) { *SortedPointValuesPlayhead = Effect_V2(Memory, &Effect, SortedPointIndexPlayhead[a]); SortedPointValuesPlayhead++; } } } else { Data = (real32 *)Memory_PushScratch(Memory, Size); for (int c = 0; c < EffectEntry->Property_Count; c++) { property_channel *Property = (property_channel *)Memory_Block_AddressAtIndex(Memory, F_Properties, Effect.Block_Property_Index[c]); Data[c] = Property->CurrentValue; } } EffectEntry->func(Data, Width, Height, BytesPerPixel, EffectBitmapAddress, EffectEntry->GLShaderIndex); Memory_PopScratch(Memory, Size); } } GL_DeleteHWBuffer(&TestL); GL_DeleteHWBuffer(&TestM); } static void Layer_ToggleChannel(project_data *File, memory *Memory, int32 a) { int h = 0, c = 0, i = 0; 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 == 1) Layer->Property[a].IsToggled ^= 1; } } static void Layer_Select(memory *Memory, project_state *State, int32 i) { block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i); Layer->IsSelected = true; State->MostRecentlySelectedLayer = i; State->RecentSelectionType = selection_type_layer; } static void Layer_Select_RecurseUp(memory *Memory, project_state *State, int32 i, int16 RecursionIdx[MAX_PRECOMP_RECURSIONS], uint32 Recursions) { for (int a = 1; a <= Recursions; a++) { block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, RecursionIdx[a]); Layer->IsSelected = 2; } } static void Layer_DeselectAll(project_data *File, project_state *State, memory *Memory) { int h = 0, c = 0, i = 0; while (Block_Loop(Memory, F_Layers, File->Layer_Count, &h, &c, &i)) { block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i); Layer->IsSelected = false; } State->MostRecentlySelectedLayer = -1; } // TODO(fox): This function will be replaced once properties are reworked. // h: index of the total amount of properties and effects // c: index of the amount of properties in a given effect // p: prior property's keyframe count, so we can increment the sorted keyframe array properly static bool32 Layer_LoopChannels(project_state *State, memory *Memory, sorted_property_array **SortedProperty, uint16 **SortedKeyframe, block_layer *Layer, property_channel **Property, block_effect **EffectOut, int *h, int *c, int *p, int LoopNumber) { uint32 Amount = LoopNumber + Layer->Block_Effect_Count; // Assert(Layer->Block_Effect_Count < 2); while (*h < Amount) { if (*h < LoopNumber && *c == 0) { *Property = &Layer->Property[*h]; if (*h != 0) { *SortedProperty += 1; *SortedKeyframe += *p; } *h += 1; *p = (**Property).Keyframe_Count; return 1; } else { uint16 EffectIdx = Layer->Block_Effect_Index[*h - AmountOf(Layer->Property)]; block_effect *Effect = (block_effect *)Memory_Block_AddressAtIndex(Memory, F_Effects, EffectIdx); if (EffectOut) *EffectOut = Effect; header_effect *EffectHeader = Effect_EntryFromID(State, Effect->ID); while (*c < EffectHeader->Property_Count) { // header_property ChannelHeader = State->Property[EffectHeader->PropertyStartIndex + c]; *Property = (property_channel *)Memory_Block_AddressAtIndex(Memory, F_Properties, Effect->Block_Property_Index[*c]); *SortedProperty += 1; *SortedKeyframe += *p; *p = (**Property).Keyframe_Count; *c += 1; return 1; } *h += 1; *c = 0; } } Assert(*h != (Amount - 1)); return 0; } static void Layer_ToggleAllChannels(project_state *State, memory *Memory, block_layer *Layer, sorted_comp_array *SortedCompStart, sorted_layer_array *SortedLayerStart, sorted_property_array *SortedPropertyStart, uint16 *SortedKeyframeArray) { bool32 ToggleMode = 1; { sorted_property_array *InfoLocation = SortedPropertyStart + SortedLayerStart->SortedPropertyStart; uint16 *ArrayLocation = SortedKeyframeArray + SortedLayerStart->SortedKeyframeStart; int h = 0, c = 0, p = 0; property_channel *Property = NULL; block_effect *Effect = NULL; while (Layer_LoopChannels(State, Memory, &InfoLocation, &ArrayLocation, Layer, &Property, &Effect, &h, &c, &p)) { if (Property->IsToggled) { ToggleMode = 0; break; } } } sorted_property_array *InfoLocation = SortedPropertyStart + SortedLayerStart->SortedPropertyStart; uint16 *ArrayLocation = SortedKeyframeArray + SortedLayerStart->SortedKeyframeStart; int h = 0, c = 0, p = 0; property_channel *Property = NULL; block_effect *Effect = NULL; while (Layer_LoopChannels(State, Memory, &InfoLocation, &ArrayLocation, Layer, &Property, &Effect, &h, &c, &p)) { if (Property->Keyframe_Count) { Property->IsToggled = ToggleMode; } } } static void Layer_Select_Traverse(uint16 PrincipalCompIndex, memory *Memory, project_state *State, int32 IndexToFind, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, int16 RecursionIdx[MAX_PRECOMP_RECURSIONS], int32 *Recursions) { uint16 CompIndex = 0; if (RecursionIdx[*Recursions] == -1) { CompIndex = PrincipalCompIndex; } else { block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, RecursionIdx[*Recursions]); CompIndex = Layer->Block_Source_Index; } sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(SortedLayerArray, SortedCompArray, CompIndex); sorted_comp_array SortedCompStart = SortedCompArray[CompIndex]; uint32 RecursionsCurrent = *Recursions; 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); if (Layer->IsPrecomp && Layer->IsSelected == 2) { *Recursions = RecursionsCurrent + 1; RecursionIdx[*Recursions] = Index_Physical; Layer_Select_Traverse(PrincipalCompIndex, Memory, State, IndexToFind, SortedCompArray, SortedLayerArray, RecursionIdx, Recursions); } else if (Index_Physical == IndexToFind) { return; } } } static void Layer_GetDimensions(memory *Memory, block_layer *Layer, int *Width, int *Height) { if (Layer->IsPrecomp) { block_composition *Comp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, Layer->Block_Source_Index); *Width = Comp->Width; *Height = Comp->Height; } else if (Layer->IsShapeLayer) { *Width = Layer->Shape.Width; *Height = Layer->Shape.Height; } else { block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, Layer->Block_Source_Index); *Width = Source->Width; *Height = Source->Height; } } static v2 Layer_TraverseForPoint(project_data *File, project_state *State, memory *Memory, v2 PrincipalCompUV, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray) { int16 RecursionIdx[MAX_PRECOMP_RECURSIONS] = {}; RecursionIdx[0] = -1; int32 Recursions = 0; sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(SortedLayerArray, SortedCompArray, File->PrincipalCompIndex); sorted_comp_array SortedCompStart = SortedCompArray[File->PrincipalCompIndex]; block_composition *Comp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, File->PrincipalCompIndex); Layer_Select_Traverse(File->PrincipalCompIndex, Memory, State, State->Brush.LayerToPaint_Index, SortedCompArray, SortedLayerArray, RecursionIdx, &Recursions); v2 PointUV = {0, 0}; int OuterWidth = Comp->Width, OuterHeight = Comp->Height; int InnerWidth = 0, InnerHeight = 0; if (Recursions == 0) { block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, State->Brush.LayerToPaint_Index); layer_transforms T = Layer_GetTransforms(Layer); Layer_GetDimensions(Memory, Layer, &InnerWidth, &InnerHeight); PointUV = T_CompUVToLayerUV(T, OuterWidth, OuterHeight, InnerWidth, InnerHeight, PrincipalCompUV); } else { for (int i = 1; i <= Recursions; i++) { block_layer *InnerLayer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, RecursionIdx[i]); layer_transforms T = Layer_GetTransforms(InnerLayer); Layer_GetDimensions(Memory, InnerLayer, &InnerWidth, &InnerHeight); PointUV = T_CompUVToLayerUV(T, OuterWidth, OuterHeight, InnerWidth, InnerHeight, PrincipalCompUV); OuterWidth = InnerWidth; OuterHeight = InnerHeight; } } return PointUV * V2(InnerWidth, InnerHeight); } // TODO(fox): Precomps? static int32 Layer_TestSelection(memory *Memory, project_state *State, ui *UI, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, uint16 PrincipalIndex) { 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); int SelectionCount = 0; int SelectedLayerIndex = 0; 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, State->LastClickedPoint); if (UV.x <= 1.0f && UV.x >= 0.0f && UV.y <= 1.0f && UV.y >= 0.0f && Layer->IsSelected) { SelectionCount++; SelectedLayerIndex = i; } } int32 LayerIndex = -1; 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, State->LastClickedPoint); if (UV.x <= 1.0f && UV.x >= 0.0f && UV.y <= 1.0f && UV.y >= 0.0f && !Layer->IsSelected) { if (SelectionCount == 1) { if (i < SelectedLayerIndex) { LayerIndex = Index_Physical; break; } } else { LayerIndex = Index_Physical; break; } } // if (Layer->IsPrecomp) { // Layer_RecursiveDeselect(Memory, SortedCompArray, SortedLayerArray, TargetIndex, Layer->Block_Source_Index); // } // if (Layer->Block_Composition_Index != TargetIndex) { // Layer->IsSelected = false; // } } return LayerIndex; } static bool32 Shape_TestBoxSelect(v2 Min, v2 Max, bezier_point *BezierPointData, uint32 BezierCount) { v2 StartMin = V2(1000, 1000); v2 StartMax = V2(-1000, -1000); v2 ClosestPoint[4] = { StartMin, StartMax, V2(StartMin.x, StartMax.y), V2(StartMax.y, StartMin.x) }; for (int i = 0; i < BezierCount; i++) { bezier_point *Point = &BezierPointData[i]; if (i == 0 || Point->Type == interpolation_type_linear) { if ((Point->Pos[0].x > Min.x) && (Point->Pos[0].x < Max.x) && (Point->Pos[0].x > Min.y) && (Point->Pos[0].x < Max.y)) Assert(0); } else if (Point->Type == interpolation_type_bezier) { Assert(0); /* bezier_point *Point_1 = &BezierPointData[i-1]; v2 Pos[2] = { Point_1->Pos[0], Point->Pos[0] }; PointPlayhead = (nvg_point *)Bezier_CubicCalcPoints(Pos[0], Pos[0] + Point_1->Pos[1], Pos[1] + Point->Pos[2], Pos[1], PointPlayhead, sizeof(nvg_point)); */ } else { Assert(0); } } return false; } // v2 Bezier_LineClose // stPoint(v2 a, v2 b, v2 p); // char get_line_intersection(float p0_x, float p0_y, float p1_x, float p1_y, // float p2_x, float p2_y, float p3_x, float p3_y, float *i_x, float *i_y) #if 0 char T_TestLine(v2 Point[4]) { /* float s1_x, s1_y, s2_x, s2_y; s1_x = p1_x - p0_x; s1_y = p1_y - p0_y; s2_x = p3_x - p2_x; s2_y = p3_y - p2_y; */ v2 Vector0 = Point[1] - Point[0]; v2 Vector1 = Point[3] - Point[2]; Vector1 * (Point[0] - Point[2]) / Side0 = (-s1_y * (p0_x - p2_x) + s1_x * (p0_y - p2_y)) float s, t; s = (-s1_y * (p0_x - p2_x) + s1_x * (p0_y - p2_y)) / (-s2_x * s1_y + s1_x * s2_y); t = ( s2_x * (p0_y - p2_y) - s2_y * (p0_x - p2_x)) / (-s2_x * s1_y + s1_x * s2_y); if (s >= 0 && s <= 1 && t >= 0 && t <= 1) { // Collision detected if (i_x != NULL) *i_x = p0_x + (t * s1_x); if (i_y != NULL) *i_y = p0_y + (t * s1_y); return 1; } return 0; // No collision } #endif static bool32 Transform_TestBox(block_layer *Layer, uint32 Width, uint32 Height, v2 Min, v2 Max) { real32 Rad = (Layer->rotation.CurrentValue * (PI / 180)); real32 s = Layer->scale.CurrentValue; v2 XAxis = (Width * s)*V2(cos(Rad), sin(Rad)); v2 YAxis = (Height * -s)*V2(sin(Rad), -cos(Rad)); real32 AnchorX = Layer->ax.CurrentValue; real32 AnchorY = Layer->ay.CurrentValue; v2 Pos = {Layer->x.CurrentValue, Layer->y.CurrentValue}; v2 Origin = Pos - (XAxis * AnchorX) - (YAxis * AnchorY); real32 XLengthSq = 1.0f / LengthSq(XAxis); real32 YLengthSq = 1.0f / LengthSq(YAxis); v2 Box[4] = { Min, V2(Min.x, Max.y), Max, V2(Max.x, Min.y) }; v2 Point[4] = {Origin, Origin + YAxis, Origin + XAxis + YAxis, Origin + XAxis }; if (Length((Max - Min)) < 2.0f) return false; v2 *P1_B = &Box[3]; v2 *P2_B = &Box[0]; for (int x = 0; x < 4; x++) { v2 *P1 = &Point[3]; v2 *P2 = &Point[0]; for (int i = 0; i < 4; i++) { // v2 ClosestLayer = Bezier_LineClosestPoint(*P1, *P2, *P1_B); // v2 ClosestBox = Bezier_LineClosestPoint(*P1_B, *P2_B, *P1); // if (abs(ClosestLayer.x - ClosestBox.x) < 1.0f && // abs(ClosestLayer.y - ClosestBox.y) < 1.0f) // return true; // P1 = P2++; } P1_B = P2_B++; } return false; } static void Layer_TestBoxSelect(memory *Memory, project_state *State, ui *UI, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, uint16 PrincipalIndex, v2 MinPos, v2 MaxPos) { 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); if (Layer->IsShapeLayer) { shape_layer *Shape = &Layer->Shape; int Width = Shape->Width, Height = Shape->Height; layer_transforms T = Layer_GetTransforms(Layer); v2 MinUV = T_CompUVToLayerUV(T, Comp->Width, Comp->Height, Width, Height, MinPos); v2 MaxUV = T_CompUVToLayerUV(T, Comp->Width, Comp->Height, Width, Height, MaxPos); bezier_point *BezierPointData = (bezier_point *)Memory_PushScratch(Memory, sizeof(bezier_point) * 128); uint32 BezierCount = Bezier_Shape_Sort(Memory, Shape, BezierPointData, State, T, Width, Height, Comp->Width, Comp->Height, 0); Shape_TestBoxSelect(MinPos, MaxPos, BezierPointData, BezierCount); Memory_PopScratch(Memory, sizeof(bezier_point) * 128); } else { int Width, Height; Layer_GetDimensions(Memory, Layer, &Width, &Height); if (Transform_TestBox(Layer, Width, Height, MinPos, MaxPos)) Layer->IsSelected = true; } } } static void Layer_RecursiveDeselect(memory *Memory, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, uint16 TargetIndex, uint16 PrincipalIndex) { 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 = 0; i < SortedCompStart.LayerCount; 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); if (Layer->IsPrecomp) { Layer_RecursiveDeselect(Memory, SortedCompArray, SortedLayerArray, TargetIndex, Layer->Block_Source_Index); } if (Layer->Block_Composition_Index != TargetIndex) { Layer->IsSelected = false; } } }