diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/createcalls.cpp | 4 | ||||
-rw-r--r-- | src/imgui_ui.cpp | 2 | ||||
-rw-r--r-- | src/imgui_ui_properties.cpp | 2 | ||||
-rw-r--r-- | src/imgui_ui_timeline.cpp | 2 | ||||
-rw-r--r-- | src/imgui_ui_viewport.cpp | 70 | ||||
-rw-r--r-- | src/include/all.h | 13 | ||||
-rw-r--r-- | src/include/functions.h | 6 | ||||
-rw-r--r-- | src/main.cpp | 95 | ||||
-rw-r--r-- | src/prenderer.cpp | 74 | ||||
-rw-r--r-- | src/sorted.cpp | 10 |
10 files changed, 198 insertions, 80 deletions
diff --git a/src/createcalls.cpp b/src/createcalls.cpp index 18ab1b7..e41a9d2 100644 --- a/src/createcalls.cpp +++ b/src/createcalls.cpp @@ -656,7 +656,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) { + if (Layer->IsSelected == 1) { if (!CommitAction) { History_Entry_Commit(Memory, "Delete layer"); CommitAction = 1; @@ -697,7 +697,7 @@ 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)) + if ((FakeOnly && SortEntry.IsFake) || (!FakeOnly && Layer->IsSelected == 1)) { if (!FakeOnly) Layer->IsSelected = false; diff --git a/src/imgui_ui.cpp b/src/imgui_ui.cpp index e77195c..c24571c 100644 --- a/src/imgui_ui.cpp +++ b/src/imgui_ui.cpp @@ -555,7 +555,7 @@ ImGui_ProcessInputs(project_data *File, project_state *State, ui *UI, memory *Me 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 && Layer->IsPrecomp) { + if ((Layer->IsSelected == 1) && Layer->IsPrecomp) { Layer->Precomp_Toggled ^= 1; } } diff --git a/src/imgui_ui_properties.cpp b/src/imgui_ui_properties.cpp index c427971..43c4a79 100644 --- a/src/imgui_ui_properties.cpp +++ b/src/imgui_ui_properties.cpp @@ -276,7 +276,7 @@ ImGui_PropertiesPanel(project_data *File, project_state *State, ui *UI, memory * if (State->MostRecentlySelectedLayer > -1) { Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, State->MostRecentlySelectedLayer, 0); sorted_comp_array SortedCompStart = SortedCompArray[Layer->Block_Composition_Index]; - sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(SortedLayerArray, &SortedCompStart, Layer->Block_Composition_Index); + sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(SortedLayerArray, SortedCompArray, Layer->Block_Composition_Index); SortedLayer = &SortedLayerStart[State->MostRecentlySelectedLayer]; if (!Layer->Occupied) Display = 0; diff --git a/src/imgui_ui_timeline.cpp b/src/imgui_ui_timeline.cpp index 6c111f1..dcb3bc2 100644 --- a/src/imgui_ui_timeline.cpp +++ b/src/imgui_ui_timeline.cpp @@ -239,7 +239,7 @@ ImGui_Timeline_DrawGraph(project_data *File, project_state *State, memory *Memor for (int c = 0; c < File->Comp_Count; c++) { sorted_comp_array SortedCompStart = SortedCompArray[c]; - sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(SortedLayerArray, &SortedCompStart, c); + sorted_layer_array *SortedLayerStart = Sorted_GetLayerStart(SortedLayerArray, SortedCompArray, c); for (int i = 0; i < SortedCompStart.LayerCount; i++) { sorted_layer_array *SortedLayer = &SortedLayerStart[i]; block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, SortedLayer->Block_Layer_Index); diff --git a/src/imgui_ui_viewport.cpp b/src/imgui_ui_viewport.cpp index 1fd5bf9..946edec 100644 --- a/src/imgui_ui_viewport.cpp +++ b/src/imgui_ui_viewport.cpp @@ -279,6 +279,10 @@ T_FindBestFit(int PointCount, v2 *PointData, v2 *Center, v2 *NewCenter, v2 *Best int a = 0; return 0; } +static void +LayerIterate(project_state *State, memory *Memory, uint32 CompIndex, layer_transforms ExtraT, v2 Center, + sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray); + static void ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Memory, ui *UI, ImGuiIO &io, ImDrawList *draw_list, @@ -300,7 +304,7 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me Interact->Scale = 1.0f; } - if (Interact->Min.x != 0.0f) { + if (Interact->Scale != 0.0f) { InteractMin = Interact->Min; InteractMax = Interact->Max; Rad = Interact->RadianOffset; @@ -626,22 +630,30 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me if (!ImGui::IsMouseDown(ImGuiMouseButton_Left)) { // A mouse release without any delta usually means the user wants - // to initiate a layer seelect. + // to initiate a layer select. ImVec2 LengthVec = (io.MousePos - io.MouseClickedPos[0]); if (fabsf(LengthVec.x) + fabsf(LengthVec.y) > 2) { Assert(State->Interact_Active == interact_type_viewport_transform_gizmo); - int h = 0, c = 0, i = 0; + // NOTE(fox): We have to go through these sorted instead of a + // Block_Loop since Interact_Transform is only saving the + // mouse's transform. History_Entry_Commit(Memory, "Transform layers"); - 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) { - 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_ApplyInteractive(State->Interact_Transform, &Layer->x.CurrentValue, &Layer->y.CurrentValue, &Layer->rotation.CurrentValue, &Layer->scale.CurrentValue); - } + + interact_transform Interact = State->Interact_Transform; + v2 BoxLength = Interact.Max - Interact.Min; + v2 Center = Interact.Max - (BoxLength/2); + if (Interact.RadianOffset != 0.0f) { + v2 LocalCenter = Interact.NewCenter; + real32 Rad = Interact.RadianOffset; + real32 Point0X = Center.x - Interact.OGCenter.x; + real32 Point0Y = Center.y - Interact.OGCenter.y; + v2 XAxis = (Point0X * 1.0f)*V2(cos(Rad), sin(Rad)); + v2 YAxis = (Point0Y * 1.0f)*V2(sin(Rad), -cos(Rad)); + Center = Interact.OGCenter + XAxis + YAxis; } + + layer_transforms T = {}; + LayerIterate(State, Memory, File->PrincipalCompIndex, T, Center, SortedCompArray, SortedLayerArray); History_Entry_End(Memory); State->UpdateFrame = true; State->UncommitedKeyframe = 1; @@ -948,9 +960,10 @@ ImGui_Viewport_TransformUI(project_data *File, project_state *State, memory *Mem } static void -ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImGuiIO &io, ImDrawList *draw_list, block_composition *MainComp, uint32 CompIndex, block_layer *ParentLayer[4], uint32 Recursions, int *PointCount, v2 *PointData, +ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImGuiIO &io, ImDrawList *draw_list, block_composition *MainComp, uint32 CompIndex, layer_transforms ExtraT, int *PointCount, v2 *PointData, 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; @@ -960,10 +973,13 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImG uint32 Index_Physical = SortEntry.Block_Layer_Index; block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, Index_Physical); if (Layer->IsPrecomp) { - ParentLayer[Recursions] = Layer; - ImGui_Viewport_SelectedLayerUI(State, Memory, UI, io, draw_list, MainComp, Layer->Block_Source_Index, ParentLayer, Recursions + 1, PointCount, PointData, SortedCompArray, SortedLayerArray); + layer_transforms NewExtraT = Layer_GetTransforms(Layer); + if (ExtraT.scale != 0) { + NewExtraT = Transform_Add(NewExtraT, ExtraT, Comp->Width, Comp->Height); + } + ImGui_Viewport_SelectedLayerUI(State, Memory, UI, io, draw_list, MainComp, Layer->Block_Source_Index, NewExtraT, PointCount, PointData, SortedCompArray, SortedLayerArray); } - if (Layer->IsSelected) { + if (Layer->IsSelected == 1) { uint32 Width = 0, Height = 0; void *Data; uint32 NumberOfVerts; @@ -992,7 +1008,6 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImG } layer_transforms T = Layer_GetTransforms(Layer); - if ((State->Interact_Active == interact_type_viewport_transform || State->Interact_Active == interact_type_viewport_transform_gizmo) && Layer->IsSelected == 1) { Transform_ApplyInteractive(State->Interact_Transform, &T.x, &T.y, &T.rotation, &T.scale); @@ -1002,6 +1017,10 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImG 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); + } + if (Layer->IsShapeLayer && State->Tool == tool_default_pointmove && State->Interact_Active == interact_type_none ) { ImGui_Viewport_ShapeUI(State, Memory, UI, io, Layer, Width, Height, &Layer->Shape, MainComp, draw_list); @@ -1040,18 +1059,6 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImG NewPos[i] = TransformPoint(T, Width, Height, BoundingPoint[i]); } - int i = 0; - while (i < Recursions) { - T = Layer_GetTransforms(ParentLayer[i]); - block_composition *Comp = (block_composition *)Memory_Block_AddressAtIndex(Memory, F_Precomps, ParentLayer[i]->Block_Source_Index); - Width = Comp->Width; - Height = Comp->Height; - for (int i = 0; i < 5; i++) { - NewPos[i] = TransformPoint(T, Width, Height, NewPos[i]); - } - i++; - } - for (int i = 0; i < 4; i++) { v2 Pos = NewPos[i+1]; PointData[*PointCount] = Pos; @@ -1165,11 +1172,10 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory, // UI+interaction for layer if (State->MostRecentlySelectedLayer > -1) { - block_layer *ParentLayer[4]; - // NOTE(fox): This min and max val is affected by interactive transforms! v2 *PointData = (v2 *)Memory_PushScratch(Memory, sizeof(v2) * 512); int PointCount = 0; - ImGui_Viewport_SelectedLayerUI(State, Memory, UI, io, draw_list, MainComp, File->PrincipalCompIndex, ParentLayer, 0, &PointCount, PointData, SortedCompArray, SortedLayerArray); + layer_transforms T = {}; + ImGui_Viewport_SelectedLayerUI(State, Memory, UI, io, draw_list, MainComp, File->PrincipalCompIndex, T, &PointCount, PointData, SortedCompArray, SortedLayerArray); if (State->Interact_Active == interact_type_viewport_transform) { ImGui_Viewport_TransformUI(File, State, Memory, UI, io, draw_list, &State->Interact_Transform, ViewportMin, MainComp->Width, MainComp->Height, SortedKeyframeArray); } else { diff --git a/src/include/all.h b/src/include/all.h index 11957af..7d7557a 100644 --- a/src/include/all.h +++ b/src/include/all.h @@ -487,14 +487,17 @@ T_CompUVToLayerUV(layer_transforms T, uint32 FileWidth, uint32 FileHeight, uint3 static v2 T_CompPosToLayerPos(layer_transforms T, uint32 FileWidth, uint32 FileHeight, uint32 SourceWidth, uint32 SourceHeight, real32 X, real32 Y); +static layer_transforms +Transform_TestInteracts(project_state *State, block_layer *Layer, sorted_layer_array SortEntry, layer_transforms T); + +static layer_transforms +Transform_Add(layer_transforms T, layer_transforms ExtraT, real32 Width, real32 Height); + 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, sorted_property_array *SortedPropertyStart, uint16 *SortedKeyframeArray, uint32 CompIndex, int32 Frame_Current); -static layer_transforms -Transform_Add(layer_transforms T, layer_transforms ExtraT); - static v2 Transform_ScreenSpaceToLocal(layer_transforms T, uint32 FileWidth, uint32 FileHeight, uint32 SourceWidth, uint32 SourceHeight, ImVec2 CompPos, ImVec2 CompZoom, ImVec2 ViewportMin, ImVec2 Point); @@ -504,6 +507,10 @@ static void Transform_ApplyInteractive(interact_transform Interact, real32 *OutputX, real32 *OutputY, real32 *OutputRotation, real32 *OutputScale); static void +LayerIterate(project_state *State, memory *Memory, uint32 CompIndex, layer_transforms ExtraT, v2 Center, + sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray); + +static void Transform_IterateOuterBounds(block_layer *Layer, uint32 Width, uint32 Height, real32 *MinX, real32 *MinY, real32 *MaxX, real32 *MaxY); static void Transform_Recurse(project_state *State, memory *Memory, block_composition *MainComp, uint32 CompIndex, block_layer *ParentLayer[4], uint32 Recursions, diff --git a/src/include/functions.h b/src/include/functions.h index 4c4ea2d..3826824 100644 --- a/src/include/functions.h +++ b/src/include/functions.h @@ -44,6 +44,12 @@ static layer_transforms Transform_Inverse(layer_transforms T); static v2 T_CompPosToLayerPos(layer_transforms T, uint32 FileWidth, uint32 FileHeight, uint32 SourceWidth, uint32 SourceHeight, real32 X, real32 Y); +static layer_transforms +Transform_TestInteracts(project_state *State, block_layer *Layer, sorted_layer_array SortEntry, layer_transforms T); + +static layer_transforms +Transform_Add(layer_transforms T, layer_transforms ExtraT, real32 Width, real32 Height); + inline void ImGui_DrawCenteredRect(ImDrawList *draw_list, ImVec2 Point, real32 Width, uint32 col) 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; diff --git a/src/prenderer.cpp b/src/prenderer.cpp index 76ac4ab..11f72f6 100644 --- a/src/prenderer.cpp +++ b/src/prenderer.cpp @@ -96,6 +96,46 @@ Transform_ApplyInteractive(interact_transform Interact, real32 *OutputX, real32 *OutputScale *= Interact.Scale; } +static v2 +TransformVec(layer_transforms T, real32 Width, real32 Height, v2 Point) +{ + real32 Rad = (T.rotation * (PI / 180)); + v2 XAxis = Point.x * T.scale * V2(cos(Rad), sin(Rad)); + v2 YAxis = Point.y * -T.scale * V2(sin(Rad), -cos(Rad)); + v2 LocalPoint = XAxis + YAxis; + return V2(LocalPoint.x, LocalPoint.y); +} + +static void +Transform_ApplyLocal(interact_transform Interact, layer_transforms T, layer_transforms ExtraT, v2 Center, + real32 CompWidth, real32 CompHeight, real32 Width, real32 Height, + real32 *OutputX, real32 *OutputY, real32 *OutputRotation, real32 *OutputScale) +{ + v2 Position = Interact.Position; + if (ExtraT.scale) { + v2 CompPosition = TransformVec(ExtraT, CompWidth, CompHeight, Interact.Position); + Position = CompPosition; + } + + real32 Point0X = Center.x - *OutputX; + real32 Point0Y = Center.y - *OutputY; + + real32 Rad = Interact.Radians; + real32 Rotation = Rad / (PI / 180); + + v2 XAxis = (Point0X * Interact.Scale)*V2(cos(Rad), sin(Rad)); + v2 YAxis = (Point0Y * -Interact.Scale)*V2(sin(Rad), -cos(Rad)); + + real32 X0 = -XAxis.x - YAxis.x + Center.x; + real32 Y0 = -XAxis.y - YAxis.y + Center.y; + + *OutputX = X0 + Position.x; + *OutputY = Y0 + Position.y; + *OutputRotation += Rotation; + // *OutputScale += Interact.Scale - 1.0f; + *OutputScale *= Interact.Scale; +} + static void Transform_IterateOuterBounds(block_layer *Layer, uint32 Width, uint32 Height, real32 *MinX, real32 *MinY, real32 *MaxX, real32 *MaxY) { @@ -279,6 +319,27 @@ Transform_Inverse(layer_transforms T) return T; } +static layer_transforms +Transform_TestInteracts(project_state *State, block_layer *Layer, sorted_layer_array SortEntry, layer_transforms T) +{ + 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]; + } + return T; +} + static layer_transforms Transform_Add(layer_transforms T, layer_transforms ExtraT, real32 Width, real32 Height) { @@ -292,6 +353,19 @@ Transform_Add(layer_transforms T, layer_transforms ExtraT, real32 Width, real32 return T; } +static layer_transforms +Transform_Add2(layer_transforms T, layer_transforms ExtraT, real32 Width, real32 Height) +{ + v2 NewPos = TransformPoint(ExtraT, Width, Height, V2(T.x, T.y)); + T.x = NewPos.x; + T.y = NewPos.y; + T.ax = T.ax; + T.ay = T.ay; + T.rotation = T.rotation - ExtraT.rotation; + T.scale = T.scale / ExtraT.scale; + return T; +} + static ImVec2 Layer_LocalToScreenSpace(project_state *State, memory *Memory, block_layer *Layer, ui *UI, uint32 PrincipalCompIndex, v2 Point) { diff --git a/src/sorted.cpp b/src/sorted.cpp index 03f5b0a..1d2b4f2 100644 --- a/src/sorted.cpp +++ b/src/sorted.cpp @@ -17,14 +17,16 @@ Property_GetSortedArray(uint16 *SortedKeyframeArray, int i, int h) } static sorted_layer_array * -Sorted_GetLayerStart(sorted_layer_array *LayerArrayStart, sorted_comp_array *SortedCompStart, uint32 TargetComp) +Sorted_GetLayerStart(sorted_layer_array *SortedLayerArray, sorted_comp_array *SortedCompArray, uint32 TargetComp) { uint32 LayerOffset = 0; int s = 0; while (s < TargetComp) { - LayerOffset += SortedCompStart[s].LayerCount + SortedCompStart[s].FakeLayerCount; + Assert(SortedCompArray[s].LayerCount < 10000); // passed Start instead of Array! + Assert(SortedCompArray[s].FakeLayerCount < 10000); + LayerOffset += SortedCompArray[s].LayerCount + SortedCompArray[s].FakeLayerCount; s++; } - return LayerArrayStart + LayerOffset; + return SortedLayerArray + LayerOffset; } // The sorting algorithm is straightforward: read every point, evaluate it if @@ -122,6 +124,8 @@ Layer_Sort_DisplayOffset(project_state *State, memory *Memory, // real32 SmallestY = Layer_Top->Vertical_Offset; // real32 LargestY = Layer_Bottom->Vertical_Offset; DisplayOffset = LargestY - SmallestY + 2 + DisplayOffset; + } else { + DisplayOffset = 2; } return DisplayOffset; } |