diff --git a/CMakeLists.txt b/CMakeLists.txt index e5747a0..c62ada8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,7 @@ add_subdirectory(lib) set(SRC src/AppGLFW.cpp + src/views/PixelariumImageView.cpp src/main.cpp ${imgui_DIR}/imgui.cpp ${imgui_DIR}/imgui_demo.cpp diff --git a/lib/rendering/CvMatRender.hpp b/lib/rendering/CvMatRender.hpp index 0f485da..2aea15d 100644 --- a/lib/rendering/CvMatRender.hpp +++ b/lib/rendering/CvMatRender.hpp @@ -31,7 +31,7 @@ class CvMatRender CvMatRender(const CvMatRender&) = delete; CvMatRender(CvMatRender&&) = delete; CvMatRender& operator=(CvMatRender&) = default; - CvMatRender& operator=(CvMatRender&&) = default; + CvMatRender& operator=(CvMatRender&& other) = default; ~CvMatRender(); explicit CvMatRender(const std::shared_ptr& img); diff --git a/src/AppGLFW.cpp b/src/AppGLFW.cpp index d9f993c..b62ce89 100644 --- a/src/AppGLFW.cpp +++ b/src/AppGLFW.cpp @@ -11,30 +11,10 @@ #include "rendering/CvMatRender.hpp" #include "uiresources.h" #include "utilities/ILog.hpp" +#include "views/PixelariumImageView.hpp" using namespace pixelarium::imaging; -/*static*/ bool pixelarium::ui::dim_changed_p(const ImVec2& ref_rect, const ImVec2& new_rect) -{ - if (std::abs(ref_rect.y - new_rect.y) > 5 || std::abs(ref_rect.x - new_rect.x)) - { - return true; - } - - return false; -} - -/*static*/ ImVec2 pixelarium::ui::aspect_const_dimensions(const pixelarium::imaging::PixelariumImage& img, - const ImVec2& curr_dim) -{ - const auto w_fact = (static_cast(curr_dim.x) / img.GetImage().cols); - const auto h_fact = (static_cast(curr_dim.y) / img.GetImage().rows); - - const auto fact = w_fact < h_fact ? w_fact : h_fact; - - return ImVec2(img.GetImage().cols * fact, img.GetImage().rows * fact); -} - void pixelarium::ui::AppGLFW::InitMainWindow() { glfwSetErrorCallback(glfw_error_callback); @@ -135,37 +115,11 @@ int pixelarium::ui::AppGLFW::Run() ImGui::DockSpaceOverViewport(ImGui::GetID("Backspace")); this->MenuBar(); - if (demop_) - ImGui::ShowDemoWindow(&this->demop_); - if (this->imagep_) + if (demop_) ImGui::ShowDemoWindow(&this->demop_); + + if (this->image_view_) { - // auto render = render::CvMatRender(this->_img); - ImGui::Begin("An image", &this->imagep_, ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_MenuBar); - this->curr_dim_ = ImGui::GetContentRegionAvail(); - auto new_dim = ImGui::GetContentRegionAvail(); - auto texture = dim_changed_p(this->curr_dim_, new_dim) - ? this->render_.Render(static_cast(this->curr_dim_.x), - static_cast(this->curr_dim_.y)) - : this->render_.Render(); - - this->curr_dim_ = new_dim; - - // random aspect ratio - // ImGui::Image(reinterpret_cast( - // reinterpret_cast(*texture)), - // this->_curr_dim); - ImVec2 dim(this->img_->GetImage().cols, this->img_->GetImage().rows); - // aspect ratio constant render - ImGui::Image(reinterpret_cast(reinterpret_cast(texture)), - aspect_const_dimensions(*this->img_, new_dim)); - // ImGui::Image(reinterpret_cast(reinterpret_cast(texture)), - // ImVec2(img_->GetImage().cols, img_->GetImage().rows)); - - // We can do everything else from within the image buffer that ImGui offers - // ImGui::Separator(); - // ImGui::Text("This is a text within the image frame"); - - ImGui::End(); + this->image_view_->ShowImage(); } // Rendering @@ -212,8 +166,7 @@ void pixelarium::ui::AppGLFW::MenuBar() log_level_ = n; this->logger_.ChangeLevel(static_cast(1 << log_level_)); } - if (is_selected) - ImGui::SetItemDefaultFocus(); + if (is_selected) ImGui::SetItemDefaultFocus(); } ImGui::EndCombo(); } @@ -245,8 +198,8 @@ void pixelarium::ui::AppGLFW::LoadImageProt() { this->logger_.Debug(std::format("{}: Creating image {}", __FUNCTION__, p)); - this->img_ = std::make_shared(p); - this->render_ = pixelarium::render::CvMatRender(this->img_); - this->imagep_ = true; + auto img = std::make_shared(p); + this->image_view_ = std::make_shared(img); + this->image_view_->ToggleView(true); } } diff --git a/src/AppGLFW.hpp b/src/AppGLFW.hpp index 5ff7f96..0eeff0d 100644 --- a/src/AppGLFW.hpp +++ b/src/AppGLFW.hpp @@ -11,20 +11,13 @@ #include "rendering/CvMatRender.hpp" #include "resources/resource.hpp" #include "utilities/ILog.hpp" +#include "views/PixelariumImageView.hpp" namespace pixelarium::ui { -static bool dim_changed_p(const ImVec2& ref_rect, const ImVec2& new_rect); +// static bool dim_changed_p(const ImVec2& ref_rect, const ImVec2& new_rect); -static ImVec2 aspect_const_dimensions(const pixelarium::imaging::PixelariumImage& img, const ImVec2& curr_dim); - -enum LogLevelSelection -{ - Debug = 0, - Info = 1, - Warning = 2, - Error = 3 -}; +// static ImVec2 aspect_const_dimensions(const pixelarium::imaging::PixelariumImage& img, const ImVec2& curr_dim); class AppGLFW { @@ -53,12 +46,12 @@ class AppGLFW void LoadImageProt(); private: - // LogLevelSelection log_level_ = static_cast(0); utils::log::ILog& logger_; resources::ImageResourcePool* pool_; GLFWwindow* window = nullptr; ImGuiWindowFlags window_flags_ = 0; - std::shared_ptr img_; + // std::shared_ptr img_; + std::shared_ptr image_view_; pixelarium::render::CvMatRender render_; bool imagep_{false}; bool demop_{false};