summaryrefslogtreecommitdiff
path: root/src/layer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/layer.cpp')
-rw-r--r--src/layer.cpp68
1 files changed, 55 insertions, 13 deletions
diff --git a/src/layer.cpp b/src/layer.cpp
index 4c94987..9a3a0a4 100644
--- a/src/layer.cpp
+++ b/src/layer.cpp
@@ -182,7 +182,7 @@ Layer_ToggleChannel(project_data *File, memory *Memory, int32 a)
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 == 1)
+ if (Layer->IsSelected & 0x01)
Layer->Property[a].IsToggled ^= 1;
}
}
@@ -191,7 +191,8 @@ static void
Layer_Select(memory *Memory, project_state *State, int32 i)
{
block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i);
- Layer->IsSelected = true;
+ // Assert(!(Layer->IsSelected & 0x02));
+ Layer->IsSelected |= 0x01;
State->MostRecentlySelectedLayer = i;
State->Interact_Transform = {};
State->RecentSelectionType = selection_type_layer;
@@ -202,24 +203,50 @@ Layer_Select_RecurseUp(memory *Memory, project_state *State, int32 i, int16 Recu
{
for (int a = 1; a <= Recursions; a++) {
block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, RecursionIdx[a]);
- Layer->IsSelected = 2;
+ Layer->IsSelected = 0x02;
}
}
static void
-Layer_DeselectAll(project_data *File, project_state *State, memory *Memory) {
+Interact_BoxSelect_Start(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);
- // stupid way to preserve this
- if (Layer->IsSelected == -1) {
- Layer->IsSelected = 2;
+ if (Layer->IsSelected & 0x01) {
+ Layer->IsSelected |= 0x04;
+ }
+ }
+}
+
+static void
+Interact_BoxSelect_End(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 & 0x04) {
+ Layer->IsSelected ^= 0x04;
+ }
+ }
+}
+
+static void
+Layer_DeselectAll(project_data *File, project_state *State, memory *Memory, bool32 AllowComp) {
+ int h = 0, c = 0, i = 0;
+ bool32 ShiftLayers = false;
+ 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 & 0x04) {
+ ShiftLayers = 1;
} else {
- Layer->IsSelected = false;
+ if (!(AllowComp && Layer->IsSelected & 0x02)) {
+ Layer->IsSelected = 0x00;
+ }
}
}
State->Interact_Transform = {};
- State->MostRecentlySelectedLayer = -1;
+ if (!ShiftLayers) {
+ State->MostRecentlySelectedLayer = -1;
+ }
}
// TODO(fox): This function will be replaced once properties are reworked.
@@ -317,7 +344,7 @@ Layer_Select_Traverse(uint16 PrincipalCompIndex, memory *Memory, project_state *
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->IsPrecomp && Layer->IsSelected == 2) {
+ if (Layer->IsPrecomp && (Layer->IsSelected & 0x02)) {
*Recursions = RecursionsCurrent + 1;
RecursionIdx[*Recursions] = Index_Physical;
Layer_Select_Traverse(PrincipalCompIndex, Memory, State, IndexToFind, SortedCompArray, SortedLayerArray, RecursionIdx, Recursions);
@@ -390,7 +417,7 @@ Layer_TestForPoint(memory *Memory, project_state *State, ui *UI, sorted_comp_arr
Layer_GetDimensions(Memory, Layer, &Width, &Height);
layer_transforms T = Layer_GetTransforms(Layer);
v2 UV = T_CompUVToLayerUV(T, Comp->Width, Comp->Height, Width, Height, CompUV);
- if (UV.x <= 1.0f && UV.x >= 0.0f && UV.y <= 1.0f && UV.y >= 0.0f && (Layer->IsSelected || Layer->IsPrecomp) && !Layer->IsLocked)
+ if (UV.x <= 1.0f && UV.x >= 0.0f && UV.y <= 1.0f && UV.y >= 0.0f && ((Layer->IsSelected & 0x01) || Layer->IsPrecomp) && !Layer->IsLocked)
{
return 1;
}
@@ -512,6 +539,10 @@ Transform_TestBox(block_layer *Layer, uint32 Width, uint32 Height, v2 Min, v2 Ma
v2 Pos = {Layer->x.CurrentValue, Layer->y.CurrentValue};
v2 Origin = Pos - (XAxis * AnchorX) - (YAxis * AnchorY);
+ if (Origin.x > Min.x && Origin.x < Max.x &&
+ Origin.y > Min.y && Origin.y < Max.y)
+ return true;
+
real32 XLengthSq = 1.0f / LengthSq(XAxis);
real32 YLengthSq = 1.0f / LengthSq(YAxis);
@@ -577,7 +608,7 @@ Shape_TestBoxSelect(layer_transforms T, uint32 CompWidth, uint32 CompHeight, uin
static void
Layer_TestBoxSelect(memory *Memory, project_state *State, ui *UI, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray,
- uint16 PrincipalIndex, v2 MinPos, v2 MaxPos)
+ uint16 PrincipalIndex, layer_transforms ExtraT, v2 MinPos, v2 MaxPos)
{
block_composition *Comp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, PrincipalIndex);
sorted_comp_array SortedCompStart = SortedCompArray[PrincipalIndex];
@@ -603,6 +634,17 @@ Layer_TestBoxSelect(memory *Memory, project_state *State, ui *UI, sorted_comp_ar
}
Memory_PopScratch(Memory, sizeof(nvg_point) * 1024);
+ } else if (Layer->IsPrecomp && (Layer->IsSelected & 0x02)) {
+ int Width = 0, Height = 0;
+ Layer_GetDimensions(Memory, Layer, &Width, &Height);
+ // only like 20% sure how this works...
+ layer_transforms NewExtraT = Layer_GetTransforms(Layer);
+ v2 NewMinPos = T_CompPosToLayerPos(NewExtraT, Comp->Width, Comp->Height, Width, Height, MinPos.x, MinPos.y);
+ v2 NewMaxPos = T_CompPosToLayerPos(NewExtraT, Comp->Width, Comp->Height, Width, Height, MaxPos.x, MaxPos.y);
+ NewExtraT.rotation = ExtraT.rotation - NewExtraT.rotation;
+ NewExtraT.scale = ExtraT.scale / NewExtraT.scale;
+ Layer_TestBoxSelect(Memory, State, UI, SortedCompArray, SortedLayerArray,
+ Layer->Block_Source_Index, NewExtraT, NewMinPos, NewMaxPos);
} else {
int Width, Height;
Layer_GetDimensions(Memory, Layer, &Width, &Height);
@@ -626,7 +668,7 @@ Layer_RecursiveDeselect(memory *Memory, sorted_comp_array *SortedCompArray, sort
Layer_RecursiveDeselect(Memory, SortedCompArray, SortedLayerArray, TargetIndex, Layer->Block_Source_Index);
}
if (Layer->Block_Composition_Index != TargetIndex) {
- Layer->IsSelected = false;
+ Layer->IsSelected = 0x00;
}
}
}