From 78349e2854a297aeeedeb49325610535a53237f7 Mon Sep 17 00:00:00 2001 From: lachrymaLF Date: Sun, 30 Jun 2024 06:00:42 -0400 Subject: [PATCH] this is so broken --- Keishiki/UI.cpp | 90 ++++++++++++++++++++++++++++++++----------------- TODO.md | 1 + 2 files changed, 61 insertions(+), 30 deletions(-) diff --git a/Keishiki/UI.cpp b/Keishiki/UI.cpp index c142394..d59637e 100644 --- a/Keishiki/UI.cpp +++ b/Keishiki/UI.cpp @@ -47,6 +47,7 @@ namespace { K_DR_Selected_Layers, K_DR_Selected_Keys, K_DR_Selected_Nodes, + K_DR_Make_Subcomposition, K_DR_Count }; bool delete_requests[K_DR_Count]{}; @@ -326,6 +327,7 @@ namespace K::UI { void Viewport(CompositionState& s) { ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{}); if (ImGui::Begin("Viewport", nullptr, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) { + ImGuiIO& io = ImGui::GetIO(); static bool do_bg = true, dragging = false; static f32 size = 1.0f, angle = 0; static ImVec2 pos{}, old = pos; @@ -385,7 +387,6 @@ namespace K::UI { } ImGui::EndDisabled();*/ - ImGuiIO io = ImGui::GetIO(); if (ImGui::IsWindowHovered()) { if (io.MouseWheel != 0.0f) { size += io.MouseWheel * 0.25f; @@ -414,8 +415,6 @@ namespace K::UI { if (ImGui::BeginChild("Controls")) { ImGui::Text("%ux%u@%.1f", s.width, s.height, s.fps); ImGui::SameLine(); - ImGui::Checkbox("Transparency Grid", &do_bg); - ImGui::SameLine(); f32 percentage = size * 100.0f; ImGui::SetNextItemWidth(110.0f); if (ImGui::InputFloat("View Scale", &percentage, 15.0f, 25.0f, "%.2f%%")) { @@ -423,7 +422,9 @@ namespace K::UI { } ImGui::SameLine(); ImGui::SetNextItemWidth(50.0f); - ImGui::DragFloat("Rotation", &angle); + ImGui::DragFloat("View Angle", &angle, .05f, 0.0f, 0.0f, "%.1f"); + ImGui::SameLine(); + ImGui::Checkbox("Transparency Grid", &do_bg); } ImGui::EndChild(); ImGui::PopStyleColor(); @@ -457,6 +458,7 @@ namespace K::UI { ImGui::End(); return; } + ImGuiIO& io = ImGui::GetIO(); static bool show_curve_editor = false; if (ImGui::Shortcut(ImGuiKey_Space)) @@ -505,7 +507,6 @@ namespace K::UI { ImGui::Checkbox("Chain Editor", &show_curve_editor); - ImGuiIO& io = ImGui::GetIO(); ImRect drag_rect{io.MousePos, io.MousePos}; drag_rect.Add(io.MouseClickedPos[ImGuiMouseButton_Left]); ImGuiStyle style = ImGui::GetStyle(); @@ -823,23 +824,7 @@ namespace K::UI { ImGui::CloseCurrentPopup(); } if (ImGui::Button("Make Subcomposition")) { - CompositionState new_comp{.width = s.width, .height = s.height}; - u32 index_in_new_comp = 0; - u64 frame_min = -1, frame_max = 0; - for (auto j : s.selected) { - new_comp.layers.emplace_back(std::move(s.layers[j])); - if (std::ranges::find(s.disabled, j) != s.disabled.end()) - new_comp.disabled.push_back(index_in_new_comp); - frame_min = std::min(frame_min, s.layers[j].in); - frame_max = std::max(frame_max, s.layers[j].out); - index_in_new_comp++; - } - new_comp.frame_max = frame_max - frame_min; - for (auto& layer : new_comp.layers) - layer.in -= frame_min; - delete_requests[K_DR_Selected_Layers] = true; - app_state.project.compositions.insert(std::move(new_comp)); - /* todo make comp */ + delete_requests[K_DR_Make_Subcomposition] = true; ImGui::CloseCurrentPopup(); } } @@ -1021,7 +1006,7 @@ namespace K::UI { auto& connected_v = std::visit([&u](auto&& arg) -> auto& { return arg->in[u.connection.index].value; }, u.connection.p); - std::visit([&u, &dragging_on_socket, &drag_source, &s, &style, &io](auto &&arg) { + std::visit([&io, &u, &dragging_on_socket, &drag_source, &s, &style](auto &&arg) { using T = std::decay_t; if constexpr (std::is_same_v) { if (ImGui::IsItemActive()) @@ -1714,7 +1699,6 @@ namespace K::UI { } ImGui::TextUnformatted("----Compositions----"); for (auto& comp : app_state.project.compositions) { - // todo skip comps that induce a cycle ImGui::PushID(id++); const bool is_selected = r_name == comp.name.c_str(); // lol if (ImGui::Selectable(comp.name.c_str(), is_selected)) { @@ -1783,7 +1767,6 @@ namespace K::UI { void Interpolation(CompositionState& s) { if (ImGui::Begin("Interpolation", nullptr, ImGuiWindowFlags_NoScrollbar)) { ImGuiIO& io = ImGui::GetIO(); - static Plugboard::K_Interpolation type_current = Plugboard::K_I_CubicBezier; static const ImVec2 p1 { 0.0f, 0.0f}, p4 {1.0f, 1.0f}; @@ -2083,7 +2066,8 @@ namespace K::UI { if (static_cast(j) < s.active) before_active++; deleted++; - } else if (auto it = std::ranges::find(s.disabled, j); it != s.disabled.end()) + } + else if (auto it = std::ranges::find(s.disabled, j); it != s.disabled.end()) *it -= deleted; } s.selected.clear(); @@ -2093,6 +2077,55 @@ namespace K::UI { delete_requests[K_DR_Selected_Layers] = false; } + if (delete_requests[K_DR_Make_Subcomposition]) { + auto itt = app_state.project.compositions.emplace(); + CompositionState& new_comp = *itt; + new_comp.name = "subcomp"; + new_comp.fps = s.fps; + new_comp.width = s.width; + new_comp.height = s.height; + new_comp.Setup(); + u32 index_in_new_comp = 0; + u64 frame_min = -1, frame_max = 0; + for (auto& j : s.selected) { + for (auto& u : s.layers[j].track.uniforms) + if (u.status & K_U_Exposed) { + VisualTrack::HideUniform(s, u); // fixme + VisualTrack::ExposeUniform(new_comp, u); + } + new_comp.layers.push_back(std::move(s.layers[j])); + if (std::ranges::find(s.disabled, j) != s.disabled.end()) + new_comp.disabled.push_back(index_in_new_comp); + frame_min = std::min(frame_min, s.layers[j].in); + frame_max = std::max(frame_max, s.layers[j].out); + index_in_new_comp++; + } + new_comp.frame_max = frame_max - frame_min; + for (auto& layer : new_comp.layers) + layer.in -= frame_min; + + if (std::ranges::find(s.selected, s.active) != s.selected.end()) // unset active if active is selected + s.active = -1; + u32 deleted = 0, before_active = 0; // stupid counting tricks + const u32 sz = s.layers.size(); + for (u32 j = 0; j < sz; j++) { // im sure this isn't the best way to go about this + if (std::ranges::find(s.selected, j) != s.selected.end()) { + s.layers.erase(s.layers.begin() + j - deleted); + std::erase(s.disabled, j); + if (static_cast(j) < s.active) + before_active++; + deleted++; + } + else if (auto it = std::ranges::find(s.disabled, j); it != s.disabled.end()) + *it -= deleted; + } + s.selected.clear(); + if (s.active != -1) + s.active -= static_cast(before_active); + + delete_requests[K_DR_Make_Subcomposition] = false; + } + if (delete_requests[K_DR_Selected_Nodes]) { for (auto p: s.plugboard.selected_nodes) { std::visit([&s](auto &&arg) { @@ -2111,7 +2144,6 @@ namespace K::UI { delete_requests[K_DR_Selected_Nodes] = false; } - if (delete_requests[K_DR_Selected_Keys]) { for (auto& chain : s.plugboard.selected_nodes) { if (auto *c = std::get_if(&chain)) { @@ -2135,9 +2167,7 @@ namespace K::UI { ImGui::DockSpaceOverViewport(0, ImGui::GetMainViewport(), ImGuiDockNodeFlags_PassthruCentralNode); - - -// ImGui::ShowDemoWindow(); + ImGui::ShowDemoWindow(); MainMenuBar(); if (draw_assets) Assets(); diff --git a/TODO.md b/TODO.md index 8c584c1..c428646 100644 --- a/TODO.md +++ b/TODO.md @@ -20,6 +20,7 @@ - skia is too heavy probably - investigate cpu-gpu shared buffers with blend2d - or maybe fork nanovg? + - more realistic: fork/maintain https://github.com/jdryg/vg-renderer - Frontend: - AE-like interface - canvas-like interface