init view abstractions
This commit is contained in:
committed by
Kueffner, Maximilian
parent
6370bfdff6
commit
790c55c0bb
@@ -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