summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp95
1 files changed, 58 insertions, 37 deletions
diff --git a/src/main.cpp b/src/main.cpp
index e5fae1d..c7e4808 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -345,6 +345,57 @@ GL_Test(const ImDrawList* parent_list, const ImDrawCmd* cmd)
GL_DeleteHWBuffer(&MSBuffer);
}
+// Same loop as Render_UI and ImGui_Viewport_SelectedLayerUI except we're
+// finding the inverse transform-- i.e. transforming the layers locally rather
+// than transforming them in comp space.
+static void
+LayerIterate(project_state *State, memory *Memory, uint32 CompIndex, layer_transforms ExtraT, v2 Center,
+ sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray)
+{
+ 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 LayerCount = SortedCompStart->LayerCount + SortedCompStart->FakeLayerCount;
+ for (int i = 0; i < LayerCount; i++)
+ {
+ 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);
+ int Width = 0, Height = 0;
+ Layer_GetDimensions(Memory, Layer, &Width, &Height);
+ if (Layer->IsPrecomp) {
+ // only like 20% sure how this works...
+ layer_transforms NewExtraT = Layer_GetTransforms(Layer);
+ v2 NewCenter = T_CompPosToLayerPos(NewExtraT, Comp->Width, Comp->Height, Width, Height, Center.x, Center.y);
+ if (State->Interact_Transform.Radians != 0.0f)
+ NewExtraT.rotation = -NewExtraT.rotation;
+ if (ExtraT.scale) {
+ NewExtraT = Transform_Add2(ExtraT, NewExtraT, Comp->Width, Comp->Height);
+ v2 NewPos = T_CompPosToLayerPos(NewExtraT, Comp->Width, Comp->Height, Width, Height, NewExtraT.x, NewExtraT.y);
+ NewExtraT.x = NewPos.x;
+ NewExtraT.y = NewPos.y;
+ } else {
+ NewExtraT.rotation = -NewExtraT.rotation;
+ NewExtraT.scale = 1.0f / NewExtraT.scale;
+ }
+ LayerIterate(State, Memory, Layer->Block_Source_Index, NewExtraT, NewCenter, SortedCompArray, SortedLayerArray);
+ }
+ if (Layer->IsSelected == 1) {
+#if DEBUG
+ if (Layer->IsPrecomp)
+ PostMsg(State, "DEBUG: Precomp transformed!");
+#endif
+ layer_transforms T = Layer_GetTransforms(Layer);
+ History_Action_Swap(Memory, F_Layers, sizeof(Layer->x.CurrentValue), &Layer->x.CurrentValue);
+ History_Action_Swap(Memory, F_Layers, sizeof(Layer->y.CurrentValue), &Layer->y.CurrentValue);
+ History_Action_Swap(Memory, F_Layers, sizeof(Layer->scale.CurrentValue), &Layer->scale.CurrentValue);
+ History_Action_Swap(Memory, F_Layers, sizeof(Layer->rotation.CurrentValue), &Layer->rotation.CurrentValue);
+ Transform_ApplyLocal(State->Interact_Transform, T, ExtraT, Center, Comp->Width, Comp->Height, Width, Height,
+ &Layer->x.CurrentValue, &Layer->y.CurrentValue, &Layer->rotation.CurrentValue, &Layer->scale.CurrentValue);
+ }
+ }
+}
+
static uint8 *
Render_UI(project_data *File, project_state *State, memory *Memory, ui *UI, ImDrawList *draw_list, uint8 *PointBuffer, gl_viewport_data *RenderData,
sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray, layer_transforms ExtraT,
@@ -378,24 +429,10 @@ Render_UI(project_data *File, project_state *State, memory *Memory, ui *UI, ImDr
Frame_End_Abs > Frame_Current && Layer->IsVisible)
{
layer_transforms T = Layer_GetTransforms(Layer);
- if (State->Interact_Active == interact_type_viewport_transform && Layer->IsSelected == 1) {
- Transform_ApplyInteractive(State->Interact_Transform, &T.x, &T.y, &T.rotation, &T.scale);
- }
- if (State->Interact_Active == interact_type_viewport_transform_gizmo && Layer->IsSelected == 1) {
- Transform_ApplyInteractive(State->Interact_Transform, &T.x, &T.y, &T.rotation, &T.scale);
- }
- if (State->Interact_Active == interact_type_viewport_slide && Layer->IsSelected == 1) {
- Assert(0);
- // Transform_ApplySlide((v2 *)&State->Interact_Offset[0], &T);
- }
- if (State->Interact_Active == interact_type_viewport_duplicate && SortEntry.IsFake) {
- Assert(Layer->IsSelected);
- T.x += State->Interact_Offset[0];
- T.y += State->Interact_Offset[1];
- }
if (ExtraT.scale != 0) {
T = Transform_Add(T, ExtraT, Comp->Width, Comp->Height);
}
+ T = Transform_TestInteracts(State, Layer, SortEntry, T);
if (Layer->IsShapeLayer) {
void *Data = PointBuffer;
@@ -429,33 +466,17 @@ Render_UI(project_data *File, project_state *State, memory *Memory, ui *UI, ImDr
} else if (Layer->IsPrecomp) {
layer_transforms NewExtraT = Layer_GetTransforms(Layer);
- if (State->Interact_Active == interact_type_viewport_transform && Layer->IsSelected == 1) {
- Transform_ApplyInteractive(State->Interact_Transform, &NewExtraT.x, &NewExtraT.y, &NewExtraT.rotation, &NewExtraT.scale);
- }
- if (State->Interact_Active == interact_type_viewport_transform_gizmo && Layer->IsSelected == 1) {
- Transform_ApplyInteractive(State->Interact_Transform, &NewExtraT.x, &NewExtraT.y, &NewExtraT.rotation, &NewExtraT.scale);
- }
- if (State->Interact_Active == interact_type_viewport_slide && Layer->IsSelected == 1) {
- Assert(0);
- // Transform_ApplySlide((v2 *)&State->Interact_Offset[0], &T);
- }
- if (State->Interact_Active == interact_type_viewport_duplicate && SortEntry.IsFake) {
- Assert(Layer->IsSelected);
- NewExtraT.x += State->Interact_Offset[0];
- NewExtraT.y += State->Interact_Offset[1];
- }
+ NewExtraT = Transform_TestInteracts(State, Layer, SortEntry, NewExtraT);
if (ExtraT.scale != 0) {
- ExtraT = Transform_Add(NewExtraT, ExtraT, Comp->Width, Comp->Height);
- } else {
- ExtraT = NewExtraT;
- }
+ NewExtraT = Transform_Add(NewExtraT, ExtraT, Comp->Width, Comp->Height);
+ }
gl_data *GL_Data = RenderData->LayerEntry[RenderData->LayerCount] = (gl_data *)PointBuffer;
RenderData->LayerCount++;
PointBuffer += sizeof(gl_data);
int Width = 0, Height = 0;
Layer_GetDimensions(Memory, Layer, &Width, &Height);
GL_Data->Type = 1;
- GL_Data->T = ExtraT;
+ GL_Data->T = NewExtraT;
GL_Data->Width = Width;
GL_Data->Height = Height;
GL_Data->FillData = PointBuffer;
@@ -470,14 +491,14 @@ Render_UI(project_data *File, project_state *State, memory *Memory, ui *UI, ImDr
GL_Data->FillCount = 4;
PointBuffer = Render_UI(File, State, Memory, UI, draw_list, PointBuffer, RenderData,
- SortedCompArray, SortedLayerArray, ExtraT,
+ SortedCompArray, SortedLayerArray, NewExtraT,
SortedPropertyStart, SortedKeyframeArray, Layer->Block_Source_Index, Frame_Current);
GL_Data = RenderData->LayerEntry[RenderData->LayerCount] = (gl_data *)PointBuffer;
RenderData->LayerCount++;
PointBuffer += sizeof(gl_data);
GL_Data->Type = 2;
- GL_Data->T = ExtraT;
+ GL_Data->T = NewExtraT;
GL_Data->Width = Width;
GL_Data->Height = Height;
GL_Data->FillData = PointBuffer;