diff options
Diffstat (limited to 'src/sorted.cpp')
-rw-r--r-- | src/sorted.cpp | 127 |
1 files changed, 90 insertions, 37 deletions
diff --git a/src/sorted.cpp b/src/sorted.cpp index 1d2b4f2..5826e68 100644 --- a/src/sorted.cpp +++ b/src/sorted.cpp @@ -156,6 +156,93 @@ Layer_Sort_CheckPrev(memory *Memory, int i, int Direction, sorted_layer_array *S // interactivity if the user is moving any layers. static void +Layer_Sort_Shift(project_state *State, memory *Memory, + sorted_layer_array *LayerArrayStart, sorted_comp_array *CompArrayStart, + uint32 LayerCount, uint32 CompCount) +{ + int32 Offset = (int32)State->Interact_Offset[1]; + bool32 Direction = (Offset > 0) ? 1 : -1; + for (uint32 c = 0; c < CompCount; c++) { + sorted_comp_array *SortedCompStart = &CompArrayStart[c]; + if (!SortedCompStart->LayerCount) + continue; + sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(LayerArrayStart, CompArrayStart, c); + int i = (Direction > 0) ? SortedCompStart->LayerCount - 1 : 0; + bool32 Case = 1; + while (Case) { + int32 EntriesPassed = 0; + sorted_layer_array *LayerEntry = &SortedLayerStart[i]; + block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, LayerEntry->Block_Layer_Index); + Assert(LayerEntry->SortedOffset == Layer->Vertical_Offset); + if (Layer->IsSelected) { + int32 SpacesToMove = Offset * Direction; + while (SpacesToMove) { + Layer_Sort_CheckPrev(Memory, i, Direction, SortedLayerStart, *SortedCompStart, &EntriesPassed, LayerEntry, 0); + LayerEntry->SortedOffset -= Direction; + SpacesToMove--; + } + } + int b = 0; + while (b < EntriesPassed) { + sorted_layer_array *FrontEntry = &SortedLayerStart[i+(b*Direction)]; + sorted_layer_array *BackEntry = &SortedLayerStart[i+((b+1)*Direction)]; + sorted_layer_array Swap = *FrontEntry; + *FrontEntry = *BackEntry; + *BackEntry = Swap; + b++; + } + i -= Direction; + Case = (Direction > 0) ? (i >= 0) : (i < SortedCompStart->LayerCount); + } + } +} + +#if 0 +static void +Layer_Sort_Shift2(project_state *State, memory *Memory, + sorted_layer_array *LayerArrayStart, sorted_comp_array *CompArrayStart, + uint32 LayerCount, uint32 CompCount, int32 Offset) +{ + bool32 Direction = (Offset > 0) ? 1 : -1; + for (uint32 c = 0; c < CompCount; c++) { + sorted_comp_array *SortedCompStart = &CompArrayStart[c]; + if (!SortedCompStart->LayerCount) + continue; + sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(LayerArrayStart, CompArrayStart, c); + int i = (Direction > 0) ? SortedCompStart->LayerCount - 1 : 0; + int FauxIncrement = 0; + bool32 Case = 1; + while (Case) { + int Idx = i + FauxIncrement; + int32 EntriesPassed = 0; + sorted_layer_array *LayerEntry = &SortedLayerStart[Idx]; + block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, LayerEntry->Block_Layer_Index); + Assert(LayerEntry->SortedOffset == Layer->Vertical_Offset); + if (Layer->IsSelected) { + int32 SpacesToMove = Offset * Direction; + Assert(SpacesToMove == 1); + while (SpacesToMove) { + Layer_Sort_CheckPrev(Memory, i, Direction, SortedLayerStart, *SortedCompStart, &EntriesPassed, LayerEntry, 0); + SpacesToMove--; + } + int b = 0; + while (b < EntriesPassed) { + sorted_layer_array *FrontEntry = &SortedLayerStart[i+(b*Direction)]; + sorted_layer_array *BackEntry = &SortedLayerStart[i+((b+1)*Direction)]; + sorted_layer_array Swap = *FrontEntry; + *FrontEntry = *BackEntry; + *BackEntry = Swap; + b++; + } + } + i -= Direction; + Case = (Direction > 0) ? (i >= 0) : (i < SortedCompStart->LayerCount); + } + } +} +#endif + +static void Layer_SortAll(project_state *State, memory *Memory, sorted_layer_array *LayerArrayStart, sorted_comp_array *CompArrayStart, uint32 LayerCount, uint32 CompCount) @@ -166,7 +253,7 @@ Layer_SortAll(project_state *State, memory *Memory, Assert(Layer->Block_Composition_Index < CompCount); sorted_comp_array *SortedCompStart = &CompArrayStart[Layer->Block_Composition_Index]; SortedCompStart->LayerCount++; - if (State->Interact_Active == interact_type_viewport_duplicate && Layer->IsSelected) { + if (State->Interact_Active == interact_type_viewport_duplicate && Layer->IsSelected == 1) { SortedCompStart->FakeLayerCount++; } } @@ -197,41 +284,7 @@ Layer_SortAll(project_state *State, memory *Memory, SortedCompStart->CurrentSortIndex++; } if (State->Interact_Active == interact_type_layer_move) { - int32 Offset = (int32)State->Interact_Offset[1]; - bool32 Direction = (Offset > 0) ? 1 : -1; - for (uint32 c = 0; c < CompCount; c++) { - sorted_comp_array *SortedCompStart = &CompArrayStart[c]; - if (!SortedCompStart->LayerCount) - continue; - sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(LayerArrayStart, CompArrayStart, c); - int i = (Direction > 0) ? SortedCompStart->LayerCount - 1 : 0; - bool32 Case = 1; - while (Case) { - int32 EntriesPassed = 0; - sorted_layer_array *LayerEntry = &SortedLayerStart[i]; - block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, LayerEntry->Block_Layer_Index); - Assert(LayerEntry->SortedOffset == Layer->Vertical_Offset); - if (Layer->IsSelected) { - int32 SpacesToMove = Offset * Direction; - while (SpacesToMove) { - Layer_Sort_CheckPrev(Memory, i, Direction, SortedLayerStart, *SortedCompStart, &EntriesPassed, LayerEntry, 0); - LayerEntry->SortedOffset -= Direction; - SpacesToMove--; - } - } - int b = 0; - while (b < EntriesPassed) { - sorted_layer_array *FrontEntry = &SortedLayerStart[i+(b*Direction)]; - sorted_layer_array *BackEntry = &SortedLayerStart[i+((b+1)*Direction)]; - sorted_layer_array Swap = *FrontEntry; - *FrontEntry = *BackEntry; - *BackEntry = Swap; - b++; - } - i -= Direction; - Case = (Direction > 0) ? (i >= 0) : (i < SortedCompStart->LayerCount); - } - } + Layer_Sort_Shift(State, Memory, LayerArrayStart, CompArrayStart, LayerCount, CompCount); } else if (State->Interact_Active == interact_type_viewport_duplicate) { for (uint32 c = 0; c < CompCount; c++) { @@ -245,7 +298,7 @@ Layer_SortAll(project_state *State, memory *Memory, int Idx = i + FauxIncrement; sorted_layer_array *LayerEntry = &SortedLayerStart[Idx]; block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, LayerEntry->Block_Layer_Index); - if (Layer->IsSelected) { + if (Layer->IsSelected == 1) { for (int a = i+1; a < SortedCompStart->LayerCount; a++) { int PrevIdx = a + FauxIncrement - 1; sorted_layer_array *PrevLayerEntry = &SortedLayerStart[PrevIdx]; |