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.cpp173
1 files changed, 129 insertions, 44 deletions
diff --git a/src/imgui_ui_viewport.cpp b/src/imgui_ui_viewport.cpp
index e21c1a6..9563d63 100644
--- a/src/imgui_ui_viewport.cpp
+++ b/src/imgui_ui_viewport.cpp
@@ -32,6 +32,66 @@ ImGui_Viewport_Toolbar(project_state *State, ImDrawList *draw_list)
}
static void
+ImGui_Viewport_ShapeUI(project_state *State, memory *Memory, ui *UI, shape_layer *Shape, block_composition *MainComp, ImDrawList *draw_list)
+{
+ if (Shape->Point_Count) {
+ uint32 wcol = IM_COL32(00, 00, 80, 255);
+ v2 CompUV = State->LastClickedPoint;
+ ImVec2 ScreenPoint = ImVec2(UI->CompPos.x + CompUV.x * UI->CompZoom.x,
+ UI->CompPos.y + CompUV.y * UI->CompZoom.y);
+ bezier_point *Point_0 = Bezier_LookupAddress(Memory, Shape->Block_Bezier_Index, Shape->Point_Count - 1, 1);
+ bezier_point *Point_1 = Bezier_LookupAddress(Memory, Shape->Block_Bezier_Index, 0, 1);
+ Assert(Shape->Contiguous);
+ int i = 0;
+ while (i < Shape->Point_Count) {
+ ImVec2 CompDimensions = ImVec2(MainComp->Width, MainComp->Height);
+ ImVec2 ScreenPoint_0[3];
+ ImVec2 ScreenPoint_1[3];
+
+ 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_Ratio = Point / CompDimensions;
+ 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_Ratio = Point / CompDimensions;
+ ScreenPoint_1[i] = UI->CompPos + Point_Ratio * UI->CompZoom;
+ }
+
+ if (Point_1->Type == interpolation_type_bezier)
+ draw_list->AddLine(ScreenPoint_0[1], ScreenPoint_0[2], wcol, 2.0f);
+ draw_list->AddNgon(ScreenPoint_0[0], 2, wcol, 8, 2.0f);
+
+ ImGui::PushID(i);
+ for (int a = 0; a < 3; a++) {
+ ImGui::PushID(a);
+ ImGui::SetCursorScreenPos(ScreenPoint_1[a]);
+ if (ImGui::Button("##bezhandle")) {
+ if (a == 0 && i == 0) {
+ History_Entry_Commit(Memory, "Close shape");
+ History_Action_Swap(Memory, F_File, sizeof(Shape->IsClosed), &Shape->IsClosed);
+ Shape->IsClosed = true;
+ History_Entry_End(Memory);
+ }
+ }
+ ImGui::PopID();
+ }
+ ImGui::PopID();
+ // draw_list->AddBezierCubic(ScreenPoint_0, ScreenPoint_R_0, ScreenPoint_L_1, ScreenPoint_1, IM_COL32(10, 10, 10, 255), 1.0f, 0);
+ // draw_list->AddLine(ScreenPoint_0, ScreenPoint_1, wcol, 2.0f);
+
+ i++;
+ if (i < Shape->Point_Count) {
+ Point_0 = Bezier_LookupAddress(Memory, Shape->Block_Bezier_Index, i-1, 1);
+ Point_1 = Bezier_LookupAddress(Memory, Shape->Block_Bezier_Index, i, 1);
+ }
+ }
+ }
+}
+
+
+static void
ImGui_Viewport_BrushUI(project_state *State, memory *Memory, ImVec2 ViewportMin, ImVec2 ViewportMax, ImVec2 CompZoom, ImGuiIO io, uint16 Width, uint16 Height)
{
@@ -386,7 +446,8 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImD
block_bezier *Bezier = (block_bezier *)Memory_Block_AddressAtIndex(Memory, F_Bezier, Layer->Shape.Block_Bezier_Index[0]);
Data = Memory_PushScratch(Memory, sizeof(nvg_point) * 128);
int L_Width = 0, L_Height = 0;
- NumberOfVerts = NVG_FlattenPath(Memory, Bezier, 3, (nvg_point *)Data, &L_Width, &L_Height);
+ Assert(Layer->Shape.Contiguous);
+ NumberOfVerts = NVG_FlattenPath(Memory, &Layer->Shape, (nvg_point *)Data, &L_Width, &L_Height);
Width = L_Width;
Height = L_Height;
} else {
@@ -395,8 +456,6 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImD
Height = Source->Height;
}
- v2 Point[5] = { V2(Width*Layer->ax.CurrentValue, Height*Layer->ay.CurrentValue), V2(0, 0), V2(Width, 0), V2(0, Height), V2(Width, Height) };
-
layer_transforms T = Layer_GetTransforms(Layer);
if (State->Interact_Active == interact_type_viewport_transform && Layer->IsSelected == 1) {
@@ -404,34 +463,39 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImD
}
if (Layer->IsShapeLayer) {
+ /*
block_bezier *Bezier = (block_bezier *)Memory_Block_AddressAtIndex(Memory, F_Bezier, Layer->Shape.Block_Bezier_Index[0]);
- // for (int i = 0; i < Layer->Shape.Point_Count; i++) {
- // v2 ThisPoint = Bezier->Point[i].Pos[0];
- // v2 Pos = TransformPoint(T, Width, Height, ThisPoint);
- // v2 CompUV = Pos / V2(MainComp->Width, MainComp->Height);
- // ImVec2 ScreenPoint = ImVec2(UI->CompPos.x + CompUV.x * UI->CompZoom.x,
- // UI->CompPos.y + CompUV.y * UI->CompZoom.y);
- // draw_list->AddNgon(ScreenPoint, 10, IM_COL32(10, 10, 10, 255), 8, 9.0f);
- // }
-
- // imgui code
-
- void *Data2 = Memory_PushScratch(Memory, sizeof(real32) * 3 * 256);
- uint32 GL_PointCount = NVG_ExpandStroke(Memory, Bezier, NumberOfVerts, (nvg_point *)Data, (real32 *)Data2);
-
- v2 L_Pos[4] = { Bezier->Point[0].Pos[0], Bezier->Point[0].Pos[2], Bezier->Point[1].Pos[1], Bezier->Point[1].Pos[0] };
- L_Pos[1] = L_Pos[1] + L_Pos[0];
- L_Pos[2] = L_Pos[2] + L_Pos[3];
- ImVec2 ScreenPoint[4];
- for (int i = 0; i < 4; i++) {
- v2 Pos = TransformPoint(T, Width, Height, L_Pos[i]);
+ for (int i = 0; i < Layer->Shape.Point_Count; i++) {
+ bezier_point Point = Bezier->Point[i];
+ v2 Pos = TransformPoint(T, Width, Height, Point.Pos[0]);
v2 CompUV = Pos / V2(MainComp->Width, MainComp->Height);
- ScreenPoint[i] = ImVec2(UI->CompPos.x + CompUV.x * UI->CompZoom.x,
- UI->CompPos.y + CompUV.y * UI->CompZoom.y);
+ ImVec2 ScreenPoint = ImVec2(UI->CompPos.x + CompUV.x * UI->CompZoom.x,
+ UI->CompPos.y + CompUV.y * UI->CompZoom.y);
+ draw_list->AddNgon(ScreenPoint, 10, IM_COL32(10, 10, 10, 255), 8, 9.0f);
}
- draw_list->AddNgon(ScreenPoint[0], 10, IM_COL32(10, 10, 10, 255), 8, 2.0f);
- draw_list->AddNgon(ScreenPoint[3], 10, IM_COL32(10, 10, 10, 255), 8, 2.0f);
- draw_list->AddBezierCubic(ScreenPoint[0],ScreenPoint[1],ScreenPoint[2],ScreenPoint[3], IM_COL32(10, 10, 10, 255), 1.0f, 0);
+ for (int i = 1; i < Layer->Shape.Point_Count; i++) {
+ if (Bezier->Point[i].Type == interpolation_type_bezier) {
+ v2 L_Pos[4] = { Bezier->Point[i-1].Pos[0], Bezier->Point[i-1].Pos[2], Bezier->Point[i].Pos[1], Bezier->Point[i].Pos[0] };
+ L_Pos[1] = L_Pos[1] + L_Pos[0];
+ L_Pos[2] = L_Pos[2] + L_Pos[3];
+ ImVec2 ScreenPoint[4];
+ for (int i = 0; i < 4; i++) {
+ v2 Pos = TransformPoint(T, Width, Height, L_Pos[i]);
+ v2 CompUV = Pos / V2(MainComp->Width, MainComp->Height);
+ ScreenPoint[i] = ImVec2(UI->CompPos.x + CompUV.x * UI->CompZoom.x,
+ UI->CompPos.y + CompUV.y * UI->CompZoom.y);
+ }
+ draw_list->AddNgon(ScreenPoint[0], 10, IM_COL32(10, 10, 10, 255), 8, 2.0f);
+ draw_list->AddNgon(ScreenPoint[3], 10, IM_COL32(10, 10, 10, 255), 8, 2.0f);
+ draw_list->AddBezierCubic(ScreenPoint[0],ScreenPoint[1],ScreenPoint[2],ScreenPoint[3], IM_COL32(10, 10, 10, 255), 1.0f, 0);
+ } else {
+ }
+ }
+ */
+ ImGui_Viewport_ShapeUI(State, Memory, UI, &Layer->Shape, MainComp, draw_list);
+
+ void *Data2 = Memory_PushScratch(Memory, sizeof(real32) * 3 * 256);
+ uint32 GL_PointCount = NVG_ExpandStroke(Memory, NumberOfVerts, Layer->Shape.Opt.StrokeWidth, Layer->Shape.IsClosed, (nvg_point *)Data, (real32 *)Data2);
// test code
@@ -456,9 +520,10 @@ ImGui_Viewport_SelectedLayerUI(project_state *State, memory *Memory, ui *UI, ImD
Memory_PopScratch(Memory, sizeof(nvg_point) * 128);
}
+ v2 BoundingPoint[5] = { V2(Width*Layer->ax.CurrentValue, Height*Layer->ay.CurrentValue), V2(0, 0), V2(Width, 0), V2(0, Height), V2(Width, Height) };
v2 NewPos[5];
for (int i = 0; i < 5; i++) {
- NewPos[i] = TransformPoint(T, Width, Height, Point[i]);
+ NewPos[i] = TransformPoint(T, Width, Height, BoundingPoint[i]);
}
int i = 0;
@@ -554,7 +619,9 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
}
}
-
+ shape_layer *Shape = &UI->Shape;
+ if (State->Tool == tool_pen && State->Interact_Active == interact_type_none && State->MostRecentlySelectedLayer == -1)
+ ImGui_Viewport_ShapeUI(State, Memory, UI, Shape, MainComp, draw_list);
// Interactions for dragging and zooming
ImGui::SetCursorScreenPos(ViewportMin);
@@ -573,7 +640,7 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
if (IsHovered && IsActivated && !ImGui::IsMouseDown(ImGuiMouseButton_Right))
{
- State->TempZoomRatio = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, io.MousePos);
+ State->LastClickedPoint = ImGui_ScreenPointToCompUV(ViewportMin, UI->CompPos, UI->CompZoom, io.MousePos);
if (!ImGui::IsKeyDown(ImGuiKey_Z)) {
if (State->Tool == tool_brush && State->Interact_Active != interact_type_brush) {
@@ -654,21 +721,39 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
RenderQueue_AddBlit(State);
}
}
+
if (State->Tool == tool_pen && State->Interact_Active == interact_type_none && State->MostRecentlySelectedLayer == -1) {
- v2 CompUV = State->TempZoomRatio;
+ v2 CompUV = State->LastClickedPoint;
ImVec2 ScreenPoint = ImVec2(UI->CompPos.x + CompUV.x * UI->CompZoom.x,
UI->CompPos.y + CompUV.y * UI->CompZoom.y);
- ImVec2 Vector = io.MousePos - ScreenPoint;
- if (IsActive && !OtherActions) {
- uint32 wcol = IM_COL32(00, 00, 80, 255);
- draw_list->AddLine(ScreenPoint - Vector, io.MousePos, wcol, 2.0f);
- draw_list->AddNgon(ScreenPoint, 2, wcol, 8, 2.0f);
+ shape_layer *Shape = &UI->Shape;
+ ImGui::OpenPopupOnItemClick("shapecreate", ImGuiPopupFlags_MouseButtonRight);
+ if (ImGui::BeginPopup("shapecreate")) {
+ if (ImGui::Selectable("Create shape layer")) {
+ State->HotkeyInput = hotkey_newlayer_shape;
+ }
+ ImGui::EndPopup();
}
- if (IsDeactivated) {
- State->HotkeyInput = hotkey_newlayer_shape;
- if (fabs(Vector.x) > 5 && fabs(Vector.y) > 5) {
- State->HotkeyExtra[0] = Vector.x;
- State->HotkeyExtra[1] = Vector.y;
+ if (!Shape->IsClosed) {
+ if (IsHovered && IsActivated && !ImGui::IsMouseDown(ImGuiMouseButton_Right))
+ {
+ }
+ ImVec2 Vector = io.MousePos - ScreenPoint;
+ uint32 wcol = IM_COL32(00, 00, 80, 255);
+ if (IsActive && !OtherActions) {
+ draw_list->AddLine(ScreenPoint - Vector, io.MousePos, wcol, 2.0f);
+ draw_list->AddNgon(ScreenPoint, 2, wcol, 8, 2.0f);
+ }
+ if (IsDeactivated && !OtherActions && !ImGui::IsMouseReleased(ImGuiMouseButton_Right)) {
+ interpolation_type Type = interpolation_type_bezier;
+ if (fabs(Vector.x) < 5 && fabs(Vector.y) < 5) {
+ Type = interpolation_type_linear;
+ Vector = ImVec2(0, 0);
+ }
+ bezier_point PointData = { 1, { CompUV * V2(MainComp->Width, MainComp->Height), V2(Vector.x, Vector.y), V2(-Vector.x, -Vector.y) }, Type, 0 };
+ History_Entry_Commit(Memory, "Bezier point");
+ Bezier_Add(Memory, F_File, Shape->Block_Bezier_Index, &Shape->Block_Bezier_Count, &Shape->Point_Count, PointData);
+ History_Entry_End(Memory);
}
}
}
@@ -693,8 +778,8 @@ ImGui_Viewport(project_data *File, project_state *State, ui *UI, memory *Memory,
Distance *= -1;
UI->CompZoom.x += (Distance)*(real32)MainComp->Width/MainComp->Height;
UI->CompZoom.y += (Distance);
- UI->CompPos.x -= ((Distance)*(real32)MainComp->Width/MainComp->Height)*State->TempZoomRatio.x;
- UI->CompPos.y -= Distance*State->TempZoomRatio.y;
+ UI->CompPos.x -= ((Distance)*(real32)MainComp->Width/MainComp->Height)*State->LastClickedPoint.x;
+ UI->CompPos.y -= Distance*State->LastClickedPoint.y;
}
ImGui::SetCursorScreenPos(ImVec2(ViewportMin.x, ViewportMin.y + ViewportScale.y - FontSize*1.5));