summaryrefslogtreecommitdiff
path: root/src/imgui_ui_viewport.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/imgui_ui_viewport.cpp')
-rw-r--r--src/imgui_ui_viewport.cpp70
1 files changed, 38 insertions, 32 deletions
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 {