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.cpp92
1 files changed, 54 insertions, 38 deletions
diff --git a/src/imgui_ui_viewport.cpp b/src/imgui_ui_viewport.cpp
index eb48159..f3e124e 100644
--- a/src/imgui_ui_viewport.cpp
+++ b/src/imgui_ui_viewport.cpp
@@ -57,10 +57,10 @@ ImGui_Viewport_ShapeUI(project_state *State, memory *Memory, ui *UI, ImGuiIO &io
}
for (int i = 0; i < 3; i++) {
- ImVec2 Point = (i == 0) ? ImVec2_(Point_0->Pos[0]) : ImVec2_(Point_0->Pos[0] + Point_0->Pos[i]);
+ ImVec2 Point = (i == 0) ? IV2(Point_0->Pos[0]) : IV2(Point_0->Pos[0] + Point_0->Pos[i]);
if (Layer != NULL) {
layer_transforms T = Layer_GetTransforms(Layer);
- Point = ImVec2_(TransformPoint(T, Width, Height, *(v2 *)&Point));
+ Point = IV2(TransformPoint(T, Width, Height, *(v2 *)&Point));
}
if (State->Interact_Active == interact_type_keyframe_move && Point_0->IsSelected) {
Point.x += State->Interact_Offset[0];
@@ -70,10 +70,10 @@ ImGui_Viewport_ShapeUI(project_state *State, memory *Memory, ui *UI, ImGuiIO &io
ScreenPoint_0[i] = UI->CompPos + Point_Ratio * UI->CompZoom;
}
for (int i = 0; i < 3; i++) {
- ImVec2 Point = (i == 0) ? ImVec2_(Point_1->Pos[0]) : ImVec2_(Point_1->Pos[0] + Point_1->Pos[i]);
+ ImVec2 Point = (i == 0) ? IV2(Point_1->Pos[0]) : IV2(Point_1->Pos[0] + Point_1->Pos[i]);
if (Layer != NULL) {
layer_transforms T = Layer_GetTransforms(Layer);
- Point = ImVec2_(TransformPoint(T, Width, Height, *(v2 *)&Point));
+ Point = IV2(TransformPoint(T, Width, Height, *(v2 *)&Point));
}
if (State->Interact_Active == interact_type_keyframe_move && Point_1->IsSelected) {
Point.x += State->Interact_Offset[0];
@@ -516,8 +516,7 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImG
ParentLayer[Recursions] = Layer;
ImGui_Viewport_SelectedLayerUI(State, Memory, UI, io, draw_list, MainComp, Layer->Block_Source_Index, ParentLayer, Recursions + 1, SortedCompArray, SortedLayerArray);
}
- // if (Layer->IsSelected) {
- if (1) {
+ if (Layer->IsSelected) {
uint32 Width = 0, Height = 0;
void *Data;
uint32 NumberOfVerts;
@@ -556,7 +555,7 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImG
T.y += State->Interact_Offset[1];
}
- if (Layer->IsShapeLayer) {
+ 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);
// point visualization
@@ -691,7 +690,7 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
// UI+interaction for layer
- // if (State->MostRecentlySelectedLayer > -1)
+ if (State->MostRecentlySelectedLayer > -1)
{
block_layer *ParentLayer[4];
ImGui_Viewport_SelectedLayerUI(State, Memory, UI, io, draw_list, MainComp, File->PrincipalCompIndex, ParentLayer, 0, SortedCompArray, SortedLayerArray);
@@ -719,6 +718,8 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
bool32 IsDeactivated = ImGui::IsKeyReleased(ImGuiKey_3);
#endif
+ // TODO(fox): Tidy up once all work is done
+
if (IsHovered && IsActivated && !ImGui::IsMouseDown(ImGuiMouseButton_Right))
{
State->LastClickedPoint = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, io.MousePos);
@@ -746,43 +747,59 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
State->HotkeyInput = hotkey_newlayer_paint;
}
}
- // Layer selection
- if (State->Tool == tool_default && State->Interact_Active == interact_type_none) {
- if (io.KeyAlt) {
- } else {
- 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);
- }
- }
}
}
- if (IsActive && !ImGui::IsMouseDown(ImGuiMouseButton_Right) && !io.KeyCtrl && !io.KeyAlt)
+ bool32 OtherActions = ImGui::IsKeyDown(ImGuiKey_Z) || ImGui::IsMouseDown(ImGuiMouseButton_Right);
+
+ if (IsActive && !OtherActions && !io.KeyCtrl && !io.KeyAlt)
{
- v2 CompUV = State->LastClickedPoint;
- ImVec2 ScreenPointStart = ImVec2(UI->CompPos.x + CompUV.x * UI->CompZoom.x,
- UI->CompPos.y + CompUV.y * UI->CompZoom.y);
- uint32 fcol = IM_COL32(00, 00, 255, 50);
- uint32 wcol = IM_COL32(128, 128, 255, 255);
- ImVec2 Vector = io.MousePos - ScreenPointStart;
+ ImVec2 ClickedPos = io.MouseClickedPos[0];
ImVec2 MousePos = io.MousePos;
- if (State->Tool == tool_default && State->Interact_Active == interact_type_none) {
- draw_list->AddRectFilled(ScreenPointStart, MousePos, fcol, 2.0f);
- draw_list->AddRect(ScreenPointStart, MousePos, wcol, 2.0f);
- }
- if (io.MouseDelta.x || io.MouseDelta.y) {
- Layer_DeselectAll(File, State, Memory);
- v2 LocalMaxUV = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, MousePos);
- v2 LocalMinPos = State->LastClickedPoint * V2(MainComp->Width, MainComp->Height);
- v2 LocalMaxPos = LocalMaxUV * V2(MainComp->Width, MainComp->Height);
- Layer_TestBoxSelect(Memory, State, UI, SortedCompArray, SortedLayerArray, File->PrincipalCompIndex,
- LocalMinPos, LocalMaxPos);
+ ImVec2 BoxMin = {}, BoxMax = {};
+ BoxMin.x = (MousePos.x < ClickedPos.x) ? MousePos.x : ClickedPos.x;
+ 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) {
+ Assert(BoxMax.x > BoxMin.x &&
+ BoxMax.y > BoxMin.y)
+ BoxMax.y = (MousePos.y > ClickedPos.y) ? MousePos.y : ClickedPos.y;
+ if (io.MouseDelta.x || io.MouseDelta.y) {
+ 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);
+ Layer_TestBoxSelect(Memory, State, UI, SortedCompArray, SortedLayerArray, File->PrincipalCompIndex, MinPos_Comp, MaxPos_Comp);
+ }
+ }
+ if (State->Interact_Active == interact_type_viewport_selection) {
+ uint32 fcol = IM_COL32(00, 00, 255, 50);
+ uint32 wcol = IM_COL32(128, 128, 255, 255);
+ draw_list->AddRectFilled(BoxMin, BoxMax, fcol, 2.0f);
+ draw_list->AddRect(BoxMin, BoxMax, wcol, 2.0f);
+ }
}
}
+ if (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);
+ }
+ }
+
+ if (IsDeactivated && State->Interact_Active == interact_type_viewport_selection) {
+ State->Interact_Active = interact_type_none;
+ }
+
/*
if (State->Interact_Active == interact_type_viewport_transform) {
interact_transform *Interact = (interact_transform *)&State->Interact_Offset[0];
@@ -800,7 +817,6 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
}
- bool32 OtherActions = ImGui::IsKeyDown(ImGuiKey_Z) || ImGui::IsMouseDown(ImGuiMouseButton_Right);
if (State->Tool == tool_brush && State->Interact_Active == interact_type_brush) {
Assert(State->Brush.LayerToPaint_Index != -1);
if (IsActive && !OtherActions) {