From 89c7e9c7496d8525f0990c99822e96c7e9385dad Mon Sep 17 00:00:00 2001 From: Jules Fouchy Date: Sat, 9 Nov 2024 19:27:47 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Move=20Aspect=20Ratio=20control=20t?= =?UTF-8?q?o=20a=20floating=20button=20+=20Use=20a=20shared=20aspect=20rat?= =?UTF-8?q?io=20for=20View=20Constraint=20and=20Export=20Size?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cool | 2 +- src/App.cpp | 48 ++++++++++++++++++--------- src/App.h | 3 +- src/Gallery/GalleryPoster.cpp | 13 +++----- src/Gallery/GalleryPoster.h | 19 ++++++----- src/Project.h | 5 ++- src/ProjectManager/internal_utils.cpp | 2 ++ 7 files changed, 57 insertions(+), 35 deletions(-) diff --git a/Cool b/Cool index 2e936c2e..9436f1b6 160000 --- a/Cool +++ b/Cool @@ -1 +1 @@ -Subproject commit 2e936c2e8e4a357a8387b2969f2b6e1e554457ff +Subproject commit 9436f1b65abf42af4bd406cffda2b09a2d52955e diff --git a/src/App.cpp b/src/App.cpp index e3c1f4d8..eb963852 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -68,9 +68,6 @@ App::App(Cool::WindowManager& windows, Cool::ViewsManager& views) { command_executor().execute(Command_NewProject{}); _project.clock.pause(); // Make sure the new project will be paused. - - _project.camera_3D_manager.hook_events(_preview_view.mouse_events(), command_executor()); - _project.camera_2D_manager.hook_events(_preview_view.mouse_events(), command_executor()); } void App::on_shutdown() @@ -80,6 +77,16 @@ void App::on_shutdown() _is_shutting_down = true; } +void App::on_project_loaded() +{ + _project.camera_3D_manager.hook_events(_preview_view.mouse_events(), command_executor()); + _project.camera_2D_manager.hook_events(_preview_view.mouse_events(), command_executor()); + + _project.view_constraint.set_shared_aspect_ratio(_project.shared_aspect_ratio); + _project.exporter.set_shared_aspect_ratio(_project.shared_aspect_ratio); + _gallery_poster.set_shared_aspect_ratio(_project.shared_aspect_ratio); +} + void App::compile_all_is0_nodes() { // for (auto const& node_template : _project.modules_graph->compositing_module().nodes_templates()) @@ -115,6 +122,9 @@ void App::update() initial_project_opening(command_execution_context()); } + if (_project.shared_aspect_ratio.fill_the_view) + _project.shared_aspect_ratio.aspect_ratio.set(render_view().aspect_ratio()); + if (DebugOptions::force_rerender_every_frame()) _project.modules_graph->request_rerender_all(); @@ -313,7 +323,7 @@ void App::imgui_window_view() bool b = false; bool const align_buttons_vertically = _preview_view.has_vertical_margins() - || (!_project.view_constraint.wants_to_constrain_aspect_ratio() && !_output_view.is_open()); // Hack to avoid flickering the alignment of the buttons when we are resizing the View + || (!_project.view_constraint.does_constrain_aspect_ratio() && !_output_view.is_open()); // Hack to avoid flickering the alignment of the buttons when we are resizing the View int buttons_order{0}; // Reset cameras @@ -341,6 +351,18 @@ void App::imgui_window_view() } b |= ImGui::IsItemActive(); ImGui::SetItemTooltip("%s", _project.camera_2D_manager.is_editable_in_view() ? "2D camera is active" : "3D camera is active"); + + // Aspect Ratio + if (Cool::ImGuiExtras::floating_button(ICOMOON_CROP, buttons_order++, align_buttons_vertically)) + ImGui::OpenPopup("##Aspect Ratio"); + ImGui::SetItemTooltip("%s", "Aspect Ratio"); + if (ImGui::BeginPopup("##Aspect Ratio")) + { + _project.view_constraint.imgui_aspect_ratio(); + ImGui::EndPopup(); + } + b |= ImGui::IsItemActive(); + return b; }, }); @@ -479,14 +501,11 @@ void App::file_menu() } } -void App::view_menu() +void App::performance_menu() { - if (ImGui::BeginMenu(Cool::icon_fmt("View", ICOMOON_IMAGE, true).c_str())) + if (ImGui::BeginMenu(Cool::icon_fmt("Performance", ICOMOON_POWER, true).c_str())) { - if (_project.view_constraint.imgui()) - { - // render_impl(_view.render_target, *_current_module, _project.clock.time()); - } + _project.view_constraint.imgui_nb_pixels(); ImGui::EndMenu(); } } @@ -515,7 +534,7 @@ void App::export_menu() }, Cool::icon_fmt("Share online", ICOMOON_EARTH, true) ); - _gallery_poster.imgui_open_sharing_form(_project.view_constraint.aspect_ratio()); + _gallery_poster.imgui_open_sharing_form(); ImGui::PopStyleVar(); ImGui::EndMenu(); } @@ -557,7 +576,8 @@ void App::commands_menu() if (ImGui::Selectable(ICOMOON_IMAGE " Open output window")) { _output_view.toggle_open_close(); - _project.view_constraint.should_control_aspect_ratio(false); + if (_output_view.is_open()) + _project.shared_aspect_ratio.fill_the_view = true; } if (ImGui::Selectable(ICOMOON_FOLDER_OPEN " Open user-data folder")) Cool::open(Cool::Path::user_data().string().c_str()); @@ -579,8 +599,8 @@ void App::imgui_menus() file_menu(); export_menu(); // windows_menu();/// This menu might make sense if we have several views one day, but for now it just creates a menu for no reason - view_menu(); settings_menu(); + performance_menu(); commands_menu(); ImGui::SetCursorPosX( // HACK while waiting for ImGui to support right-to-left layout. See issue https://github.com/ocornut/imgui/issues/5875 @@ -661,13 +681,11 @@ void App::check_inputs__timeline() void App::open_image_exporter() { - _project.exporter.maybe_set_aspect_ratio(_project.view_constraint.aspect_ratio()); _project.exporter.image_export_window().open(); } void App::open_video_exporter() { - _project.exporter.maybe_set_aspect_ratio(_project.view_constraint.aspect_ratio()); _project.exporter.video_export_window().open(); } diff --git a/src/App.h b/src/App.h index 9704181c..2f914c82 100644 --- a/src/App.h +++ b/src/App.h @@ -61,6 +61,7 @@ class App : public Cool::IApp { public: explicit App(Cool::WindowManager& windows, Cool::ViewsManager& views); void on_shutdown() override; + void on_project_loaded(); void update() override; void request_rerender() override; @@ -105,7 +106,7 @@ class App : public Cool::IApp { void reset_cameras(); void file_menu(); - void view_menu(); + void performance_menu(); void export_menu(); void settings_menu(); void commands_menu(); diff --git a/src/Gallery/GalleryPoster.cpp b/src/Gallery/GalleryPoster.cpp index 0c972309..c83a0a32 100644 --- a/src/Gallery/GalleryPoster.cpp +++ b/src/Gallery/GalleryPoster.cpp @@ -24,17 +24,14 @@ static constexpr bool has_openssl = false; #endif -void GalleryPoster::imgui_open_sharing_form(std::optional const& aspect_ratio) +void GalleryPoster::imgui_open_sharing_form() { Cool::ImGuiExtras::disabled_if( !has_openssl, - "DEV ONLY: We didn't find the OpenSSL library on your machine while compiling Coollab so this feature was disabled.\nLook at how to install OpenSSL on your computer if you want this feature.", [&]() { + "DEV ONLY: We didn't find the OpenSSL library on your machine while compiling Coollab so this feature was disabled.\nLook at how to install OpenSSL on your computer if you want this feature.", + [&]() { if (ImGui::Button(Cool::icon_fmt("Share online", ICOMOON_EARTH, true).c_str())) - { _window.open(); - if (aspect_ratio) - _aspect_ratio = *aspect_ratio; - } } ); } @@ -46,7 +43,7 @@ void GalleryPoster::imgui_window(std::function const& re Cool::ImGuiExtras::markdown("If you want to edit or remove it, send an email at [coollab.lib@gmail.com](mailto:coollab.lib@gmail.com) from the email address that you will provide below."); Cool::ImGuiExtras::separator_text("Artwork"); _artwork_info.imgui(); - _aspect_ratio.imgui(0.f, "Aspect Ratio"); + _shared_aspect_ratio->aspect_ratio.imgui(0.f, "Aspect Ratio"); { auto const size = export_size(); auto sz = glm::ivec2{ @@ -82,7 +79,7 @@ void GalleryPoster::imgui_window(std::function const& re auto GalleryPoster::export_size() const -> img::Size { - return Cool::compute_image_size(_aspect_ratio.get(), 2'250'000.f); + return Cool::compute_image_size(_shared_aspect_ratio->aspect_ratio.get(), 2'250'000.f); } } // namespace Lab \ No newline at end of file diff --git a/src/Gallery/GalleryPoster.h b/src/Gallery/GalleryPoster.h index 682d5dd3..1776c1b9 100644 --- a/src/Gallery/GalleryPoster.h +++ b/src/Gallery/GalleryPoster.h @@ -2,7 +2,7 @@ #include "ArtworkInfo.h" #include "AuthorInfo.h" #include "Cool/ImGui/ImGuiWindow.h" -#include "Cool/Image/AspectRatio.h" +#include "Cool/Image/SharedAspectRatio.hpp" #include "LegalInfo.h" namespace Lab { @@ -11,19 +11,21 @@ class GalleryPoster { public: GalleryPoster(); - void imgui_open_sharing_form(std::optional const&); + void imgui_open_sharing_form(); /// `render` is a function that renders an image to a .png and returns it in a string. void imgui_window(std::function const& render_png); + void set_shared_aspect_ratio(Cool::SharedAspectRatio& shared_aspect_ratio) { _shared_aspect_ratio = &shared_aspect_ratio; } + private: [[nodiscard]] auto export_size() const -> img::Size; private: - Cool::ImGuiWindow _window; - ArtworkInfo _artwork_info{}; - AuthorInfo _author_info{}; - LegalInfo _legal_info{}; - Cool::AspectRatio _aspect_ratio{}; + Cool::ImGuiWindow _window; + ArtworkInfo _artwork_info{}; + AuthorInfo _author_info{}; + LegalInfo _legal_info{}; + Cool::SharedAspectRatio* _shared_aspect_ratio{}; private: // Serialization @@ -34,8 +36,7 @@ class GalleryPoster { archive( ser20::make_nvp("Artwork info", _artwork_info), ser20::make_nvp("Author info", _author_info), - ser20::make_nvp("Legal info", _legal_info), - ser20::make_nvp("Aspect Ratio", _aspect_ratio) + ser20::make_nvp("Legal info", _legal_info) ); } }; diff --git a/src/Project.h b/src/Project.h index ee652a0c..f532343d 100644 --- a/src/Project.h +++ b/src/Project.h @@ -3,6 +3,7 @@ #include "Cool/Audio/AudioManager.h" #include "Cool/Exporter/Exporter.h" #include "Cool/Image/ImageSizeConstraint.h" +#include "Cool/Image/SharedAspectRatio.hpp" #include "Cool/Midi/MidiManager.h" #include "Cool/OSC/OSCConnectionEndpoint.h" #include "Cool/StrongTypes/Camera2D.h" @@ -24,6 +25,7 @@ struct Project { Cool::Exporter exporter; Cool::AudioManager audio; Cool::OSCConnectionEndpoint osc_endpoint{}; + Cool::SharedAspectRatio shared_aspect_ratio{}; [[nodiscard]] auto is_empty() const -> bool; [[nodiscard]] auto current_clock() const -> Cool::Clock const& { return exporter.is_exporting() ? exporter.clock() : clock; } @@ -47,7 +49,8 @@ struct Project { ser20::make_nvp("History", history), ser20::make_nvp("Audio", audio), ser20::make_nvp("OSC Endpoint", osc_endpoint), - ser20::make_nvp("MIDI Channels", Cool::midi_manager().all_values()) + ser20::make_nvp("MIDI Channels", Cool::midi_manager().all_values()), + ser20::make_nvp("Shared Aspect Ratio", shared_aspect_ratio) ); } }; diff --git a/src/ProjectManager/internal_utils.cpp b/src/ProjectManager/internal_utils.cpp index b72503cf..df9261ce 100644 --- a/src/ProjectManager/internal_utils.cpp +++ b/src/ProjectManager/internal_utils.cpp @@ -1,5 +1,6 @@ #include "internal_utils.h" #include +#include "App.h" #include "Command_SaveProject.h" #include "Common/Path.h" #include "Cool/OSC/OSCManager.h" @@ -45,6 +46,7 @@ void set_current_project(CommandExecutionContext_Ref const& ctx, Project&& proje before_project_destruction(ctx); ctx.project() = std::move(project); + ctx.app().on_project_loaded(); for (auto& [_, node] : ctx.project().modules_graph->graph().nodes()) ctx.make_sure_node_uses_the_most_up_to_date_version_of_its_definition(node.downcast());