From ae94b4b9fc5b4443f6d9eb6bb450de1def108cdb Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Wed, 24 Aug 2022 20:40:39 -0400 Subject: fixes for gl core; create/delete developing --- keyframes.cpp | 84 +++++++++++++++++++++++++++-------------------------------- 1 file changed, 38 insertions(+), 46 deletions(-) (limited to 'keyframes.cpp') 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) { @@ -129,6 +107,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) { @@ -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); -- cgit v1.2.3