summaryrefslogtreecommitdiff
path: root/keyframes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'keyframes.cpp')
-rw-r--r--keyframes.cpp84
1 files changed, 38 insertions, 46 deletions
diff --git a/keyframes.cpp b/keyframes.cpp
index 7fb7c13..451f2b6 100644
--- a/keyframes.cpp
+++ b/keyframes.cpp
@@ -80,28 +80,6 @@ CheckKeyframeSort(property_channel *Property, int32 Increment, int32 b)
*/
}
-static void
-DeleteKeyframeFromMemory(property_channel *Property, int16 Increment, int16 StopAt) {
- if (Increment > 0) {
- int16 i = Property->NumberOfTotalKeyframes - 1;
- while (i > StopAt) {
- keyframe *CurrentKeyframe = KeyframeLookup(Property, i);
- keyframe *NextKeyframe = KeyframeLookup(Property, i + Increment);
- *NextKeyframe = *CurrentKeyframe;
- i--;
- }
- Property->NumberOfTotalKeyframes += Increment;
- } else {
- int16 i = StopAt;
- while (i < Property->NumberOfTotalKeyframes - 1) {
- keyframe *CurrentKeyframe = KeyframeLookup(Property, i);
- keyframe *NextKeyframe = KeyframeLookup(Property, i - Increment);
- *CurrentKeyframe = *NextKeyframe;
- i++;
- }
- Property->NumberOfTotalKeyframes += Increment;
- }
-}
static void
ResortPropertyChannel(property_channel *Property) {
@@ -130,6 +108,28 @@ ResortPropertyChannel(property_channel *Property) {
}
static void
+Keyframe_ShiftPointers(property_channel *Property, int16 Increment, int16 StopAt) {
+ if (Increment > 0) {
+ int16 i = Property->NumberOfTotalKeyframes - 1;
+ while (i >= StopAt) {
+ keyframe *CurrentKeyframe = KeyframeLookup(Property, i);
+ keyframe *NextKeyframe = KeyframeLookup(Property, i + Increment);
+ *NextKeyframe = *CurrentKeyframe;
+ i--;
+ }
+ } else {
+ int16 i = StopAt;
+ while (i <= Property->NumberOfTotalKeyframes - 1) {
+ keyframe *CurrentKeyframe = KeyframeLookup(Property, i);
+ keyframe *NextKeyframe = KeyframeLookup(Property, i - Increment);
+ *CurrentKeyframe = *NextKeyframe;
+ i++;
+ }
+ }
+}
+
+
+static void
DeleteSelectedKeyframes(project_data *File, memory *Memory)
{
for (int i = 0; i < File->NumberOfLayers; i++) {
@@ -148,7 +148,7 @@ DeleteSelectedKeyframes(project_data *File, memory *Memory)
Until = false;
}
}
- DeleteKeyframeFromMemory(Property, -ToShift, l);
+ Keyframe_ShiftPointers(Property, -ToShift, l);
}
}
ResortPropertyChannel(Property);
@@ -226,28 +226,6 @@ ClampSurroundingKeyframeHandles(property_channel *Property, int16 b) {
}
}
-
-static void
-ShiftKeyframes(property_channel *Property, int16 Increment, int16 StopAt) {
- if (Increment > 0) {
- int16 i = Property->NumberOfTotalKeyframes - 1;
- while (i >= StopAt) {
- keyframe *NextKeyframe = KeyframeLookup(Property, i + Increment);
- keyframe *CurrentKeyframe = KeyframeLookup(Property, i);
- *NextKeyframe = *CurrentKeyframe;
- i--;
- }
- } else {
- int16 i = StopAt;
- while (i <= Property->NumberOfTotalKeyframes - 1) {
- keyframe *NextKeyframe = KeyframeLookup(Property, i - Increment);
- keyframe *CurrentKeyframe = KeyframeLookup(Property, i);
- *CurrentKeyframe = *NextKeyframe;
- i++;
- }
- }
-}
-
static uint32
Keyframe_FindClosestIndex(property_channel *Property, int32 CurrentFrame, bool32 *Overlapping)
{
@@ -301,6 +279,20 @@ Keyframe_FindClosestIndex(property_channel *Property, int32 CurrentFrame, bool32
}
}
+// NOTE(fox): Delete calls need to increment the total number before shifting!
+static void
+Keyframe_Delete(property_channel *Property, memory *Memory, uint32 Index)
+{
+ History_Entry_Commit(Memory, action_entry_default, "Delete keyframe");
+ keyframe *KeyframeIndex = KeyframeLookup(Property, Index);
+ History_Action_StoreData(Memory, KeyframeIndex, sizeof(keyframe));
+
+ History_Action_Change_Decrement(Memory, &Property->NumberOfTotalKeyframes, action_type_change_u16);
+ History_Action_Shift(Memory, action_type_shift_keyframe, Property, -1, Index);
+ Keyframe_ShiftPointers(Property, -1, Index);
+ History_Entry_End(Memory);
+}
+
static void
Keyframe_Insert(property_channel *Property, memory *Memory, int32 CurrentFrame, real32 Val)
{
@@ -317,7 +309,7 @@ Keyframe_Insert(property_channel *Property, memory *Memory, int32 CurrentFrame,
History_Entry_Commit(Memory, action_entry_default, "Insert keyframe");
if (Index != Property->NumberOfTotalKeyframes) {
History_Action_Shift(Memory, action_type_shift_keyframe, Property, 1, Index);
- ShiftKeyframes(Property, 1, Index);
+ Keyframe_ShiftPointers(Property, 1, Index);
}
History_Action_Change_Increment(Memory, &Property->NumberOfTotalKeyframes, action_type_change_u16);