Skip to content

Commit

Permalink
✨ Move Aspect Ratio control to a floating button + Use a shared aspec…
Browse files Browse the repository at this point in the history
…t ratio for View Constraint and Export Size
  • Loading branch information
JulesFouchy committed Nov 9, 2024
1 parent 99e899f commit 89c7e9c
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 35 deletions.
48 changes: 33 additions & 15 deletions src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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())
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
},
});
Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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());
Expand All @@ -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
Expand Down Expand Up @@ -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();
}

Expand Down
3 changes: 2 additions & 1 deletion src/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
13 changes: 5 additions & 8 deletions src/Gallery/GalleryPoster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,14 @@ static constexpr bool has_openssl =
false;
#endif

void GalleryPoster::imgui_open_sharing_form(std::optional<Cool::AspectRatio> 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;
}
}
);
}
Expand All @@ -46,7 +43,7 @@ void GalleryPoster::imgui_window(std::function<std::string(img::Size)> const& re
Cool::ImGuiExtras::markdown("If you want to edit or remove it, send an email at [[email protected]](mailto:[email protected]) 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{
Expand Down Expand Up @@ -82,7 +79,7 @@ void GalleryPoster::imgui_window(std::function<std::string(img::Size)> 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
19 changes: 10 additions & 9 deletions src/Gallery/GalleryPoster.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -11,19 +11,21 @@ class GalleryPoster {
public:
GalleryPoster();

void imgui_open_sharing_form(std::optional<Cool::AspectRatio> 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<std::string(img::Size)> 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
Expand All @@ -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)
);
}
};
Expand Down
5 changes: 4 additions & 1 deletion src/Project.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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; }
Expand All @@ -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)
);
}
};
Expand Down
2 changes: 2 additions & 0 deletions src/ProjectManager/internal_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "internal_utils.h"
#include <ProjectManager/utils.h>
#include "App.h"
#include "Command_SaveProject.h"
#include "Common/Path.h"
#include "Cool/OSC/OSCManager.h"
Expand Down Expand Up @@ -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<Node>());

Expand Down

0 comments on commit 89c7e9c

Please sign in to comment.