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.cpp124
1 files changed, 92 insertions, 32 deletions
diff --git a/src/imgui_ui_viewport.cpp b/src/imgui_ui_viewport.cpp
index c846c7e..749999d 100644
--- a/src/imgui_ui_viewport.cpp
+++ b/src/imgui_ui_viewport.cpp
@@ -3,7 +3,6 @@
#include "main.h"
#endif
-
static void
ImGui_Viewport_Toolbar(project_state *State, ImDrawList *draw_list)
{
@@ -133,6 +132,8 @@ ImGui_Viewport_ShapeUI(project_state *State, memory *Memory, ui *UI, ImGuiIO &io
if (IsItemDeactivated) {
if (Layer == NULL && a == 0 && i == 0 && Shape->IsClosed == false) {
History_Entry_Commit(Memory, "Close shape");
+ Assert(0);
+ // which one??
History_Action_Swap(Memory, F_File, sizeof(Shape->IsClosed), &Shape->IsClosed);
Shape->IsClosed = true;
History_Entry_End(Memory);
@@ -261,7 +262,7 @@ T_FindBestFit(int PointCount, v2 *PointData, v2 *Center, v2 *NewCenter, v2 *Best
*BestMin = Min;
*BestMax = Max;
*BestRadians = 0;
- // real32 Angles[4] = { 15, 30, 45, 60 };
+ // TODO(fox): Make more efficient and more precise.
for (real32 i = 0; i < 90; i+= 1) {
v2 NewMin = {}, NewMax = {};
real32 NewArea = T_AreaAtAngle(PointCount, PointData, *Center, i, &NewMin, &NewMax);
@@ -294,7 +295,8 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
real32 Scale = 1;
if (Interact->Min.x == 0.0f) {
- T_FindBestFit(*PointCount, PointData, &Interact->OGCenter, &Interact->NewCenter, &Interact->Min, &Interact->Max, &Interact->RadianOffset);
+ if (*PointCount > 0)
+ T_FindBestFit(*PointCount, PointData, &Interact->OGCenter, &Interact->NewCenter, &Interact->Min, &Interact->Max, &Interact->RadianOffset);
// Interact->RadianOffset +=
Interact->Scale = 1.0f;
}
@@ -394,8 +396,8 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
real32 U = LayerPoint.x / BoxLength.x;
real32 V = LayerPoint.y / BoxLength.y;
- DebugWatchVar("U", &U, d_float);
- DebugWatchVar("V", &V, d_float);
+ // DebugWatchVar("U", &U, d_float);
+ // DebugWatchVar("V", &V, d_float);
ImVec2 ScaleHandleSize(50, 50);
@@ -407,9 +409,18 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
ImGui::PushID(i);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::ColorConvertFloat4ToU32(ImVec4(0.6f, 0.0f, 0.3f, 1.0f)));
- ImGui::Button("##ScaleMids", ScaleHandleSize);
+ ImGui::InvisibleButton("##ScaleMids", ScaleHandleSize);
ImGui::PopStyleColor();
+ ImGui_DrawCenteredRect(draw_list, Mid_P[i], 12, IM_COL32(20, 20, 20, 255));
+ ImGui_DrawCenteredRect(draw_list, Mid_P[i], 10, IM_COL32(20, 20, 220, 255));
+ ImGui_DrawCenteredRect(draw_list, Mid_P[i], 6, IM_COL32(255, 255, 225, 50));
+
+
+ if (ImGui::GetMouseCursor() != ImGuiMouseCursor_None && ImGui::IsItemHovered() && !OtherActions) {
+ ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS);
+ }
+
if (ImGui::IsItemActivated() && !OtherActions) {
State->Interact_Active = interact_type_viewport_transform_gizmo;
State->InteractTransformMode = 1;
@@ -420,36 +431,56 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
uint32 side = i;
v2 Dir = {};
if (i == 0) {
- Dir = V2(-1, 1);
+ Dir = V2(1, -1);
} else if (i == 1) {
- Dir = V2(1, 1);
+ Dir = V2(-1, -1);
} else if (i == 2) {
- Dir = V2(1, -1);
+ Dir = V2(-1, 0);
} else if (i == 3) {
- Dir = V2(-1, -1);
+ Dir = V2(1, 0);
} else {
Assert(0);
}
+ // InteractMin + V2(BoxLength.x * 0.5, 0), InteractMin + V2(0, BoxLength.y * 0.5),
+ // InteractMax - V2(BoxLength.x * 0.5, 0), InteractMax - V2(0, BoxLength.y * 0.5) };
+
+
ImVec2 LengthVec = (io.MousePos - io.MouseClickedPos[0]) / CompScale;
real32 NegRad = -Rad;
v2 UnrotatedLengthVec = {};
{
v2 XAxis = (LengthVec.x * 1.0f)*V2(cos(NegRad), sin(NegRad));
v2 YAxis = (LengthVec.y * -1.0f)*V2(sin(NegRad), -cos(NegRad));
- v2 UnrotatedLengthVec = XAxis + YAxis;
+ UnrotatedLengthVec = XAxis + YAxis;
}
real32 Length = UnrotatedLengthVec.x * Dir.x;
- DebugWatchVar("Len", &Length, d_float);
real32 BoxAxis = BoxLength.x;
Interact->Scale = 1.0f + Length / BoxAxis;
v2 MovePos = V2((Length / 2), -(Length / 2) * (BoxLength.y / BoxLength.x));
v2 XAxis = (MovePos.x * Dir.x)*V2(cos(Rad), sin(Rad));
v2 YAxis = (MovePos.y * Dir.y)*V2(sin(Rad), -cos(Rad));
v2 Pos = XAxis + YAxis;
- Interact->Position.x = Pos.x;
- Interact->Position.y = Pos.y;
+
+ Interact->Position.x = Pos.x;
+ Interact->Position.y = Pos.y;
+#if 0
+ if (i == 0) {
+ Interact->Position.x = Pos.x;
+ Interact->Position.y = Pos.y;
+ } else if (i == 1) {
+ Interact->Position.x = Pos.x;
+ Interact->Position.y = Pos.y;
+ } else if (i == 2) {
+ Interact->Position.x = Pos.x;
+ Interact->Position.y = Pos.y;
+ } else if (i == 3) {
+ Interact->Position.x = Pos.x;
+ Interact->Position.y = Pos.y;
+ }
+#endif
+
}
ImGui::PopID();
@@ -459,7 +490,7 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
// Scale if cursor is on button within the UV, rotate if outside UV, and position if a non-button is dragged.
if (U >= 0.0f && U <= 1.0f && V >= 0.0f && V <= 1.0f)
{
- ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::ColorConvertFloat4ToU32(ImVec4(0.6f, 0.0f, 0.3f, 1.0f)));
+ // ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::ColorConvertFloat4ToU32(ImVec4(0.6f, 0.0f, 0.3f, 1.0f)));
InBounds = true;
}
@@ -467,7 +498,19 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
for (int i = 0; i < 4; i++) {
ImGui::SetCursorScreenPos(P[i] - ScaleHandleSize/2);
ImGui::PushID(i);
- ImGui::Button("##ScaleRotateCorners", ScaleHandleSize);
+ ImGui::InvisibleButton("##ScaleRotateCorners", ScaleHandleSize);
+
+ ImGui_DrawCenteredRect(draw_list, P[i], 12, IM_COL32(80, 80, 80, 255));
+ ImGui_DrawCenteredRect(draw_list, P[i], 10, IM_COL32(20, 20, 220, 255));
+ ImGui_DrawCenteredRect(draw_list, P[i], 6, IM_COL32(255, 255, 225, 50));
+
+ if (ImGui::GetMouseCursor() != ImGuiMouseCursor_None && ImGui::IsItemHovered() && !OtherActions) {
+ if (InBounds) {
+ ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNESW);
+ } else {
+ ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeAll);
+ }
+ }
if (ImGui::IsItemActivated() && !OtherActions) {
if (InBounds)
@@ -545,6 +588,10 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
MouseRadians = 0.0f;
Interact->Radians = Direction * MouseRadians;
+ if (io.KeyShift) {
+ real32 Angle = (Interact->Radians / (PI / 180));
+ Interact->Radians = (int)(Angle / 15.0f) * 15.0f * (PI / 180);
+ }
}
ImGui::PopID();
}
@@ -553,8 +600,11 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
v2 MouseLocalUV = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, io.MousePos);
bool32 LayerHovered = Layer_TestForPoint(Memory, State, UI, SortedCompArray, SortedLayerArray, File->PrincipalCompIndex, MouseLocalUV);
if (LayerHovered) {
+ if (ImGui::GetMouseCursor() == ImGuiMouseCursor_None) {
+ ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
+ }
ImGui::SetCursorScreenPos(io.MousePos - ScaleHandleSize/2);
- ImGui::Button("##mover", ScaleHandleSize);
+ ImGui::InvisibleButton("##mover", ScaleHandleSize);
if (!State->InteractTransformMode && ImGui::IsItemActivated() && !OtherActions) {
State->Interact_Active = interact_type_viewport_transform_gizmo;
State->InteractTransformMode = 3;
@@ -598,7 +648,7 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
}
if (InBounds == true) {
- ImGui::PopStyleColor();
+ // ImGui::PopStyleColor();
}
}
@@ -1159,7 +1209,7 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
BoxMin.y = (MousePos.y < ClickedPos.y) ? MousePos.y : ClickedPos.y;
BoxMax.x = (MousePos.x > ClickedPos.x) ? MousePos.x : ClickedPos.x;
BoxMax.y = (MousePos.y > ClickedPos.y) ? MousePos.y : ClickedPos.y;
- if (BoxMax.x - BoxMin.x > 2.0f && BoxMax.y - BoxMin.y > 2.0f) {
+ if (BoxMax.x - BoxMin.x > 0.1f && BoxMax.y - BoxMin.y > 0.1f) {
Assert(BoxMax.x > BoxMin.x &&
BoxMax.y > BoxMin.y)
BoxMax.y = (MousePos.y > ClickedPos.y) ? MousePos.y : ClickedPos.y;
@@ -1167,15 +1217,16 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
if (State->Tool == tool_default && State->Interact_Active == interact_type_none) {
int32 Selection = Layer_TestSelection(Memory, State, UI, SortedCompArray, SortedLayerArray, File->PrincipalCompIndex);
if (!State->InteractTransformMode && Selection != -1) {
+ Layer_DeselectAll(File, State, Memory);
Layer_Select(Memory, State, Selection);
State->Interact_Active = interact_type_viewport_transform_gizmo;
+ State->Interact_OutOfDrag = true;
State->InteractTransformMode = 3;
} else {
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);
@@ -1191,18 +1242,27 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
}
}
- if (((io.KeyAlt && IsActivated && State->MostRecentlySelectedLayer == -1) ||
- (IsHovered && IsDeactivated && !io.KeyCtrl && !io.KeyAlt)) &&
- !ImGui::IsMouseDown(ImGuiMouseButton_Right) && !ImGui::IsKeyDown(ImGuiKey_Z))
- {
- // Layer selection
- if (State->Tool == tool_default && State->Interact_Active == interact_type_none) {
- int32 Selection = Layer_TestSelection(Memory, State, UI, SortedCompArray, SortedLayerArray, File->PrincipalCompIndex);
- if (!io.KeyShift && State->Interact_Active == interact_type_none)
- Layer_DeselectAll(File, State, Memory);
- if (Selection != -1)
- Layer_Select(Memory, State, Selection);
- }
+ bool32 Delta = (io.MouseDelta.x || io.MouseDelta.y);
+ if (IsActivated || IsDeactivated) {
+ if (((io.KeyAlt && IsActivated && State->MostRecentlySelectedLayer == -1) ||
+ (IsHovered && IsDeactivated && !Delta && !io.KeyCtrl && !io.KeyAlt)) &&
+ !ImGui::IsMouseDown(ImGuiMouseButton_Right) && !ImGui::IsKeyDown(ImGuiKey_Z))
+ {
+ if (State->Interact_OutOfDrag) {
+ State->Interact_OutOfDrag = 0;
+ } else {
+ // Layer selection
+ int32 Selection = Layer_TestSelection(Memory, State, UI, SortedCompArray, SortedLayerArray, File->PrincipalCompIndex);
+ if (State->Tool == tool_default && State->Interact_Active == interact_type_none) {
+ if (!io.KeyShift && State->Interact_Active == interact_type_none) {
+ Layer_DeselectAll(File, State, Memory);
+ State->Interact_Transform = {};
+ }
+ if (Selection != -1)
+ Layer_Select(Memory, State, Selection);
+ }
+ }
+ }
}
if (IsDeactivated && State->Interact_Active == interact_type_viewport_selection) {