diff --git a/assets/editor/localization.csv b/assets/editor/localization.csv index a1f0f23..3e07bd9 100644 --- a/assets/editor/localization.csv +++ b/assets/editor/localization.csv @@ -16,6 +16,7 @@ LOC_EDITOR_MENU_TOOLS;Tools;Outils LOC_EDITOR_MENU_LANGUAGE;Language;Langue LOC_EDITOR_MENU_VIEW;View;Fenetre LOC_EDITOR_MENU_RESOLUTION;Resolution;Résolution +LOC_EDITOR_MENU_ASPECTRATIO;Aspect Ratio;Aspect Ratio LOC_EDITOR_ACTION_LEVEL_NEW_DESC;Create new level;Créé un nouveau niveau LOC_EDITOR_ACTION_LEVEL_OPEN_DESC;Open a level;Ouvre un niveau LOC_EDITOR_ACTION_LEVEL_SAVE_DESC;Save current level;Sauvegarde le niveau actuel @@ -28,4 +29,8 @@ LOC_EDITOR_WINDOW_LEVEL_TITLE;Level;Niveau LOC_EDITOR_WINDOW_MAIN_TITLE;MainWindow;Fenêtre principale LOC_EDITOR_WINDOW_OUTPUT_TITLE;Output;Sortie LOC_EDITOR_POPUP_CREATE_LEVEL_TITLE;Warning;Attention -LOC_EDITOR_POPUP_CREATE_LEVEL_DESC;Are you sure you want to create a new level?;Etes-vous sur de vouloir créer un nouveau niveau? \ No newline at end of file +LOC_EDITOR_POPUP_CREATE_LEVEL_DESC;Are you sure you want to create a new level?;Etes-vous sur de vouloir créer un nouveau niveau? +LOC_EDITOR_CAMERA_KEEPASPECTRATIO_TITLE;Aspect Ratio;Aspect Ratio +LOC_EDITOR_CAMERA_KEEPASPECTRATIO_DESC;Keep Aspect Ratio;Garder l'aspect ratio +LOC_EDITOR_CAMERA_FILL_TITLE;Fill;Remplir +LOC_EDITOR_CAMERA_FILL_DESC;Fills the window;Remplis la fenetre \ No newline at end of file diff --git a/include/NazaraEditor/Core/Application/Actions/EditorAction_Camera.hpp b/include/NazaraEditor/Core/Application/Actions/EditorAction_Camera.hpp index 037ed7f..c9de5e7 100644 --- a/include/NazaraEditor/Core/Application/Actions/EditorAction_Camera.hpp +++ b/include/NazaraEditor/Core/Application/Actions/EditorAction_Camera.hpp @@ -32,4 +32,29 @@ namespace Nz protected: Nz::Vector2ui m_size; }; + + class NAZARAEDITOR_CORE_API EditorAction_SetCameraStretchMode final + : public EditorAction + { + public: + EditorAction_SetCameraStretchMode(const Properties& properties, StretchMode mode) + : EditorAction(properties) + , m_mode(mode) + {} + EditorAction_SetCameraStretchMode(const std::shared_ptr& properties, StretchMode mode) + : EditorAction(properties) + , m_mode(mode) + {} + ~EditorAction_SetCameraStretchMode() = default; + + std::unique_ptr Clone() const override { return std::make_unique(m_properties, m_mode); } + const std::string& GetName() const override { return m_properties->className; } + bool IsUndoRedoable() const override { return false; } + static const char* GetClassName() { return "EditorAction_SetCameraStretchMode"; } + + void Execute() override; + + protected: + StretchMode m_mode; + }; } \ No newline at end of file diff --git a/include/NazaraEditor/Core/Application/BaseApplication.hpp b/include/NazaraEditor/Core/Application/BaseApplication.hpp index f0b8e3c..18fc9a0 100644 --- a/include/NazaraEditor/Core/Application/BaseApplication.hpp +++ b/include/NazaraEditor/Core/Application/BaseApplication.hpp @@ -82,6 +82,9 @@ namespace Nz inline Nz::Texture* GetEngineTexture() { return m_engineTexture.get(); } inline const Nz::Texture* GetEngineTexture() const { return m_engineTexture.get(); } + + inline StretchMode GetEngineTextureStretchMode() const { return m_engineTextureStretchMode; } + inline void SetEngineTextureStretchMode(StretchMode mode) { m_engineTextureStretchMode = mode; } void CreateEngineTexture(const Nz::Vector2ui& resolution); @@ -103,5 +106,7 @@ namespace Nz Nz::Level m_level; entt::handle m_mainCamera; + + StretchMode m_engineTextureStretchMode; }; } \ No newline at end of file diff --git a/include/NazaraEditor/Core/Config.hpp b/include/NazaraEditor/Core/Config.hpp index 19199c9..1d60306 100644 --- a/include/NazaraEditor/Core/Config.hpp +++ b/include/NazaraEditor/Core/Config.hpp @@ -15,4 +15,13 @@ #define NAZARAEDITOR_CORE_API #endif +namespace Nz +{ + enum StretchMode + { + Fill, + KeepAspectRatio + }; +} + #endif // NAZARAEDITOR_CORE_CONFIG_HPP diff --git a/src/NazaraEditor/Core/Application/Actions/EditorAction_Camera.cpp b/src/NazaraEditor/Core/Application/Actions/EditorAction_Camera.cpp index 3afa299..e3f0c7e 100644 --- a/src/NazaraEditor/Core/Application/Actions/EditorAction_Camera.cpp +++ b/src/NazaraEditor/Core/Application/Actions/EditorAction_Camera.cpp @@ -21,10 +21,29 @@ namespace Nz .category = "Tools", }, size); } + + app.RegisterAction({ + .className = std::format("{}_{}", Nz::EditorAction_SetCameraSize::GetClassName(), "Fill"), + .description = "LOC_EDITOR_CAMERA_FILL_DESC", + .path = { "LOC_EDITOR_MENU_VIEW", "LOC_EDITOR_MENU_ASPECTRATIO", "LOC_EDITOR_CAMERA_FILL_TITLE" }, + .category = "Tools", + }, StretchMode::Fill); + + app.RegisterAction({ + .className = std::format("{}_{}", Nz::EditorAction_SetCameraSize::GetClassName(), "AspectRatio"), + .description = "LOC_EDITOR_CAMERA_KEEPASPECTRATIO_DESC", + .path = { "LOC_EDITOR_MENU_VIEW", "LOC_EDITOR_MENU_ASPECTRATIO", "LOC_EDITOR_CAMERA_KEEPASPECTRATIO_TITLE" }, + .category = "Tools", + }, StretchMode::KeepAspectRatio); } void EditorAction_SetCameraSize::Execute() { Nz::EditorBaseApplication::Instance()->CreateEngineTexture(m_size); } + + void EditorAction_SetCameraStretchMode::Execute() + { + Nz::EditorBaseApplication::Instance()->SetEngineTextureStretchMode(m_mode); + } } \ No newline at end of file diff --git a/src/NazaraEditor/Core/Application/BaseApplication.cpp b/src/NazaraEditor/Core/Application/BaseApplication.cpp index 213335f..b6ef46c 100644 --- a/src/NazaraEditor/Core/Application/BaseApplication.cpp +++ b/src/NazaraEditor/Core/Application/BaseApplication.cpp @@ -18,6 +18,7 @@ namespace Nz EditorBaseApplication::EditorBaseApplication() : m_level(this) + , m_engineTextureStretchMode(StretchMode::KeepAspectRatio) { NazaraAssert(s_instance == nullptr, "EditorBaseApplication already exists"); s_instance = this; diff --git a/src/NazaraEditor/Editor/UI/MainWindow.cpp b/src/NazaraEditor/Editor/UI/MainWindow.cpp index c7eebff..ba0658c 100644 --- a/src/NazaraEditor/Editor/UI/MainWindow.cpp +++ b/src/NazaraEditor/Editor/UI/MainWindow.cpp @@ -22,7 +22,29 @@ namespace NzEditor { auto pos = ImGui::GetCursorPos(); auto size = ImGui::GetContentRegionAvail(); - ImGui::Image(GetApplication()->GetEngineTexture(), Nz::Vector2f{ size.x, size.y }); + auto stretch = GetApplication()->GetEngineTextureStretchMode(); + + auto texSize = GetApplication()->GetEngineTexture()->GetSize(); + + if (stretch == Nz::StretchMode::KeepAspectRatio) + { + if (texSize.x > texSize.y) + { + float x = size.x; + float y = texSize.y * size.x / texSize.x; + ImGui::Image(GetApplication()->GetEngineTexture(), Nz::Vector2f{ x, y }); + } + else + { + float x = texSize.x * size.y / texSize.y; + float y = size.y; + ImGui::Image(GetApplication()->GetEngineTexture(), Nz::Vector2f{ x, y }); + } + } + else + { + ImGui::Image(GetApplication()->GetEngineTexture(), Nz::Vector2f{ size.x, size.y }); + } ImGui::SetCursorPos(pos); // everything else will be drawn on top of the texture auto cam = GetApplication()->GetMainCamera();