init view abstractions
This commit is contained in:
committed by
Kueffner, Maximilian
parent
6370bfdff6
commit
790c55c0bb
+13
-5
@@ -117,9 +117,19 @@ int pixelarium::ui::AppGLFW::Run()
|
||||
this->MenuBar();
|
||||
if (demop_) ImGui::ShowDemoWindow(&this->demop_);
|
||||
|
||||
if (this->image_view_)
|
||||
// if (this->image_view_)
|
||||
// {
|
||||
// this->image_view_->ShowImage();
|
||||
// }
|
||||
|
||||
if (ImGui::BeginListBox("ListBox"))
|
||||
{
|
||||
this->image_view_->ShowImage();
|
||||
pool_.EnumerateResources([](size_t id, const imaging::PixelariumImage& img) -> void
|
||||
{
|
||||
ImGui::Selectable(std::format("Image {}", id).c_str());
|
||||
});
|
||||
|
||||
ImGui::EndListBox();
|
||||
}
|
||||
|
||||
// Rendering
|
||||
@@ -198,8 +208,6 @@ void pixelarium::ui::AppGLFW::LoadImageProt()
|
||||
{
|
||||
this->logger_.Debug(std::format("{}: Creating image {}", __FUNCTION__, p));
|
||||
|
||||
auto img = std::make_shared<PixelariumImage>(p);
|
||||
this->image_view_ = std::make_shared<PixelariumImageView>(img);
|
||||
this->image_view_->ToggleView(true);
|
||||
image_view_model_->AddImage(std::move(std::make_unique<PixelariumImage>(p)));
|
||||
}
|
||||
}
|
||||
|
||||
+8
-19
@@ -11,33 +11,21 @@
|
||||
#include "rendering/CvMatRender.hpp"
|
||||
#include "resources/resource.hpp"
|
||||
#include "utilities/ILog.hpp"
|
||||
#include "viewmodels/ImageViewFactory.hpp"
|
||||
#include "views/PixelariumImageView.hpp"
|
||||
|
||||
namespace pixelarium::ui
|
||||
{
|
||||
// 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);
|
||||
|
||||
class AppGLFW
|
||||
{
|
||||
public:
|
||||
explicit AppGLFW(std::unique_ptr<utils::log::ILog>& log) : logger_(*log)
|
||||
AppGLFW(std::unique_ptr<utils::log::ILog>& log, std::unique_ptr<pixelarium::resources::ImageResourcePool>& pool)
|
||||
: logger_(*log), pool_(*pool)
|
||||
{
|
||||
logger_.Debug(std::format("{}: Initiating a new window", __FUNCTION__).c_str());
|
||||
|
||||
if (pool_)
|
||||
{
|
||||
logger_.Debug(std::format("{}: We have an image resource pool!", __FUNCTION__).c_str());
|
||||
}
|
||||
image_view_model_ = std::make_unique<ImageViewFactory>(pool_);
|
||||
|
||||
this->InitMainWindow();
|
||||
}
|
||||
AppGLFW(std::unique_ptr<utils::log::ILog>& log, std::unique_ptr<pixelarium::resources::ImageResourcePool>& pool)
|
||||
: AppGLFW(log)
|
||||
{
|
||||
pool_ = pool.get();
|
||||
};
|
||||
int Run();
|
||||
|
||||
private:
|
||||
@@ -47,12 +35,13 @@ class AppGLFW
|
||||
|
||||
private:
|
||||
utils::log::ILog& logger_;
|
||||
resources::ImageResourcePool* pool_;
|
||||
resources::ImageResourcePool& pool_;
|
||||
GLFWwindow* window = nullptr;
|
||||
ImGuiWindowFlags window_flags_ = 0;
|
||||
// std::shared_ptr<pixelarium::imaging::PixelariumImage> img_;
|
||||
std::shared_ptr<pixelarium::ui::PixelariumImageView> image_view_;
|
||||
pixelarium::render::CvMatRender render_;
|
||||
// std::shared_ptr<pixelarium::ui::PixelariumImageView> image_view_;
|
||||
std::unique_ptr<ImageViewFactory> image_view_model_;
|
||||
// pixelarium::render::CvMatRender render_;
|
||||
bool imagep_{false};
|
||||
bool demop_{false};
|
||||
int log_level_{0};
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "ImageViewFactory.hpp"
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
using namespace pixelarium::ui;
|
||||
|
||||
std::unique_ptr<PixelariumImageView> ImageViewFactory::RenderImage(size_t image_id)
|
||||
{
|
||||
auto img{this->image_pool_.GetResource(image_id)};
|
||||
|
||||
if (!img.has_value()) return nullptr;
|
||||
|
||||
// beware: here we copy the actual image resource over to the new image
|
||||
return std::make_unique<PixelariumImageView>(std::make_shared<Image>(*img.value()));
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "PixelariumImage.hpp"
|
||||
#include "resources/resource.hpp"
|
||||
#include "views/PixelariumImageView.hpp"
|
||||
namespace pixelarium::ui
|
||||
{
|
||||
class ImageViewFactory
|
||||
{
|
||||
using Image = imaging::PixelariumImage;
|
||||
using Pool = resources::ImageResourcePool;
|
||||
|
||||
public:
|
||||
explicit ImageViewFactory(Pool& pool) : image_pool_(pool) {}
|
||||
|
||||
[[nodiscard("Image Id is ignored")]]
|
||||
size_t AddImage(std::unique_ptr<imaging::PixelariumImage> res) const noexcept
|
||||
{
|
||||
return image_pool_.SetResource(std::move(res));
|
||||
}
|
||||
|
||||
std::unique_ptr<PixelariumImageView> RenderImage(size_t id);
|
||||
|
||||
private:
|
||||
Pool& image_pool_;
|
||||
};
|
||||
} // namespace pixelarium::ui
|
||||
Reference in New Issue
Block a user