Misc (#19)
* get image returns optional<Mat> instead of unique_ptr<Mat> * introduce complexity * rename image load function * add example for a basic reader for binary image files * fix windows build? * add a status bar underneath the menu bar * use status bar in custom_0 example app * clang formats * packing w/ pragma push * add "Save As" functions to image views * resize over reserve * rm local override uri * add simple thread pool * rename to simple_thread_pool * get rid of useless renderlib * document version inc * extract hardcoded values to in-header * clang format patch * clone registered image in custom_0 * document binary-file header * minor fixes * clang format * rm unused render cmake
This commit is contained in:
committed by
Maximilian Kueffner
parent
e3e161ce52
commit
b37814204f
@@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "IPixelariumImageView.hpp"
|
||||
#include "ImageViewFactory.hpp"
|
||||
#include "resources/resource.hpp"
|
||||
#include "utilities/ILog.hpp"
|
||||
|
||||
// This is intended as an additional abstraction
|
||||
// aggregating views that should be rendered (or not)
|
||||
namespace pixelarium::application
|
||||
{
|
||||
/// @brief Instead of directly using the view, we
|
||||
/// proxy it through a wrapper. This allows for arbitrary additional data
|
||||
/// to be added in future
|
||||
struct RenderImageStateWrapper
|
||||
{
|
||||
std::unique_ptr<IPixelariumImageView> view;
|
||||
const bool* show_state;
|
||||
};
|
||||
|
||||
/// @brief Manage instances of IPixelariumImageView.
|
||||
///
|
||||
/// This class is used to keep track of what must be rendered.
|
||||
/// It manages a set of IPixelariumImageView instances that can be traversed
|
||||
/// via its Enumerate() function.
|
||||
/// Views that shall not be rendered anymore should be marked for deletion
|
||||
/// with MarkForDeletion()
|
||||
class RenderImageManager
|
||||
{
|
||||
using Pool = resources::ImageResourcePool;
|
||||
|
||||
public:
|
||||
explicit RenderImageManager(Pool& pool, const utils::log::ILog& log)
|
||||
: view_factory_(std::make_unique<ImageViewFactory>(pool, log)), log_(log)
|
||||
{
|
||||
}
|
||||
|
||||
void Clear() noexcept;
|
||||
|
||||
void Add(resources::ResourceKey key) noexcept;
|
||||
|
||||
bool Remove(resources::ResourceKey key) noexcept;
|
||||
|
||||
// can't be const because func mutates the state
|
||||
template <typename Callable>
|
||||
requires std::invocable<Callable, resources::ResourceKey, RenderImageStateWrapper&>
|
||||
void Enumerate(Callable&& func)
|
||||
{
|
||||
for (auto& [key, val] : this->render_image_map_)
|
||||
{
|
||||
if (val.view != nullptr)
|
||||
{
|
||||
func(key, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MarkForDeletion(resources::ResourceKey key);
|
||||
|
||||
void UpdateCollection();
|
||||
|
||||
private:
|
||||
std::unordered_map<resources::ResourceKey, RenderImageStateWrapper> render_image_map_;
|
||||
std::unique_ptr<ImageViewFactory> view_factory_;
|
||||
std::mutex mut_;
|
||||
std::unordered_set<resources::ResourceKey> keys_to_delete_;
|
||||
|
||||
const utils::log::ILog& log_;
|
||||
};
|
||||
} // namespace pixelarium::application
|
||||
Reference in New Issue
Block a user