diff options
author | Fox Caminiti <fox@foxcam.net> | 2023-02-17 17:20:18 -0500 |
---|---|---|
committer | Fox Caminiti <fox@foxcam.net> | 2023-02-17 17:20:18 -0500 |
commit | 02870398a99fab6351182fba407d7d733affa5a1 (patch) | |
tree | fb5f4744f46e9d7816072e4d01547034bca04bb2 /src/createcalls.cpp | |
parent | fffb3474ee0321d73a47db01dbc4b6b19670ddc5 (diff) |
blend mode rendering halfway implemented
Diffstat (limited to 'src/createcalls.cpp')
-rw-r--r-- | src/createcalls.cpp | 148 |
1 files changed, 123 insertions, 25 deletions
diff --git a/src/createcalls.cpp b/src/createcalls.cpp index 56cf4d8..d7fb4b7 100644 --- a/src/createcalls.cpp +++ b/src/createcalls.cpp @@ -187,17 +187,116 @@ Source_Generate(project_data *File, project_state *State, memory *Memory, void * return -1; } - +#if WINDOWS +#else +#include <dirent.h> +static void +File_LoadDirectory(project_data *File, project_state *State, memory *Memory, char *DirString) +{ + DIR *Directory = opendir(DirString); + if (!Directory) { + PostMsg(State, "Directory couldn't be read."); + return; + } + for (;;) { + dirent *DirEnt = readdir(Directory); + if (DirEnt != NULL) { + if (DirEnt->d_name[0] != '.') { + char buf[1024]; + sprintf(buf, "%s/%s", DirString, DirEnt->d_name); + Source_Generate(File, State, Memory, buf); + } + } else { + closedir(Directory); + return; + } + } +} +#endif static void -Property_AddKeyframe(memory *Memory, memory_table_list TableName, property_channel *Property, int Frame, uint16 *ArrayLocation) +Property_AddKeyframe(memory *Memory, memory_table_list TableName, uint16 *ArrayLocation, property_channel *Property, int Frame) { History_Entry_Commit(Memory, "Add keyframe"); bezier_point Point = { 1, {(real32)Frame, Property->CurrentValue, -1, 0, 1, 0}, interpolation_type_linear, 0, {0, 0, 0}, 0 }; - Bezier_Add(Memory, TableName, Property, Point, ArrayLocation); + int Idx = Bezier_CheckSameX(Memory, TableName, Property->Block_Bezier_Index, Property->Keyframe_Count, ArrayLocation, Point.Pos[0].x); + if (Idx == -1) { + Bezier_Add(Memory, TableName, Property->Block_Bezier_Index, &Property->Block_Bezier_Count, &Property->Keyframe_Count, Point); + } else { + Assert(0); + } + History_Entry_End(Memory); +} + +// TODO(fox): Only works with transform keyframes for now! +static void +Property_AddKeyframe_AllSelected(project_data *File, project_state *State, memory *Memory, + memory_table_list TableName, sorted_layer_array *SortedLayerArray, sorted_comp_array *SortedCompArray, uint16 *SortedKeyframeArray, + uint16 Idx, int Frame) +{ + History_Entry_Commit(Memory, "Add keyframe"); + 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 & 0x01) { + sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(SortedLayerArray, SortedCompArray, Layer->Block_Composition_Index); + uint16 *ArrayLocation = SortedKeyframeArray + SortedLayerStart->SortedKeyframeStart; + property_channel *Property = &Layer->Property[Idx]; + bezier_point NewPoint = { 1, {(real32)Frame, Property->CurrentValue, -1, 0, 1, 0}, interpolation_type_linear, 0, {0, 0, 0}, 0 }; + int Idx = Bezier_CheckSameX(Memory, TableName, Property->Block_Bezier_Index, Property->Keyframe_Count, ArrayLocation, NewPoint.Pos[0].x); + if (Idx == -1) { + Bezier_Add(Memory, TableName, Property->Block_Bezier_Index, &Property->Block_Bezier_Count, &Property->Keyframe_Count, NewPoint); + } else { + bezier_point *Point = Bezier_LookupAddress(Memory, Property->Block_Bezier_Index, Idx); + History_Action_Swap(Memory, F_Bezier, sizeof(*Point), Point); + *Point = NewPoint; + } + } + } History_Entry_End(Memory); } +static void +Bezier_Delete_Selected(project_data *File, project_state *State, memory *Memory, + sorted_layer_array *SortedLayerArray, sorted_comp_array *SortedCompArray, + sorted_property_array *SortedPropertyStart, uint16 *SortedKeyframeArray) +{ + History_Entry_Commit(Memory, "Delete keyframes"); +#if 0 + for (int c = 0; c < File->Comp_Count; c++) { + sorted_comp_array SortedCompStart = SortedCompArray[c]; + sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(SortedLayerArray, SortedCompArray, c); + for (int i = 0; i < SortedCompStart.LayerCount; i++) { + sorted_layer_array *SortedLayer = &SortedLayerStart[i]; + block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, SortedLayer->Block_Layer_Index); + 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 ((State->TimelineMode != timeline_mode_graph) && !Property->IsToggled) + continue; + for (int p = 0; p < InfoLocation->KeyframeCount; p++) { + int k = ArrayLocation[p]; + bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property->Block_Bezier_Index, k); + if (PointAddress->IsSelected) { + History_Action_Swap(Memory, F_Bezier, sizeof(PointAddress->Occupied), &PointAddress->Occupied); + PointAddress->Occupied = 0; + History_Action_Swap(Memory, F_Layers, sizeof(*PointCount), PointCount); + *PointCount -= 1; + } + } + } + } + } +#endif + History_Entry_End(Memory); +} + + static property_channel Property_InitFloat(real32 Val, real32 ScrubVal, real32 MinVal, real32 MaxVal, bool32 AlwaysInteger) { property_channel Property = {}; @@ -311,9 +410,9 @@ Keyframe_Commit(project_data *File, project_state *State, memory *Memory, { if ((State->TimelineMode != timeline_mode_graph) && !Property->IsToggled) continue; - for (int p = 0; p < Property->Keyframe_Count; p++) { + for (int p = 0; p < InfoLocation->KeyframeCount; p++) { int k = ArrayLocation[p]; - bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, k); + bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property->Block_Bezier_Index, k); if (PointAddress->IsSelected) { v2 NewPos[3]; Bezier_Interact_Evaluate(State, PointAddress, NewPos); @@ -427,8 +526,8 @@ void Clipboard_Store(project_data *File, project_state *State, memory *Memory, s clipboard_channel *Channel = &Contents->Channel[Contents->ChannelCount]; bezier_point *FirstPoint = NULL; int TimeOffset = 0; - for (int p = 0; p < Property->Keyframe_Count; p++) { - bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[p]); + for (int p = 0; p < InfoLocation->KeyframeCount; p++) { + bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property->Block_Bezier_Index, ArrayLocation[p]); if (PointAddress->IsSelected) { if (!FirstPoint) { FirstPoint = PointAddress; @@ -488,27 +587,25 @@ void Slide_Test(project_data *File, project_state *State, memory *Memory, sorted block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, Interact_Layer->Index); v2 CompUV = V2(State->Interact_Offset[0], State->Interact_Offset[1]); v2 CompPos = CompUV * CompDimensions; - // v2 LayerPos = Layer_TraverseForPoint(File, State, Memory, CompUV, SortedCompArray, SortedLayerArray, Interact_Layer->Index); v2 LayerPos = V2(Layer->x.CurrentValue, Layer->y.CurrentValue); int Width, Height; Layer_GetDimensions(Memory, Layer, &Width, &Height); v2 Difference = V2(fabs(CompPos.x - LayerPos.x), fabs(CompPos.y - LayerPos.y)); printf("Diff: %.1f, %.1f\n", Difference.x, Difference.y); - if (Difference.x < Threshold && - Difference.y < Threshold) - Assert(0); + // if (Difference.x < Threshold && + // Difference.y < Threshold) } } -void Property_MinMax_X(memory *Memory, project_state *State, property_channel *Property, +void Property_MinMax_X(memory *Memory, project_state *State, uint16 *Block_Bezier_Index, uint16 LastIndex, uint16 *ArrayLocation, real32 *Min, real32 *Max) { v2 FirstPointPos[3]; - bezier_point *FirstPointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[0]); + bezier_point *FirstPointAddress = Bezier_LookupAddress(Memory, Block_Bezier_Index, ArrayLocation[0]); Bezier_Interact_Evaluate(State, FirstPointAddress, FirstPointPos); *Min = FirstPointPos[0].x; v2 LastPointPos[3]; - bezier_point *LastPointAddress = Bezier_LookupAddress(Memory, Property, ArrayLocation[Property->Keyframe_Count - 1]); + bezier_point *LastPointAddress = Bezier_LookupAddress(Memory, Block_Bezier_Index, ArrayLocation[LastIndex]); Bezier_Interact_Evaluate(State, LastPointAddress, LastPointPos); *Max = LastPointPos[0].x; } @@ -517,17 +614,17 @@ void Property_MinMax_Y(memory *Memory, project_state *State, property_channel *P { if (Evaluate) { v2 MinYPointPos[3]; - bezier_point *MinYPointAddress = Bezier_LookupAddress(Memory, Property, PropertyStart->MinYIndex); + bezier_point *MinYPointAddress = Bezier_LookupAddress(Memory, Property->Block_Bezier_Index, PropertyStart->MinYIndex); Bezier_Interact_Evaluate(State, MinYPointAddress, MinYPointPos); *Min = MinYPointPos[0].y; v2 MaxYPointPos[3]; - bezier_point *MaxYPointAddress = Bezier_LookupAddress(Memory, Property, PropertyStart->MaxYIndex); + bezier_point *MaxYPointAddress = Bezier_LookupAddress(Memory, Property->Block_Bezier_Index, PropertyStart->MaxYIndex); Bezier_Interact_Evaluate(State, MaxYPointAddress, MaxYPointPos); *Max = MaxYPointPos[0].y; } else { - bezier_point *MinYPointAddress = Bezier_LookupAddress(Memory, Property, PropertyStart->MinYIndex); + bezier_point *MinYPointAddress = Bezier_LookupAddress(Memory, Property->Block_Bezier_Index, PropertyStart->MinYIndex); *Min = MinYPointAddress->Pos[0].y; - bezier_point *MaxYPointAddress = Bezier_LookupAddress(Memory, Property, PropertyStart->MaxYIndex); + bezier_point *MaxYPointAddress = Bezier_LookupAddress(Memory, Property->Block_Bezier_Index, PropertyStart->MaxYIndex); *Max = MaxYPointAddress->Pos[0].y; } } @@ -645,9 +742,9 @@ void File_DeselectAllKeyframes(project_data *File, project_state *State, memory block_effect *Effect = NULL; while (Layer_LoopChannels(State, Memory, &InfoLocation, &ArrayLocation, Layer, &Property, &Effect, &h, &c, &p)) { - for (int p = 0; p < Property->Keyframe_Count; p++) { + for (int p = 0; p < InfoLocation->KeyframeCount; p++) { int k = ArrayLocation[p]; - bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, k); + bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property->Block_Bezier_Index, k); PointAddress->IsSelected = 0; } } @@ -678,12 +775,13 @@ Project_Layer_Delete(project_data *File, project_state *State, memory *Memory) } } +// TODO(fox): make property-agnostic static bool32 -Property_IsGraphSelected(memory *Memory, property_channel *Property, uint16 *ArrayLocation) +Property_IsGraphSelected(memory *Memory, uint16 *Block_Bezier_Index, uint16 *ArrayLocation, uint16 KeyframeCount) { - for (int p = 0; p < Property->Keyframe_Count; p++) { + for (int p = 0; p < KeyframeCount; p++) { int k = ArrayLocation[p]; - bezier_point *Point = Bezier_LookupAddress(Memory, Property, k); + bezier_point *Point = Bezier_LookupAddress(Memory, Block_Bezier_Index, k); if (Point->IsSelected) return 1; } @@ -1054,8 +1152,8 @@ void Precomp_UICreateButton(project_data *File, project_state *State, memory *Me block_layer *PrecompLayer = Layer_Init(File, Memory); bezier_point Point0 = { 1, {0, 0, 1, 0, 1, 0}, interpolation_type_linear, 0, {0, 0, 0}, 0 }; bezier_point Point1 = { 1, {(real32)NewComp->Frame_End, (real32)NewComp->Frame_End, 1, 0, 1, 0}, interpolation_type_linear, 0, {0, 0, 0}, 0 }; - Bezier_Add(Memory, F_Layers, &PrecompLayer->time, Point0, NULL); - Bezier_Add(Memory, F_Layers, &PrecompLayer->time, Point1, NULL); + Bezier_Add(Memory, F_Layers, PrecompLayer->time.Block_Bezier_Index, &PrecompLayer->time.Block_Bezier_Count, &PrecompLayer->time.Keyframe_Count, Point0); + Bezier_Add(Memory, F_Layers, PrecompLayer->time.Block_Bezier_Index, &PrecompLayer->time.Block_Bezier_Count, &PrecompLayer->time.Keyframe_Count, Point1); PrecompLayer->IsPrecomp = true; Layer_Select(Memory, State, Memory_Block_LazyIndexAtAddress(Memory, F_Layers, PrecompLayer)); PrecompLayer->Block_Source_Index = File->Comp_Count - 1; |