From 7924ad2000062c1a418411ec0f823e4aa5ea98de Mon Sep 17 00:00:00 2001 From: Stepland <10530295-Buggyroom@users.noreply.gitlab.com> Date: Wed, 16 Nov 2022 02:00:09 +0100 Subject: [PATCH] WIP Lane Layout edition --- include/imgui/imgui_demo.cpp | 24 +++++++-------- src/main.cpp | 2 +- src/widgets/linear_view.cpp | 58 ++++++++++++++++++++++++++++++++---- src/widgets/linear_view.hpp | 3 +- 4 files changed, 68 insertions(+), 19 deletions(-) diff --git a/include/imgui/imgui_demo.cpp b/include/imgui/imgui_demo.cpp index 9cbc503..c826c19 100644 --- a/include/imgui/imgui_demo.cpp +++ b/include/imgui/imgui_demo.cpp @@ -2742,18 +2742,18 @@ static void ShowDemoWindowLayout() "IsItemHovered()/IsItemActive() or SameLine() etc. on the whole group."); ImGui::BeginGroup(); { - ImGui::BeginGroup(); - ImGui::Button("AAA"); - ImGui::SameLine(); - ImGui::Button("BBB"); - ImGui::SameLine(); - ImGui::BeginGroup(); - ImGui::Button("CCC"); - ImGui::Button("DDD"); - ImGui::EndGroup(); - ImGui::SameLine(); - ImGui::Button("EEE"); - ImGui::EndGroup(); + ImGui::BeginGroup(); { + ImGui::Button("AAA"); + ImGui::SameLine(); + ImGui::Button("BBB"); + ImGui::SameLine(); + ImGui::BeginGroup(); { + ImGui::Button("CCC"); + ImGui::Button("DDD"); + } ImGui::EndGroup(); + ImGui::SameLine(); + ImGui::Button("EEE"); + } ImGui::EndGroup(); if (ImGui::IsItemHovered()) ImGui::SetTooltip("First group hovered"); } diff --git a/src/main.cpp b/src/main.cpp index 46e4cd3..e4214db 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -531,7 +531,7 @@ int main() { } ImGui::EndMenu(); } - if (ImGui::BeginMenu("Edit")) { + if (ImGui::BeginMenu("Edit", editor_state.has_value())) { if (ImGui::MenuItem("Undo", "Ctrl+Z")) { if (editor_state) { editor_state->undo(notificationsQueue); diff --git a/src/widgets/linear_view.cpp b/src/widgets/linear_view.cpp index 3b1ff8a..6306015 100644 --- a/src/widgets/linear_view.cpp +++ b/src/widgets/linear_view.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -28,7 +29,8 @@ void SelectionRectangle::reset() { } LinearView::LinearView(std::filesystem::path assets) : - beats_to_pixels_proportional(0, 1, 0, 100) + beats_to_pixels_proportional(0, 1, 0, 100), + lane_order({0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}) {} void LinearView::draw( @@ -363,9 +365,19 @@ void LinearView::set_zoom(int newZoom) { reload_transforms(); } +const std::array letters = { + "1","2","3","4", + "5","6","7","8", + "9","a","b","c", + "d","e","f","g" +}; + void LinearView::display_settings() { if (ImGui::Begin("Linear View Settings", &shouldDisplaySettings)) { - if (ImGui::TreeNode("Colors##Linear View Settings")) { + if (ImGui::CollapsingHeader("Lane Layout##Linear View Settings")) { + LaneOrderPreview(lane_order); + } + if (ImGui::CollapsingHeader("Colors##Linear View Settings")) { feis::ColorEdit4("Cursor", cursor_color); feis::ColorEdit4("Measure Lines", measure_lines_color); feis::ColorEdit4("Measure Numbers", measure_numbers_color); @@ -399,12 +411,10 @@ void LinearView::display_settings() { feis::ColorEdit4("Selected Outline##Color settings", selected_note_outline); ImGui::TreePop(); } - ImGui::TreePop(); } - if (ImGui::TreeNode("Metrics##Linear View Settings")) { + if (ImGui::CollapsingHeader("Metrics##Linear View Settings")) { ImGui::DragInt("Cursor Height", &cursor_height); ImGui::DragInt("Timeline Margin", &timeline_margin); - ImGui::TreePop(); } } ImGui::End(); @@ -509,3 +519,41 @@ bool draw_selection_rect( } return ImGui::IsMouseReleased(mouse_button); } + +void LaneOrderPreview(const std::array, 16>& order) { + static float scale = 16.f; + static sf::Vector2f offset = {0, 0}; + static float decalage_output = 5.f; + if (ImGui::Begin("Debug Linear View Settings")) { + ImGui::SliderFloat("Scale", &scale, 0, 20, "%.3f", ImGuiSliderFlags_Logarithmic); + ImGui::SliderFloat2("Offset", &offset.x, 0, 1000); + ImGui::SliderFloat("Décalage output", &decalage_output, 0, 10); + } + ImGui::End(); + const auto origin = sf::Vector2f{ImGui::GetCursorPos()}; + auto col = ImColor(sf::Color::White); + for (auto y = 0; y < 4; y++) { + for (auto x = 0; x < 4; x++) { + const auto index = x + 4*y; + ImGui::SetCursorPos(origin + offset + sf::Vector2f{static_cast(x), static_cast(y)} * scale); + ImGui::ColorConvertHSVtoRGB(static_cast(index)/16.f, 1, 1, col.Value.x, col.Value.y, col.Value.z); + ImGui::TextColored(col, "%s", letters[index].c_str()); + if (x != 3) { + ImGui::SameLine(); + } + } + } + const auto screen_origin = sf::Vector2f{ImGui::GetCursorScreenPos()}; + ImGui::RenderArrow(ImGui::GetWindowDrawList(), screen_origin + offset + sf::Vector2f{decalage_output, 1.5f} * scale, ImColor(sf::Color::White), ImGuiDir_Right); + for (std::size_t i = 0; i < order.size(); i++) { + const auto button = order.at(i); + if (button) { + const auto index = *button % 16; + ImGui::SetCursorPos(origin + offset + sf::Vector2f{static_cast(decalage_output+2+index), 1.5f} * scale); + ImGui::ColorConvertHSVtoRGB(static_cast(index)/16.f, 1, 1, col.Value.x, col.Value.y, col.Value.z); + ImGui::TextColored(col, "%s", letters[index].c_str()); + } + } + ImGui::SetCursorPos(origin); + ImGui::Dummy(sf::Vector2f{23, 4}*scale); +} \ No newline at end of file diff --git a/src/widgets/linear_view.hpp b/src/widgets/linear_view.hpp index 80dc3af..64b7026 100644 --- a/src/widgets/linear_view.hpp +++ b/src/widgets/linear_view.hpp @@ -95,6 +95,7 @@ private: SelectionRectangle selection_rectangle; bool started_selection_inside_window = false; bool any_bpm_button_hovered = false; + std::array, 16> lane_order; }; void draw_rectangle( @@ -121,4 +122,4 @@ bool draw_selection_rect( ImGuiMouseButton mouse_button = ImGuiMouseButton_Left ); -void select_everything_inside(const sf::Vector2f& rect); +void LaneOrderPreview(const std::array, 16>& order); \ No newline at end of file