summaryrefslogtreecommitdiff
path: root/src/createcalls.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/createcalls.cpp')
-rw-r--r--src/createcalls.cpp89
1 files changed, 72 insertions, 17 deletions
diff --git a/src/createcalls.cpp b/src/createcalls.cpp
index 4761a94..bf9eea2 100644
--- a/src/createcalls.cpp
+++ b/src/createcalls.cpp
@@ -207,7 +207,7 @@ Property_InitFloat(real32 Val, real32 ScrubVal, real32 MinVal, real32 MaxVal, bo
}
static block_composition *
-Precomp_Init(project_data *File, memory *Memory)
+Precomp_Init(project_data *File, memory *Memory, block_composition *DupeComp)
{
if (File->Comp_Count + 1 > MAX_COMPS) {
Assert(0);
@@ -215,7 +215,11 @@ Precomp_Init(project_data *File, memory *Memory)
block_composition *Comp = (block_composition *)Memory_Block_AllocateAddress(Memory, F_Precomps);
History_Action_Block_Swap(Memory, F_Precomps, Comp);
- *Comp = {};
+ if (DupeComp) {
+ *Comp = *DupeComp;
+ } else {
+ *Comp = {};
+ }
Comp->Occupied = 1;
Comp->Name_String_Index = Memory_Block_AllocateNew(Memory, F_Strings);
@@ -262,7 +266,7 @@ Effect_Add(project_data *File, project_state *State, memory *Memory, uint32 Effe
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) {
+ if (Layer->IsSelected & 0x01) {
Layer->Block_Effect_Index[Layer->Block_Effect_Count] = Effect_Init(State, Memory, EffectEntryIndex, Layer->Block_Effect_Count);
History_Action_Swap(Memory, F_Layers, sizeof(Layer->Block_Effect_Count), &Layer->Block_Effect_Count);
Layer->Block_Effect_Count++;
@@ -293,7 +297,7 @@ Keyframe_Commit(project_data *File, project_state *State, memory *Memory,
while (Block_Loop(Memory, F_Layers, File->Layer_Count, &h, &c, &i)) {
block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i);
sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(SortedLayerArray, SortedCompArray, Layer->Block_Composition_Index);
- if ((State->TimelineMode == timeline_mode_graph) && !Layer->IsSelected)
+ if ((State->TimelineMode == timeline_mode_graph) && !(Layer->IsSelected & 0x01))
continue;
sorted_property_array *InfoLocation = SortedPropertyStart + SortedLayerStart->SortedPropertyStart;
uint16 *ArrayLocation = SortedKeyframeArray + SortedLayerStart->SortedKeyframeStart;
@@ -360,7 +364,7 @@ void Clipboard_Paste(project_data *File, project_state *State, memory *Memory, s
sorted_layer_array SortEntry = SortedLayerStart[i];
uint32 Index_Physical = SortEntry.Block_Layer_Index;
block_layer *TestLayer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i);
- if (TestLayer->IsSelected) {
+ if (TestLayer->IsSelected & 0x01) {
Layer = TestLayer;
break;
}
@@ -414,7 +418,7 @@ void Clipboard_Store(project_data *File, project_state *State, memory *Memory, s
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) {
+ if (Property->IsToggled || (Layer->IsSelected & 0x01)) {
sorted_property_array *InfoLocation = Property_GetSortedInfo(SortedPropertyStart, i, h);
uint16 *ArrayLocation = Property_GetSortedArray(SortedKeyframeArray, i, h);
clipboard_channel *Channel = &Contents->Channel[Contents->ChannelCount];
@@ -459,7 +463,7 @@ void Slide_Init(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);
- if (Layer->IsSelected) {
+ if (Layer->IsSelected & 0x01) {
interact_slide_layer *Interact_Layer = (interact_slide_layer *)InteractBuffer;
*Interact_Layer = {0};
Interact_Layer->Index = i;
@@ -591,7 +595,7 @@ Layer_Nudge(project_data *File, project_state *State, memory *Memory,
// NOTE(fox): Some data on the tree could be saved here.
History_Action_Swap(Memory, F_Layers, sizeof(Layer->Vertical_Offset), &Layer->Vertical_Offset);
Layer->Vertical_Offset = SortEntry.SortedOffset;
- if (Layer->IsSelected) {
+ if (Layer->IsSelected & 0x01) {
History_Action_Swap(Memory, F_Layers, sizeof(Layer->Frame_Offset), &Layer->Frame_Offset);
Interact_Evaluate_Layer(Memory, State, Index_Physical, SortedCompStart, SortedLayerStart, &Layer->Frame_Start, &Layer->Frame_End, &Layer->Frame_Offset);
}
@@ -628,7 +632,7 @@ void File_DeselectAllKeyframes(project_data *File, project_state *State, 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);
- if (!Layer->IsSelected)
+ if (!(Layer->IsSelected & 0x01))
continue;
sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(SortedLayerArray, SortedCompArray, Layer->Block_Composition_Index);
sorted_property_array *InfoLocation = SortedPropertyStart + SortedLayerStart->SortedPropertyStart;
@@ -656,7 +660,7 @@ Project_Layer_Delete(project_data *File, project_state *State, memory *Memory)
int LayerCount = File->Layer_Count;
while (Block_Loop(Memory, F_Layers, LayerCount, &h, &c, &i)) {
block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i);
- if (Layer->IsSelected == 1) {
+ if (Layer->IsSelected & 0x01) {
if (!CommitAction) {
History_Entry_Commit(Memory, "Delete layer");
CommitAction = 1;
@@ -707,6 +711,55 @@ SortUnionTest(memory *Memory, sorted_layer_array *SortedLayerStart, block_layer
}
}
+// NOTE(fox): PrecompLayer is assumed to be untouched from the layer it was duplicated from!
+static uint16
+Layer_Precomp_CopyContents(project_data *File, project_state *State, memory *Memory, block_layer *PrecompLayer,
+ sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray)
+{
+ Assert(PrecompLayer->IsPrecomp);
+ int CompIndex = PrecompLayer->Block_Source_Index;
+ sorted_comp_array SortedCompStart = SortedCompArray[CompIndex];
+ sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(SortedLayerArray, SortedCompArray, CompIndex);
+ int LayerCount = SortedCompStart.LayerCount;
+ Assert(SortedCompStart.FakeLayerCount == 0);
+
+ block_composition *Comp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, CompIndex);
+ block_composition *NewPrecomp = Precomp_Init(File, Memory, Comp);
+ uint16 NewCompIndex = Memory_Block_LazyIndexAtAddress(Memory, F_Precomps, NewPrecomp);
+
+ for (int i = 0; i < LayerCount; i++)
+ {
+ sorted_layer_array SortEntry = SortedLayerStart[i];
+ uint32 Index_Physical = SortEntry.Block_Layer_Index;
+ block_layer *NewLayer = NULL;
+ {
+ block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, Index_Physical);
+ Assert(!(Layer->IsSelected & 0x01));
+ NewLayer = (block_layer *)Memory_Block_AllocateAddress(Memory, F_Layers);
+ History_Action_Block_Swap(Memory, F_Layers, NewLayer);
+ *NewLayer = *Layer;
+ }
+
+ NewLayer->Block_Composition_Index = NewCompIndex;
+
+ // TODO(fox): Effect duplication
+ Assert(NewLayer->Block_Effect_Count == 0);
+
+ block_string *OldString = (block_string *)Memory_Block_AddressAtIndex(Memory, F_Strings, NewLayer->Block_String_Index);
+
+ NewLayer->Block_String_Index = Memory_Block_AllocateNew(Memory, F_Strings);
+ block_string *String = (block_string *)Memory_Block_AddressAtIndex(Memory, F_Strings, NewLayer->Block_String_Index, 0);
+ sprintf(String->Char, "%s", OldString->Char);
+ History_Action_Swap(Memory, F_Strings, sizeof(String->Occupied), &String->Occupied);
+ String->Occupied = 1;
+
+ History_Action_Swap(Memory, F_File, sizeof(File->Layer_Count), &File->Layer_Count);
+ File->Layer_Count++;
+ }
+
+ return NewCompIndex;
+}
+
static void
Project_Layer_Duplicate(project_data *File, project_state *State, memory *Memory,
sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, v2 Offset, bool32 FakeOnly, bool32 NewPrecomp)
@@ -720,19 +773,20 @@ Project_Layer_Duplicate(project_data *File, project_state *State, memory *Memory
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 ((FakeOnly && SortEntry.IsFake) || (!FakeOnly && Layer->IsSelected == 1))
+ if ((FakeOnly && SortEntry.IsFake) || (!FakeOnly && (Layer->IsSelected & 0x01)))
{
if (!FakeOnly)
- Layer->IsSelected = false;
+ Layer->IsSelected = 0x00;
block_layer *NewLayer = (block_layer *)Memory_Block_AllocateAddress(Memory, F_Layers);
History_Action_Block_Swap(Memory, F_Layers, NewLayer);
*NewLayer = *Layer;
if (NewPrecomp && Layer->IsPrecomp) {
- NewLayer->Block_Source_Index = Layer_Precomp_CopyContents();
+ NewLayer->Block_Source_Index = Layer_Precomp_CopyContents(File, State, Memory, NewLayer, SortedCompArray, SortedLayerArray);
}
+ // TODO(fox): Effect duplication
Assert(Layer->Block_Effect_Count == 0);
Layer_Select(Memory, State, Memory_Block_LazyIndexAtAddress(Memory, F_Layers, NewLayer));
@@ -755,7 +809,7 @@ Project_Layer_Duplicate(project_data *File, project_state *State, memory *Memory
File->Layer_Count++;
} else {
- Layer->IsSelected = false;
+ Layer->IsSelected = 0x00;
}
}
}
@@ -790,6 +844,7 @@ Project_ShapeLayer_New(project_data *File, project_state *State, memory *Memory)
if (State->MostRecentlySelectedLayer == -1) {
Layer->Block_Composition_Index = File->PrincipalCompIndex;
} else {
+ // TODO(fox): Allow shapes to be drawn inside selected precomps?
// LayerIterate_DeepestPrecomp(State, Memory, CompIndex, ExtraT, Center,
// SortedCompArray, SortedLayerArray, SelectionCount, SelectedLayerIndex, SelectedPrecompIndex)
}
@@ -932,7 +987,7 @@ void Precomp_UIDelete(project_data *File, project_state *State, memory *Memory,
sorted_layer_array SortEntry = SortedLayerStart[i];
uint32 Index_Physical = SortEntry.Block_Layer_Index;
Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, Index_Physical);
- if (Layer->IsSelected) {
+ if (Layer->IsSelected & 0x01) {
}
}
}
@@ -956,7 +1011,7 @@ void Precomp_UICreateButton(project_data *File, project_state *State, memory *Me
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->IsSelected) {
+ if (Layer->IsSelected & 0x01) {
TopOffset = Layer->Vertical_Offset;
break;
}
@@ -966,7 +1021,7 @@ void Precomp_UICreateButton(project_data *File, project_state *State, memory *Me
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->IsSelected) {
+ if (Layer->IsSelected & 0x01) {
History_Action_Swap(Memory, F_Layers, sizeof(Layer->Block_Composition_Index), &Layer->Block_Composition_Index);
Layer->Block_Composition_Index = File->Comp_Count - 1;
}