summaryrefslogtreecommitdiff
path: root/createcalls.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'createcalls.cpp')
-rw-r--r--createcalls.cpp204
1 files changed, 120 insertions, 84 deletions
diff --git a/createcalls.cpp b/createcalls.cpp
index d6cfc6c..1e96c74 100644
--- a/createcalls.cpp
+++ b/createcalls.cpp
@@ -190,7 +190,8 @@ Bezier_EvaluateValue(project_state *State, bezier_point *PointAddress, v2 *Pos,
Pos[2] = PointAddress->Pos[2];
if (PointAddress->IsSelected) {
if (State->Interact_Active == interact_type_keyframe_move) {
- Pos[PointAddress->IsSelected - 1].x += (int32)State->Interact_Offset[0];
+ if (State->Interact_Modifier != 2)
+ Pos[PointAddress->IsSelected - 1].x += (int32)State->Interact_Offset[0];
if (State->Interact_Modifier != 1)
Pos[PointAddress->IsSelected - 1].y -= (State->Interact_Offset[1] / GraphZoomHeight / Y_Increment);
} else if (State->Interact_Active == interact_type_keyframe_scale) {
@@ -205,7 +206,7 @@ Bezier_EvaluateValue(project_state *State, bezier_point *PointAddress, v2 *Pos,
static void
-Bezier_Add(memory *Memory, property_channel *Property, bezier_point PointData)
+Bezier_Add(memory *Memory, property_channel *Property, bezier_point PointData, uint16 *ArrayLocation)
{
if (!Property->Block_Bezier_Count) {
Property->Block_Bezier_Index[0] = Memory_Block_AllocateNew(Memory, F_Bezier);
@@ -215,6 +216,18 @@ Bezier_Add(memory *Memory, property_channel *Property, bezier_point PointData)
History_Action_Swap(Memory, F_Layers, sizeof(Property->Block_Bezier_Count), &Property->Block_Bezier_Count);
Property->Block_Bezier_Count++;
}
+ // First check to see if the point to add overlaps an existing keyframe:
+ if (ArrayLocation) {
+ for (int p = 0; p < Property->Keyframe_Count; p++) {
+ int k = ArrayLocation[p];
+ bezier_point *Point = Bezier_LookupAddress(Memory, Property, k);
+ if (Point->Pos[0].x == PointData.Pos[0].x) {
+ History_Action_Swap(Memory, F_Bezier, sizeof(*Point), Point);
+ *Point = PointData;
+ return;
+ }
+ }
+ }
int k = 0;
for (;;) {
bezier_point *Point = Bezier_LookupAddress(Memory, Property, k, 0);
@@ -317,6 +330,19 @@ Effect_Init(project_state *State, memory *Memory, uint32 EffectEntryIndex, int E
return EffectAddressIndex;
}
+static void
+Effect_Add(project_data *File, project_state *State, memory *Memory, uint32 EffectEntryIndex)
+{
+ 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) {
+ Layer->Block_Effect_Index[Layer->Block_Effect_Count] = Effect_Init(State, Memory, EffectEntryIndex, Layer->Block_Effect_Count);
+ Layer->Block_Effect_Count++;
+ }
+ }
+}
static void
Layer_UpdateMasksEffects(project_state *State, block_layer *Layer, memory *Memory, void *EffectBitmapAddress,
@@ -384,7 +410,7 @@ 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_layer;
+ State->RecentSelectionType = selection_type_layer;
}
void Layer_DeselectAll(project_data *File, project_state *State, memory *Memory) {
@@ -405,12 +431,59 @@ void Source_DeselectAll(project_data *File, memory *Memory)
}
}
+inline sorted_property_info *
+Property_GetSortedInfo(sorted_property_info *SortedPropertyInfo, int i, int h)
+{
+ return SortedPropertyInfo + (i * 8) + h;
+}
+inline uint16 *
+Property_GetSortedArray(uint16 *SortedPropertyArray, int i, int h)
+{
+ return SortedPropertyArray + (i * 8 * MAX_KEYFRAMES_PER_BLOCK) + (h * MAX_KEYFRAMES_PER_BLOCK);
+}
+
+static void
+Bezier_Commit(project_data *File, project_state *State, memory *Memory, uint16 *SortedPropertyArray) {
+ History_Entry_Commit(Memory, "Move 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 ((State->TimelineMode == timeline_mode_graph) && !Layer->IsSelected)
+ continue;
+ for (int h = 0; h < AmountOf(Layer->Property); h++) {
+ uint16 *ArrayLocation = Property_GetSortedArray(SortedPropertyArray, i, h);
+ property_channel *Property = &Layer->Property[h];
+ if ((State->TimelineMode != timeline_mode_graph) && !Property->IsToggled)
+ continue;
+ for (int p = 0; p < Property->Keyframe_Count; p++) {
+ int k = ArrayLocation[p];
+ bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, k);
+ if (PointAddress->IsSelected) {
+ v2 NewPos[3];
+ Bezier_EvaluateValue(State, PointAddress, NewPos);
+ History_Action_Swap(Memory, F_Bezier, sizeof(PointAddress->Pos), &PointAddress->Pos);
+ PointAddress->Pos[0] = NewPos[0];
+ PointAddress->Pos[1] = NewPos[1];
+ PointAddress->Pos[2] = NewPos[2];
+ }
+ }
+ }
+ }
+ History_Entry_End(Memory);
+ State->Interact_Offset[0] = 0;
+ State->Interact_Offset[1] = 0;
+ State->Interact_Offset[2] = 0;
+ State->Interact_Offset[3] = 0;
+ State->Interact_Active = interact_type_none;
+ State->Interact_Modifier = 0;
+}
+
// NOTE(fox): This won't work with precomps!
-void Clipboard_Paste(project_data *File, project_state *State, memory *Memory, sorted_comp_info *SortedCompInfo, sorted_layer *SortedLayerInfo)
+void Clipboard_Paste(project_data *File, project_state *State, memory *Memory, sorted_comp_info *SortedCompInfo, sorted_layer *SortedLayerInfo, uint16 *SortedPropertyArray)
{
clipboard_contents *Contents = (clipboard_contents *)State->ClipboardBuffer;
- if (Contents->Type == selection_none)
+ if (Contents->Type == selection_type_none)
return;
uint64 ClipboardPos = sizeof(clipboard_contents);
ClipboardPos = sizeof(clipboard_contents);
@@ -454,7 +527,8 @@ void Clipboard_Paste(project_data *File, project_state *State, memory *Memory, s
for (int p = 0; p < Channel->KeyframeCount; p++) {
bezier_point PointData = *(bezier_point *)((uint8 *)State->ClipboardBuffer + ClipboardPos);
PointData.Pos[0].x += State->Frame_Current;
- Bezier_Add(Memory, Property, PointData);
+ uint16 *ArrayLocation = Property_GetSortedArray(SortedPropertyArray, i, h);
+ Bezier_Add(Memory, Property, PointData, ArrayLocation);
ClipboardPos += sizeof(bezier_point);
}
b++;
@@ -471,94 +545,56 @@ void Clipboard_Paste(project_data *File, project_state *State, memory *Memory, s
}
}
-inline sorted_property_info *
-Property_GetSortedInfo(sorted_property_info *SortedPropertyInfo, int i, int h)
-{
- return SortedPropertyInfo + (i * 8) + h;
-}
-inline uint16 *
-Property_GetSortedArray(uint16 *SortedPropertyArray, int i, int h)
-{
- return SortedPropertyArray + (i * 8 * MAX_KEYFRAMES_PER_BLOCK) + (h * MAX_KEYFRAMES_PER_BLOCK);
-}
-
-static void
-Bezier_Commit(project_data *File, project_state *State, memory *Memory, uint16 *SortedPropertyArray) {
- History_Entry_Commit(Memory, "Move 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)
- continue;
- for (int h = 0; h < AmountOf(Layer->Property); h++) {
- uint16 *ArrayLocation = Property_GetSortedArray(SortedPropertyArray, i, h);
- property_channel *Property = &Layer->Property[h];
- for (int p = 0; p < Property->Keyframe_Count; p++) {
- int k = ArrayLocation[p];
- bezier_point *PointAddress = Bezier_LookupAddress(Memory, Property, k);
- if (PointAddress->IsSelected) {
- v2 NewPos[3];
- Bezier_EvaluateValue(State, PointAddress, NewPos);
- History_Action_Swap(Memory, F_Bezier, sizeof(PointAddress->Pos), &PointAddress->Pos);
- PointAddress->Pos[0] = NewPos[0];
- PointAddress->Pos[1] = NewPos[1];
- PointAddress->Pos[2] = NewPos[2];
- }
- }
- }
- }
- History_Entry_End(Memory);
- State->Interact_Offset[0] = 0;
- State->Interact_Offset[1] = 0;
- State->Interact_Offset[2] = 0;
- State->Interact_Offset[3] = 0;
- State->Interact_Active = interact_type_none;
- State->Interact_Modifier = 0;
-}
-
void Clipboard_Store(project_data *File, project_state *State, memory *Memory, sorted_comp_info *SortedCompInfo, sorted_layer *SortedLayerInfo, sorted_property_info *SortedPropertyInfo, uint16 *SortedPropertyArray)
{
int LocalOffset = 0;
clipboard_contents *Contents = (clipboard_contents *)State->ClipboardBuffer;
*Contents = {};
+ Contents->Type = State->RecentSelectionType;
uint64 ClipboardPos = sizeof(clipboard_contents);
- for (int i = SortedCompInfo->LayerCount - 1; i >= 0; i--)
- {
- sorted_layer SortEntry = SortedLayerInfo[i];
- uint32 Index_Physical = SortEntry.Block_Layer_Index;
- block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, Index_Physical);
- for (int h = 0; h < AmountOf(Layer->Property); h++) {
- property_channel *Property = &Layer->Property[h];
- if (Property->IsToggled || Layer->IsSelected) {
- sorted_property_info *InfoLocation = Property_GetSortedInfo(SortedPropertyInfo, i, h);
- uint16 *ArrayLocation = Property_GetSortedArray(SortedPropertyArray, i, h);
- 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]);
- if (PointAddress->IsSelected) {
- if (!FirstPoint) {
- FirstPoint = PointAddress;
- TimeOffset = FirstPoint->Pos[0].x;
+ if (Contents->Type == selection_type_none)
+ return;
+ else if (Contents->Type == selection_type_keyframe) {
+ for (int i = SortedCompInfo->LayerCount - 1; i >= 0; i--)
+ {
+ sorted_layer SortEntry = SortedLayerInfo[i];
+ uint32 Index_Physical = SortEntry.Block_Layer_Index;
+ block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, Index_Physical);
+ for (int h = 0; h < AmountOf(Layer->Property); h++) {
+ property_channel *Property = &Layer->Property[h];
+ if (Property->IsToggled || Layer->IsSelected) {
+ sorted_property_info *InfoLocation = Property_GetSortedInfo(SortedPropertyInfo, i, h);
+ uint16 *ArrayLocation = Property_GetSortedArray(SortedPropertyArray, i, h);
+ 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]);
+ if (PointAddress->IsSelected) {
+ if (!FirstPoint) {
+ FirstPoint = PointAddress;
+ TimeOffset = FirstPoint->Pos[0].x;
+ }
+ bezier_point PointToCopy = *PointAddress;
+ PointToCopy.Pos[0].x -= TimeOffset;
+ Memory_Copy((uint8 *)State->ClipboardBuffer + ClipboardPos, (uint8 *)&PointToCopy, sizeof(bezier_point));
+ ClipboardPos += sizeof(bezier_point);
+ Channel->KeyframeCount++;
}
- bezier_point PointToCopy = *PointAddress;
- PointToCopy.Pos[0].x -= TimeOffset;
- Memory_Copy((uint8 *)State->ClipboardBuffer + ClipboardPos, (uint8 *)&PointToCopy, sizeof(bezier_point));
- ClipboardPos += sizeof(bezier_point);
- Channel->KeyframeCount++;
}
- }
- if (Channel->KeyframeCount) {
- if (!LocalOffset)
- LocalOffset = i;
- Contents->ChannelCount++;
- Channel->LayerOffset = LocalOffset - i;
- Channel->Name = Property->Name;
+ if (Channel->KeyframeCount) {
+ if (!LocalOffset)
+ LocalOffset = i;
+ Contents->ChannelCount++;
+ Channel->LayerOffset = LocalOffset - i;
+ Channel->Name = Property->Name;
+ }
}
}
}
}
+ else if (Contents->Type == selection_type_layer) {
+ }
}
static sorted_layer *
@@ -1072,8 +1108,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, &PrecompLayer->time, Point0);
- Bezier_Add(Memory, &PrecompLayer->time, Point1);
+ Bezier_Add(Memory, &PrecompLayer->time, Point0, NULL);
+ Bezier_Add(Memory, &PrecompLayer->time, Point1, NULL);
PrecompLayer->IsPrecomp = true;
Layer_Select(Memory, State, Memory_Block_LazyIndexAtAddress(Memory, F_Layers, PrecompLayer));
PrecompLayer->Block_Source_Index = File->Comp_Count - 1;