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