summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/imgui_ui.cpp3
-rw-r--r--src/imgui_ui_viewport.cpp320
-rw-r--r--src/include/main.h4
-rw-r--r--src/layer.cpp2
-rw-r--r--src/main.cpp8
-rw-r--r--src/prenderer.cpp12
6 files changed, 299 insertions, 50 deletions
diff --git a/src/imgui_ui.cpp b/src/imgui_ui.cpp
index bfb79f3..727514b 100644
--- a/src/imgui_ui.cpp
+++ b/src/imgui_ui.cpp
@@ -1,3 +1,4 @@
+#include "imgui.h"
#if SPECIAL
#include "main.h"
#endif
@@ -10,6 +11,8 @@ ImGui_File(project_data *File, project_state *State, memory *Memory, ImGuiIO io,
ImGui::Text("%s: %hu", "Layers", File->Layer_Count);
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
+ ImGui::SliderFloat("aaa", &aaa, -10, 10);
+
if (ImGui::IsKeyPressed(ImGuiKey_Backspace)) {
// TODO(fox): Delete sources code!
diff --git a/src/imgui_ui_viewport.cpp b/src/imgui_ui_viewport.cpp
index 2012354..2604991 100644
--- a/src/imgui_ui_viewport.cpp
+++ b/src/imgui_ui_viewport.cpp
@@ -388,34 +388,109 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
}
#endif
+static real32
+T_AreaAtAngle(int PointCount, v2 *PointData, v2 Center, real32 Rotation, v2 *CurrentMin, v2 *CurrentMax)
+{
+ v2 Min = V2(10000, 10000), Max = V2(-10000, -10000);
+ real32 Rad = (Rotation * (PI / 180));
+ for (int i = 0; i < PointCount; i++) {
+ v2 Pos = PointData[i];
+ v2 XAxis = (Pos.x - Center.x) * V2(cos(Rad), sin(Rad));
+ v2 YAxis = (Pos.y - Center.y) * V2(sin(Rad), -cos(Rad));
+
+ Pos = XAxis + YAxis;
+ if (Pos.x < Min.x) { Min.x = Pos.x; }
+ if (Pos.y < Min.y) { Min.y = Pos.y; }
+ if (Pos.x > Max.x) { Max.x = Pos.x; }
+ if (Pos.y > Max.y) { Max.y = Pos.y; }
+ }
+ v2 Dimensions = Max - Min;
+ *CurrentMin = Min + Center;
+ *CurrentMax = Max + Center;
+ return Dimensions.x * Dimensions.y;
+}
+
+static real32
+T_FindBestFit(int PointCount, v2 *PointData, v2 *Center, v2 *NewCenter, v2 *BestMin, v2 *BestMax, real32 *BestRadians)
+{
+ v2 Min = V2(10000, 10000), Max = V2(-10000, -10000);
+ for (int i = 0; i < PointCount; i++) {
+ v2 Pos = PointData[i];
+ if (Pos.x < Min.x) { Min.x = Pos.x; }
+ if (Pos.y < Min.y) { Min.y = Pos.y; }
+ if (Pos.x > Max.x) { Max.x = Pos.x; }
+ if (Pos.y > Max.y) { Max.y = Pos.y; }
+ }
+ v2 Dimensions = Max - Min;
+ *Center = Min + Dimensions/2;
+ real32 BestArea = Dimensions.x * Dimensions.y;
+ *BestMin = Min;
+ *BestMax = Max;
+ *BestRadians = 0;
+ // real32 Angles[4] = { 15, 30, 45, 60 };
+ for (real32 i = 0; i < 90; i+= 1) {
+ v2 NewMin = {}, NewMax = {};
+ real32 NewArea = T_AreaAtAngle(PointCount, PointData, *Center, i, &NewMin, &NewMax);
+ if (NewArea < BestArea) {
+ BestArea = NewArea;
+ v2 NewDim = NewMax - NewMin;
+ // *BestMin = Center - (NewDim/2);
+ // *BestMax = Center + (NewDim/2);
+ *NewCenter = Min + (NewDim / 2);
+ *BestMin = NewMin;
+ *BestMax = NewMax;
+ *BestRadians = (real32)i * (PI / 180);
+ }
+ }
+ int a = 0;
+ return 0;
+}
+
+static real32 bbb = 0;
+
static void
ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Memory, ui *UI, ImGuiIO &io, ImDrawList *draw_list,
- v2 Min, v2 Max, ImVec2 ViewportMin, uint32 CompWidth, uint32 CompHeight, uint16 *SortedKeyframeArray)
+ int *PointCount, v2 *PointData, ImVec2 ViewportMin, uint32 CompWidth, uint32 CompHeight, uint16 *SortedKeyframeArray)
{
- interact_transform *Interact = (interact_transform *)&State->Interact_Offset[0];
+ interact_transform *Interact = &State->Interact_Transform;
- v2 InteractMin = Min;
- v2 InteractMax = Max;
+ v2 InteractMin = {};
+ v2 InteractMax = {};
real32 Rad = 0;
+ real32 Rad2 = bbb;
real32 Scale = 1;
+ if (Interact->Min.x == 0.0f) {
+ T_FindBestFit(*PointCount, PointData, &Interact->OGCenter, &Interact->NewCenter, &Interact->Min, &Interact->Max, &Interact->RadianOffset);
+ // Interact->RadianOffset +=
+ Interact->Scale = 1.0f;
+ }
+
if (Interact->Min.x != 0.0f) {
InteractMin = Interact->Min + Interact->Position;
InteractMax = Interact->Max + Interact->Position;
- Rad = Interact->Radians;
+ Rad = Interact->RadianOffset; // + (aaa * (PI / 180));
+ bbb += 0.08;
Scale = Interact->Scale;
- }
+ }
+ real32 Angle = Interact->RadianOffset / (PI / 180);
DebugWatchVar("Rad", &Interact->Radians, d_float);
+ DebugWatchVar("bestangle", &Angle, d_float);
v2 BoxLength = InteractMax - InteractMin;
- v2 Center = InteractMax - (BoxLength/2);
+ // v2 Center = (Interact->OGCenter.x != 0) ? Interact->OGCenter : InteractMax - (BoxLength/2);
+ // v2 Center = (Interact->OGCenter.x != 0) ? Interact->OGCenter : InteractMax - (BoxLength/2);
+ // v2 Center = InteractMax - (BoxLength/2) + V2(aaa, aaa);
+
+#if 0
+ v2 Center = Interact->OGCenter;
real32 Point0X = Center.x - InteractMin.x;
real32 Point0Y = Center.y - InteractMin.y;
v2 XAxis = (Point0X * Scale)*V2(cos(Rad), sin(Rad));
- v2 YAxis = (Point0Y * -Scale)*V2(sin(Rad), -cos(Rad));
+ v2 YAxis = (Point0Y * Scale)*V2(sin(Rad), -cos(Rad));
// Points are clockwise starting from the top left.
real32 X0 = -XAxis.x - YAxis.x + Center.x;
@@ -436,20 +511,171 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
real32 Mid_Y2 = Y2 - XAxis.y;
real32 Mid_X3 = X3 - YAxis.x;
real32 Mid_Y3 = Y3 - YAxis.y;
+#elif 0
+ v2 Center = Interact->OGCenter;
+ v2 NewCenter = Interact->NewCenter;
+
+ real32 X0 = Center.x;
+ real32 Y0 = Center.y;
+ real32 X1 = Center.x;
+ real32 Y1 = Center.y;
+ real32 X2 = Center.x;
+ real32 Y2 = Center.y;
+ real32 X3 = Center.x;
+ real32 Y3 = Center.y;
+
+ {
+ real32 Point0X = InteractMin.x - Center.x;
+ real32 Point0Y = InteractMin.y - Center.y;
+ v2 XAxis = (Point0X * Scale)*V2(cos(Rad), sin(Rad));
+ v2 YAxis = (Point0Y * Scale)*V2(sin(Rad), -cos(Rad));
+ v2 Pos = XAxis + YAxis;
+ X0 += Pos.x;
+ Y0 += Pos.y;
+ }
+ {
+ real32 Point0X = InteractMax.x - Center.x;
+ real32 Point0Y = InteractMin.y - Center.y;
+ v2 XAxis = (Point0X * Scale)*V2(cos(Rad), sin(Rad));
+ v2 YAxis = (Point0Y * Scale)*V2(sin(Rad), -cos(Rad));
+ v2 Pos = XAxis + YAxis;
+ X1 += Pos.x;
+ Y1 += Pos.y;
+ }
+ {
+ real32 Point0X = InteractMax.x - Center.x;
+ real32 Point0Y = InteractMax.y - Center.y;
+ v2 XAxis = (Point0X * Scale)*V2(cos(Rad), sin(Rad));
+ v2 YAxis = (Point0Y * Scale)*V2(sin(Rad), -cos(Rad));
+ v2 Pos = XAxis + YAxis;
+ X2 += Pos.x;
+ Y2 += Pos.y;
+ }
+ {
+ real32 Point0X = InteractMin.x - Center.x;
+ real32 Point0Y = InteractMax.y - Center.y;
+ v2 XAxis = (Point0X * Scale)*V2(cos(Rad), sin(Rad));
+ v2 YAxis = (Point0Y * Scale)*V2(sin(Rad), -cos(Rad));
+ v2 Pos = XAxis + YAxis;
+ X3 += Pos.x;
+ Y3 += Pos.y;
+ }
+#else
+ v2 Center = Interact->OGCenter;
+
+ v2 PosL[4] = {};
+ v2 PosS[4] = { InteractMin, V2(InteractMax.x, InteractMin.y), InteractMax, V2(InteractMin.x, InteractMax.y) };
+
+ v2 LocalCenter = InteractMax - (BoxLength/2);
+ v2 NewCenter = {};
+ real32 Point0X = LocalCenter.x - Center.x;
+ real32 Point0Y = LocalCenter.y - Center.y;
+ v2 XAxis = (Point0X * Scale)*V2(cos(Rad), sin(Rad));
+ v2 YAxis = (Point0Y * Scale)*V2(sin(Rad), -cos(Rad));
+ v2 Pos = XAxis + YAxis;
+ NewCenter.x = Center.x + Pos.x;
+ NewCenter.y = Center.y + Pos.y;
+
+ for (int i = 0; i < 4; i++) {
+ real32 Point0X = PosS[i].x - Center.x;
+ real32 Point0Y = PosS[i].y - Center.y;
+ v2 XAxis = (Point0X * Scale)*V2(cos(Rad), sin(Rad));
+ v2 YAxis = (Point0Y * Scale)*V2(sin(Rad), -cos(Rad));
+ v2 Pos = XAxis + YAxis;
+ PosL[i].x = Center.x + Pos.x;
+ PosL[i].y = Center.y + Pos.y;
+ Point0X = PosL[i].x - NewCenter.x;
+ Point0Y = PosL[i].y - NewCenter.y;
+ XAxis = (Point0X * Scale)*V2(cos(Rad2), sin(Rad2));
+ YAxis = (Point0Y * Scale)*V2(sin(Rad2), -cos(Rad2));
+ v2 NewPos = XAxis + YAxis;
+ PosL[i].x = NewCenter.x + NewPos.x;
+ PosL[i].y = NewCenter.y + NewPos.y;
+ }
ImVec2 CompScale = UI->CompZoom / ImVec2(CompWidth, CompHeight);
ImVec2 P[4];
+ P[0] = IV2(PosL[0])*CompScale + UI->CompPos;
+ P[1] = IV2(PosL[1])*CompScale + UI->CompPos;
+ P[2] = IV2(PosL[2])*CompScale + UI->CompPos;
+ P[3] = IV2(PosL[3])*CompScale + UI->CompPos;
+
+ ImU32 wcol = IM_COL32(0, 0, 255, 255);
+ draw_list->AddLine(P[0], P[1], wcol, 2.0f);
+ draw_list->AddLine(P[1], P[2], wcol, 2.0f);
+ draw_list->AddLine(P[2], P[3], wcol, 2.0f);
+ draw_list->AddLine(P[3], P[0], wcol, 2.0f);
+
+ draw_list->AddLine(P[0], P[2], wcol, 1.0f);
+ draw_list->AddLine(P[1], P[3], wcol, 1.0f);
+}
+
+#endif
+
+#if 0
+ ImVec2 CompScale = UI->CompZoom / ImVec2(CompWidth, CompHeight);
+
+ ImVec2 P[4];
P[0] = ImVec2(X0, Y0)*CompScale + UI->CompPos;
P[1] = ImVec2(X1, Y1)*CompScale + UI->CompPos;
P[2] = ImVec2(X2, Y2)*CompScale + UI->CompPos;
P[3] = ImVec2(X3, Y3)*CompScale + UI->CompPos;
- ImVec2 Mid_P[4];
- Mid_P[0] = ImVec2(Mid_X0, Mid_Y0)*CompScale + UI->CompPos;
- Mid_P[1] = ImVec2(Mid_X1, Mid_Y1)*CompScale + UI->CompPos;
- Mid_P[2] = ImVec2(Mid_X2, Mid_Y2)*CompScale + UI->CompPos;
- Mid_P[3] = ImVec2(Mid_X3, Mid_Y3)*CompScale + UI->CompPos;
+ // ImVec2 Mid_P[4];
+ // Mid_P[0] = ImVec2(Mid_X0, Mid_Y0)*CompScale + UI->CompPos;
+ // Mid_P[1] = ImVec2(Mid_X1, Mid_Y1)*CompScale + UI->CompPos;
+ // Mid_P[2] = ImVec2(Mid_X2, Mid_Y2)*CompScale + UI->CompPos;
+ // Mid_P[3] = ImVec2(Mid_X3, Mid_Y3)*CompScale + UI->CompPos;
+
+ {
+ ImU32 wcol = IM_COL32(0, 0, 255, 255);
+ v2 Min = V2(10000, 10000), Max = V2(-10000, -10000);
+ for (int i = 0; i < *PointCount; i++) {
+ v2 Pos = PointData[i];
+ if (Pos.x < Min.x) { Min.x = Pos.x; }
+ if (Pos.y < Min.y) { Min.y = Pos.y; }
+ if (Pos.x > Max.x) { Max.x = Pos.x; }
+ if (Pos.y > Max.y) { Max.y = Pos.y; }
+ }
+ v2 Dimensions = Max - Min;
+ v2 Center = Min + Dimensions/2;
+ ImVec2 P[4] = { IV2(Min), ImVec2(Max.x, Min.y), IV2(Max), ImVec2(Min.x, Max.y) };
+ P[0] = P[0]*CompScale + UI->CompPos;
+ P[1] = P[1]*CompScale + UI->CompPos;
+ P[2] = P[2]*CompScale + UI->CompPos;
+ P[3] = P[3]*CompScale + UI->CompPos;
+ ImVec2 C = IV2(Center)*CompScale + UI->CompPos;
+ draw_list->AddNgon(C, 10, wcol, 8, 9.0f);
+ /*
+ for (int i = 0; i < *PointCount; i++) {
+ v2 Pos = PointData[i];
+ v2 XAxis = (Pos.x - Center.x) * V2(cos(Rad), sin(Rad));
+ v2 YAxis = (Pos.y - Center.y) * V2(sin(Rad), -cos(Rad));
+ Pos = XAxis + YAxis;
+ ImVec2 PosS = IV2(Pos)*CompScale + UI->CompPos;
+ draw_list->AddNgon(PosS, 10, wcol, 8, 9.0f);
+ }*/
+ draw_list->AddLine(P[0], P[1], wcol, 2.0f);
+ draw_list->AddLine(P[1], P[2], wcol, 2.0f);
+ draw_list->AddLine(P[2], P[3], wcol, 2.0f);
+ draw_list->AddLine(P[3], P[0], wcol, 2.0f);
+ }
+ {
+ ImU32 wcol = IM_COL32(255, 0, 255, 255);
+ v2 Min = Interact->Min, Max = Interact->Max;
+ ImVec2 P[4] = { IV2(Min), ImVec2(Max.x, Min.y), IV2(Max), ImVec2(Min.x, Max.y) };
+ P[0] = P[0]*CompScale + UI->CompPos;
+ P[1] = P[1]*CompScale + UI->CompPos;
+ P[2] = P[2]*CompScale + UI->CompPos;
+ P[3] = P[3]*CompScale + UI->CompPos;
+ ImVec2 C = IV2(Center)*CompScale + UI->CompPos;
+ draw_list->AddNgon(C, 10, wcol, 8, 9.0f);
+ draw_list->AddLine(P[0], P[1], wcol, 2.0f);
+ draw_list->AddLine(P[1], P[2], wcol, 2.0f);
+ draw_list->AddLine(P[2], P[3], wcol, 2.0f);
+ draw_list->AddLine(P[3], P[0], wcol, 2.0f);
+ }
ImU32 wcol = ImGui::GetColorU32(ImGuiCol_Text);
draw_list->AddLine(P[0], P[1], wcol, 2.0f);
@@ -457,11 +683,14 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
draw_list->AddLine(P[2], P[3], wcol, 2.0f);
draw_list->AddLine(P[3], P[0], wcol, 2.0f);
+ draw_list->AddLine(P[0], P[2], wcol, 1.0f);
+ draw_list->AddLine(P[1], P[3], wcol, 1.0f);
+
v2 XAxis2 = (BoxLength*CompScale.x)*V2(cos(Rad), sin(Rad));
v2 YAxis2 = (BoxLength*CompScale.y)*V2(sin(Rad), -cos(Rad));
- v2 XAxisPerp = (1.0f / LengthSq(XAxis))*XAxis;
- v2 YAxisPerp = (1.0f / LengthSq(YAxis))*YAxis;
+ // v2 XAxisPerp = (1.0f / LengthSq(XAxis))*XAxis;
+ // v2 YAxisPerp = (1.0f / LengthSq(YAxis))*YAxis;
// real32 LocalX = ((io.MousePos.x - UI->CompPos.x) - Center.x) ;
// real32 LocalY = ((io.MousePos.y - UI->CompPos.y) - Center.y) ;
@@ -529,11 +758,6 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
else
State->InteractTransformMode = 2;
State->Interact_Active = interact_type_viewport_transform_gizmo;
- if (Interact->Max.x == 0) {
- *Interact = {};
- Interact->Min = Min;
- Interact->Max = Max;
- }
}
// Scale part
@@ -565,9 +789,25 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
// Rotation part
if (State->InteractTransformMode == 2 && ImGui::IsItemActive())
{
- real32 LocalX = (io.MousePos.x - UI->CompPos.x)/CompScale.x - InteractMin.x - (BoxLength.x/2);
- real32 LocalY = (io.MousePos.y - UI->CompPos.y)/CompScale.y - InteractMin.y - (BoxLength.y/2);
+ v2 Vector0 = V2(io.MouseClickedPos[0] - UI->CompPos)/V2(CompScale) - InteractMin - (BoxLength/2);
+ v2 Vector1 = V2(io.MousePos - UI->CompPos)/V2(CompScale) - InteractMin - (BoxLength/2);
+ Vector0 = Vector0 * V2(1, -1);
+ Vector1 = Vector1 * V2(1, -1);
+
+ real32 Length0 = Length(Vector0);
+ real32 Length1 = Length(Vector1);
+
+ real32 Direction = (Inner(V2(Vector0.y, -Vector0.x), Vector1) < 0.0f) ? -1 : 1;
+ real32 MouseRadians = acosf(Inner(Vector0, Vector1) / (Length0 * Length1));
+
+ if (isnan(MouseRadians))
+ MouseRadians = 0.0f;
+ Interact->Radians = Direction * MouseRadians;
+ }
+#endif
+
+#if 0
real32 Slope_Mouse = LocalY/LocalX;
real32 Slope_Corner = 0;
real32 Slope_Flipped = 0;
@@ -622,11 +862,6 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
ImGui::Button("##mover", ScaleHandleSize);
if (!State->InteractTransformMode && ImGui::IsItemActivated() && !OtherActions) {
State->Interact_Active = interact_type_viewport_transform_gizmo;
- if (Interact->Max.x == 0) {
- *Interact = {};
- Interact->Min = Min;
- Interact->Max = Max;
- }
State->InteractTransformMode = 3;
}
}
@@ -652,12 +887,12 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
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(*(interact_transform *)&State->Interact_Offset[0], &Layer->x.CurrentValue, &Layer->y.CurrentValue, &Layer->rotation.CurrentValue, &Layer->scale.CurrentValue);
+ Transform_ApplyInteractive(State->Interact_Transform, &Layer->x.CurrentValue, &Layer->y.CurrentValue, &Layer->rotation.CurrentValue, &Layer->scale.CurrentValue);
}
}
History_Entry_End(Memory);
State->Interact_Active = interact_type_none;
- // *Interact = {};
+ State->Interact_Transform = {};
State->UpdateFrame = true;
State->InteractTransformMode = 0;
State->Interact_Modifier = 0;
@@ -669,8 +904,8 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
if (InBounds == true) {
ImGui::PopStyleColor();
}
+#endif
-}
static void
ImGui_Viewport_TransformUI(project_data *File, project_state *State, memory *Memory, ui *UI, ImGuiIO &io, ImDrawList *draw_list,
@@ -933,7 +1168,7 @@ ImGui_Viewport_TransformUI(project_data *File, project_state *State, memory *Mem
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(*(interact_transform *)&State->Interact_Offset[0], &Layer->x.CurrentValue, &Layer->y.CurrentValue, &Layer->rotation.CurrentValue, &Layer->scale.CurrentValue);
+ Transform_ApplyInteractive(State->Interact_Transform, &Layer->x.CurrentValue, &Layer->y.CurrentValue, &Layer->rotation.CurrentValue, &Layer->scale.CurrentValue);
}
}
}
@@ -952,7 +1187,7 @@ 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, v2 *Min, v2 *Max,
+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,
sorted_comp_array *SortedCompArray, sorted_layer_array *SortedLayerArray)
{
sorted_comp_array *SortedCompStart = &SortedCompArray[CompIndex];
@@ -965,7 +1200,7 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImG
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, Min, Max, SortedCompArray, SortedLayerArray);
+ ImGui_Viewport_SelectedLayerUI(State, Memory, UI, io, draw_list, MainComp, Layer->Block_Source_Index, ParentLayer, Recursions + 1, PointCount, PointData, SortedCompArray, SortedLayerArray);
}
if (Layer->IsSelected) {
uint32 Width = 0, Height = 0;
@@ -999,7 +1234,7 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImG
if ((State->Interact_Active == interact_type_viewport_transform ||
State->Interact_Active == interact_type_viewport_transform_gizmo) && Layer->IsSelected == 1) {
- Transform_ApplyInteractive(*(interact_transform *)&State->Interact_Offset[0], &T.x, &T.y, &T.rotation, &T.scale);
+ Transform_ApplyInteractive(State->Interact_Transform, &T.x, &T.y, &T.rotation, &T.scale);
}
if (State->Interact_Active == interact_type_viewport_duplicate && SortEntry.IsFake) {
Assert(Layer->IsSelected);
@@ -1058,10 +1293,8 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImG
for (int i = 0; i < 4; i++) {
v2 Pos = NewPos[i+1];
- if (Pos.x < Min->x) { Min->x = Pos.x; }
- if (Pos.y < Min->y) { Min->y = Pos.y; }
- if (Pos.x > Max->x) { Max->x = Pos.x; }
- if (Pos.y > Max->y) { Max->y = Pos.y; }
+ PointData[*PointCount] = Pos;
+ *PointCount += 1;
}
ImVec2 ScreenPoint[5];
@@ -1157,13 +1390,15 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
{
block_layer *ParentLayer[4];
// NOTE(fox): This min and max val is affected by interactive transforms!
- v2 Min = V2(10000, 10000), Max = V2(-10000, -10000);
- ImGui_Viewport_SelectedLayerUI(State, Memory, UI, io, draw_list, MainComp, File->PrincipalCompIndex, ParentLayer, 0, &Min, &Max, SortedCompArray, SortedLayerArray);
+ 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);
if (State->Interact_Active == interact_type_viewport_transform) {
- ImGui_Viewport_TransformUI(File, State, Memory, UI, io, draw_list, (interact_transform *)&State->Interact_Offset[0], ViewportMin, MainComp->Width, MainComp->Height, SortedKeyframeArray);
+ ImGui_Viewport_TransformUI(File, State, Memory, UI, io, draw_list, &State->Interact_Transform, ViewportMin, MainComp->Width, MainComp->Height, SortedKeyframeArray);
} else {
- ImGui_Viewport_TransformUI2(File, State, Memory, UI, io, draw_list, Min, Max, ViewportMin, MainComp->Width, MainComp->Height, SortedKeyframeArray);
+ ImGui_Viewport_TransformUI2(File, State, Memory, UI, io, draw_list, &PointCount, PointData, ViewportMin, MainComp->Width, MainComp->Height, SortedKeyframeArray);
}
+ Memory_PopScratch(Memory, sizeof(v2) * 512);
}
shape_layer *Shape = &UI->Shape;
@@ -1236,6 +1471,7 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
if (State->Tool == tool_default && State->Interact_Active == interact_type_none)
State->Interact_Active = interact_type_viewport_selection;
if (State->Interact_Active == interact_type_viewport_selection) {
+
Layer_DeselectAll(File, State, Memory);
v2 MinPos_Comp = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, BoxMin) * V2(MainComp->Width, MainComp->Height);
v2 MaxPos_Comp = ImGui_ScreenPointToCompUV(ViewportMax, UI->CompPos, UI->CompZoom, BoxMax) * V2(MainComp->Width, MainComp->Height);
diff --git a/src/include/main.h b/src/include/main.h
index de33a25..38e9105 100644
--- a/src/include/main.h
+++ b/src/include/main.h
@@ -335,7 +335,10 @@ struct interact_transform
v2 Min;
v2 Max;
real32 Radians;
+ real32 RadianOffset;
v2 Position;
+ v2 OGCenter;
+ v2 NewCenter;
real32 Scale = 1.0f;
ImVec2 OGPos;
uint32 TransformMode;
@@ -484,6 +487,7 @@ struct project_state
// transfer will get buggy if you expand it to everything.
selection_type RecentSelectionType = selection_type_none;
+ interact_transform Interact_Transform;
interact_type Interact_Active;
int32 Interact_Modifier;
real32 Interact_Offset[12];
diff --git a/src/layer.cpp b/src/layer.cpp
index c158466..591487e 100644
--- a/src/layer.cpp
+++ b/src/layer.cpp
@@ -193,6 +193,7 @@ Layer_Select(memory *Memory, project_state *State, int32 i)
block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i);
Layer->IsSelected = true;
State->MostRecentlySelectedLayer = i;
+ State->Interact_Transform = {};
State->RecentSelectionType = selection_type_layer;
}
@@ -212,6 +213,7 @@ Layer_DeselectAll(project_data *File, project_state *State, memory *Memory) {
block_layer *Layer = (block_layer *)Memory_Block_AddressAtIndex(Memory, F_Layers, i);
Layer->IsSelected = false;
}
+ State->Interact_Transform = {};
State->MostRecentlySelectedLayer = -1;
}
diff --git a/src/main.cpp b/src/main.cpp
index 3f8388e..d1e992a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -21,6 +21,8 @@ uint32 BitmapFill = 0x00000001;
#include <curl/curl.h>
#endif
+static real32 aaa;
+
#if SPECIAL
#else
#include "memory.cpp"
@@ -420,10 +422,10 @@ Render_UI(project_data *File, project_state *State, memory *Memory, ui *UI, ImDr
layer_transforms T = Layer_GetTransforms(Layer);
if (State->Interact_Active == interact_type_viewport_transform && Layer->IsSelected == 1) {
- Transform_ApplyInteractive(*(interact_transform *)&State->Interact_Offset[0], &T.x, &T.y, &T.rotation, &T.scale);
+ 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(*(interact_transform *)&State->Interact_Offset[0], &T.x, &T.y, &T.rotation, &T.scale);
+ Transform_ApplyInteractive(State->Interact_Transform, &T.x, &T.y, &T.rotation, &T.scale);
}
if (State->Interact_Active == interact_type_viewport_slide && Layer->IsSelected == 1) {
// Transform_ApplySlide((v2 *)&State->Interact_Offset[0], &T);
@@ -1057,6 +1059,7 @@ int main(int argc, char *argv[]) {
{
History_Undo(&Memory);
Memory_Cache_Purge(File, State, &Memory);
+ State->Interact_Transform = {};
State->UpdateFrame = true;
State->UpdateKeyframes = true;
} break;
@@ -1064,6 +1067,7 @@ int main(int argc, char *argv[]) {
{
History_Redo(&Memory);
Memory_Cache_Purge(File, State, &Memory);
+ State->Interact_Transform = {};
State->UpdateFrame = true;
State->UpdateKeyframes = true;
} break;
diff --git a/src/prenderer.cpp b/src/prenderer.cpp
index 1cc490c..1d8f512 100644
--- a/src/prenderer.cpp
+++ b/src/prenderer.cpp
@@ -72,7 +72,7 @@ Transform_ApplyInteractive(interact_transform Interact, real32 *OutputX, real32
real32 Point0Y = Center.y - *OutputY;
real32 Rad = Interact.Radians;
- real32 Rotation = Interact.Radians / (PI / 180);
+ 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));
@@ -182,7 +182,7 @@ Interact_Transform_Begin(project_data *File, memory *Memory, project_state *Stat
&MinX, &MinY, &MaxX, &MaxY);
if (MinX != 100000) {
State->Interact_Active = interact_type_viewport_transform;
- interact_transform *Interact = (interact_transform *)&State->Interact_Offset[0];
+ interact_transform *Interact = &State->Interact_Transform;
Interact->Min = V2(MinX, MinY);
Interact->Max = V2(MaxX, MaxY);
Interact->Position = V2(0);
@@ -212,7 +212,7 @@ Interact_Transform_Begin(project_data *File, memory *Memory, project_state *Stat
}
if (Activate) {
State->Interact_Active = interact_type_viewport_transform;
- interact_transform *Interact = (interact_transform *)&State->Interact_Offset[0];
+ interact_transform *Interact = &State->Interact_Transform;
Interact->Min = V2(MinX, MinY);
Interact->Max = V2(MaxX, MaxY);
Interact->Position = V2(0);
@@ -238,7 +238,7 @@ Interact_Transform2_Begin(project_data *File, memory *Memory, project_state *Sta
&MinX, &MinY, &MaxX, &MaxY);
if (MinX != 100000) {
State->Interact_Active = interact_type_viewport_transform;
- interact_transform *Interact = (interact_transform *)&State->Interact_Offset[0];
+ interact_transform *Interact = &State->Interact_Transform;
Interact->Min = V2(MinX, MinY);
Interact->Max = V2(MaxX, MaxY);
Interact->Position = V2(0);
@@ -290,7 +290,7 @@ Layer_LocalToScreenSpace(project_state *State, memory *Memory, block_layer *Laye
if ((State->Interact_Active == interact_type_viewport_transform ||
State->Interact_Active == interact_type_viewport_transform_gizmo) && Layer->IsSelected == 1) {
- Transform_ApplyInteractive(*(interact_transform *)&State->Interact_Offset[0], &T.x, &T.y, &T.rotation, &T.scale);
+ Transform_ApplyInteractive(State->Interact_Transform, &T.x, &T.y, &T.rotation, &T.scale);
}
v2 NewPos = TransformPoint(T, Width, Height, Point);
@@ -392,7 +392,7 @@ Transform_Calculate(project_state *State, memory *Memory, project_data *File, bl
if ((State->Interact_Active == interact_type_viewport_transform ||
State->Interact_Active == interact_type_viewport_transform_gizmo) && Layer->IsSelected == 1) {
- Transform_ApplyInteractive(*(interact_transform *)&State->Interact_Offset[0], &X, &Y, &Rotation, &s);
+ Transform_ApplyInteractive(State->Interact_Transform, &X, &Y, &Rotation, &s);
}
/*