summaryrefslogtreecommitdiff
path: root/src/layer.cpp
diff options
context:
space:
mode:
authorFox Caminiti <fox@foxcam.net>2023-02-07 00:21:06 -0500
committerFox Caminiti <fox@foxcam.net>2023-02-07 00:21:06 -0500
commitee654e9217487f6fca12356ec8af82319c309592 (patch)
tree7b87b83ed9087b73b733555243a66d3d0c93e900 /src/layer.cpp
parente2e0e630ca51a4fd80a8186c5795c96693a2815b (diff)
good changes
Diffstat (limited to 'src/layer.cpp')
-rw-r--r--src/layer.cpp52
1 files changed, 35 insertions, 17 deletions
diff --git a/src/layer.cpp b/src/layer.cpp
index dfe91a4..4c94987 100644
--- a/src/layer.cpp
+++ b/src/layer.cpp
@@ -211,7 +211,12 @@ Layer_DeselectAll(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);
- Layer->IsSelected = false;
+ // stupid way to preserve this
+ if (Layer->IsSelected == -1) {
+ Layer->IsSelected = 2;
+ } else {
+ Layer->IsSelected = false;
+ }
}
State->Interact_Transform = {};
State->MostRecentlySelectedLayer = -1;
@@ -372,11 +377,11 @@ Layer_TraverseForPoint(project_data *File, project_state *State, memory *Memory,
// TODO(fox): Precomps?
static bool32
-Layer_TestForPoint(memory *Memory, project_state *State, ui *UI, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, uint16 PrincipalIndex, v2 CompUV)
+Layer_TestForPoint(memory *Memory, project_state *State, ui *UI, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, uint16 CompIndex, v2 CompUV)
{
- block_composition *Comp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, PrincipalIndex);
- sorted_comp_array SortedCompStart = SortedCompArray[PrincipalIndex];
- sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(SortedLayerArray, SortedCompArray, PrincipalIndex);
+ block_composition *Comp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, CompIndex);
+ sorted_comp_array SortedCompStart = SortedCompArray[CompIndex];
+ sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(SortedLayerArray, SortedCompArray, CompIndex);
for (int i = SortedCompStart.LayerCount - 1; i >= 0; i--) {
sorted_layer_array SortEntry = SortedLayerStart[i];
uint32 Index_Physical = SortEntry.Block_Layer_Index;
@@ -385,7 +390,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)
+ if (UV.x <= 1.0f && UV.x >= 0.0f && UV.y <= 1.0f && UV.y >= 0.0f && (Layer->IsSelected || Layer->IsPrecomp) && !Layer->IsLocked)
{
return 1;
}
@@ -393,15 +398,16 @@ Layer_TestForPoint(memory *Memory, project_state *State, ui *UI, sorted_comp_arr
return 0;
}
+// Same loop as Render_UI and ImGui_Viewport_SelectedLayerUI except we're
// NOTE(fox): We loop twice to allow for convenient down-travelling when only
// one layer is selected, toggleable by the BelowOnly bool (i.e. shift held).
-// TODO(fox): Precomps?
+#if 0
static int32
-Layer_TestSelection(memory *Memory, project_state *State, ui *UI, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, uint16 PrincipalIndex, bool32 BelowOnly)
+Layer_TestSelection(memory *Memory, project_state *State, ui *UI, sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, uint16 CompIndex, bool32 BelowOnly)
{
- block_composition *Comp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, PrincipalIndex);
- sorted_comp_array SortedCompStart = SortedCompArray[PrincipalIndex];
- sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(SortedLayerArray, SortedCompArray, PrincipalIndex);
+ block_composition *Comp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, CompIndex);
+ sorted_comp_array SortedCompStart = SortedCompArray[CompIndex];
+ sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(SortedLayerArray, SortedCompArray, CompIndex);
int SelectionCount = 0;
int SelectedLayerIndex = 0;
for (int i = SortedCompStart.LayerCount - 1; i >= 0; i--) {
@@ -427,16 +433,27 @@ Layer_TestSelection(memory *Memory, project_state *State, ui *UI, sorted_comp_ar
Layer_GetDimensions(Memory, Layer, &Width, &Height);
layer_transforms T = Layer_GetTransforms(Layer);
v2 UV = T_CompUVToLayerUV(T, Comp->Width, Comp->Height, Width, Height, State->LastClickedPoint);
- if (UV.x <= 1.0f && UV.x >= 0.0f && UV.y <= 1.0f && UV.y >= 0.0f && !Layer->IsSelected && !Layer->IsLocked)
+ if (UV.x <= 1.0f && UV.x >= 0.0f && UV.y <= 1.0f && UV.y >= 0.0f && (!Layer->IsSelected || (Layer->IsPrecomp && Layer->IsSelected)) && !Layer->IsLocked)
{
- if (!BelowOnly && SelectionCount == 1) {
- if (i < SelectedLayerIndex) {
+ if (Layer->IsPrecomp) {
+ layer_transforms T = Layer_GetTransforms(Layer);
+ if (ExtraT.scale != 0) {
+ T = Transform_Add(T, ExtraT, Comp->Width, Comp->Height);
+ }
+ T = Transform_TestInteracts(State, Layer, SortEntry, T);
+ LayerIndex = Layer_TestSelection(Memory, State, UI, SortedCompArray, SortedLayerArray, Layer->Block_Source_Index, BelowOnly);
+ if (LayerIndex != -1)
+ break;
+ } else {
+ if (!BelowOnly && SelectionCount == 1) {
+ if (i < SelectedLayerIndex) {
+ LayerIndex = Index_Physical;
+ break;
+ }
+ } else {
LayerIndex = Index_Physical;
break;
}
- } else {
- LayerIndex = Index_Physical;
- break;
}
}
// if (Layer->IsPrecomp) {
@@ -448,6 +465,7 @@ Layer_TestSelection(memory *Memory, project_state *State, ui *UI, sorted_comp_ar
}
return LayerIndex;
}
+#endif
// TODO(fox): learn this; stop stealing from stackoverflow
bool32 Line_TestIntersect(real32 p0_x, real32 p0_y, real32 p1_x, real32 p1_y,