2025-09-22 23:13:28 +02:00
|
|
|
#include "DefaultApp.hpp"
|
2025-08-18 22:39:43 +00:00
|
|
|
|
2025-09-13 14:49:59 +02:00
|
|
|
#include <cstddef>
|
2025-08-18 22:39:43 +00:00
|
|
|
#include <format>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
2025-09-22 23:13:28 +02:00
|
|
|
#include "PixelariumImageFactory.hpp"
|
2025-09-13 14:49:59 +02:00
|
|
|
#include "app_resources_default.h"
|
2025-08-18 22:39:43 +00:00
|
|
|
#include "imgui.h"
|
|
|
|
|
#include "portable-file-dialogs.h"
|
2025-09-13 14:49:59 +02:00
|
|
|
#include "rendering/RenderImageManager.hpp"
|
2025-09-22 23:13:28 +02:00
|
|
|
#include "resources/resource.hpp"
|
2025-08-18 22:39:43 +00:00
|
|
|
#include "utilities/ILog.hpp"
|
|
|
|
|
|
|
|
|
|
using namespace pixelarium::imaging;
|
|
|
|
|
|
2025-09-22 23:13:28 +02:00
|
|
|
void pixelarium::ui::DefaultApp::MenuBarOptionsColumn1()
|
2025-08-18 22:39:43 +00:00
|
|
|
{
|
|
|
|
|
ImGui::MenuItem(SHOWIMGUIDEMOS, NULL, &this->demop_);
|
|
|
|
|
ImGui::MenuItem(SHOWIMAGEGALLERY, NULL, &this->image_listp_);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-22 23:13:28 +02:00
|
|
|
void pixelarium::ui::DefaultApp::MenuBarOptionsColumn2()
|
2025-08-18 22:39:43 +00:00
|
|
|
{
|
|
|
|
|
if (ImGui::BeginMenu(FILEMENUNAME))
|
|
|
|
|
{
|
2025-09-22 23:13:28 +02:00
|
|
|
if (ImGui::MenuItem(LOADIMAGE))
|
2025-08-18 22:39:43 +00:00
|
|
|
{
|
2025-09-22 23:13:28 +02:00
|
|
|
this->LoadImage();
|
2025-08-18 22:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-22 23:13:28 +02:00
|
|
|
void pixelarium::ui::DefaultApp::Run()
|
2025-08-18 22:39:43 +00:00
|
|
|
{
|
|
|
|
|
if (demop_) ImGui::ShowDemoWindow(&this->demop_);
|
|
|
|
|
if (image_listp_) this->ImageGalleryRender();
|
2025-09-13 14:49:59 +02:00
|
|
|
|
|
|
|
|
this->RenderImages();
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-22 23:13:28 +02:00
|
|
|
void pixelarium::ui::DefaultApp::RenderImages()
|
2025-09-13 14:49:59 +02:00
|
|
|
{
|
|
|
|
|
this->render_manager_->Enumerate(
|
|
|
|
|
[&](resources::ResourceKey key, render::RenderImageStateWrapper& render_state)
|
|
|
|
|
{
|
|
|
|
|
render_state.view->ShowImage();
|
|
|
|
|
|
|
|
|
|
if (!*render_state.view->GetStatus())
|
|
|
|
|
{
|
|
|
|
|
this->render_manager_->MarkForDeletion(key);
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-08-18 22:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-22 23:13:28 +02:00
|
|
|
void pixelarium::ui::DefaultApp::ImageGalleryRender()
|
2025-08-18 22:39:43 +00:00
|
|
|
{
|
2025-09-13 14:49:59 +02:00
|
|
|
ImGui::SetNextWindowSize(ImVec2(300, 500));
|
2025-09-22 23:13:28 +02:00
|
|
|
ImGui::Begin(SHOWIMAGEGALLERY, &this->image_listp_);
|
2025-09-13 14:49:59 +02:00
|
|
|
|
|
|
|
|
// this updates the render collection
|
|
|
|
|
// essentially deleting render views that were
|
|
|
|
|
// marked for deletion
|
|
|
|
|
this->render_manager_->UpdateCollection();
|
|
|
|
|
|
|
|
|
|
static size_t selected_index{0};
|
|
|
|
|
int highlight_index{-1};
|
|
|
|
|
|
|
|
|
|
if (ImGui::BeginListBox("Image List", ImVec2(200, 400)))
|
2025-08-18 22:39:43 +00:00
|
|
|
{
|
2025-09-13 14:49:59 +02:00
|
|
|
pool_.EnumerateResources(
|
2025-09-22 23:13:28 +02:00
|
|
|
[&](size_t id, size_t idx, const imaging::IPixelariumImage& img) -> void
|
2025-09-13 14:49:59 +02:00
|
|
|
{
|
|
|
|
|
const bool is_selected = selected_index == idx;
|
|
|
|
|
if (ImGui::Selectable(std::format("{}", img.Name()).c_str(), is_selected))
|
|
|
|
|
{
|
|
|
|
|
selected_index = idx;
|
|
|
|
|
this->selected_image_ = id;
|
|
|
|
|
}
|
|
|
|
|
if (highlight_index && ImGui::IsItemHovered()) highlight_index = idx;
|
|
|
|
|
|
|
|
|
|
if (is_selected) ImGui::SetItemDefaultFocus();
|
|
|
|
|
});
|
2025-08-18 22:39:43 +00:00
|
|
|
|
|
|
|
|
ImGui::EndListBox();
|
|
|
|
|
}
|
2025-09-13 14:49:59 +02:00
|
|
|
|
|
|
|
|
ImGui::Checkbox(AUTOSHOWSELECTED, &this->auto_show_selectd_image_);
|
|
|
|
|
ImGui::SameLine(); // put the button next to the checkbox
|
|
|
|
|
// note that the button will only show when the checkbox is toggled off
|
|
|
|
|
// this is intended behavior as the selected image will render automatically
|
|
|
|
|
// when the checkbox is toggled on
|
|
|
|
|
if (this->auto_show_selectd_image_ || ImGui::Button(OPENIMAGE))
|
|
|
|
|
{
|
|
|
|
|
// Try add the selected index to the manager
|
|
|
|
|
this->render_manager_->Add(this->selected_image_);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-22 23:13:28 +02:00
|
|
|
if (ImGui::Button(LOADIMAGE))
|
|
|
|
|
{
|
|
|
|
|
this->LoadImage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ImGui::Button(REMOVEIMAGE))
|
|
|
|
|
{
|
|
|
|
|
this->render_manager_->MarkForDeletion(this->selected_image_);
|
|
|
|
|
this->pool_.DeleteResource(this->selected_image_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button(CLEARALL))
|
|
|
|
|
{
|
|
|
|
|
this->render_manager_->Clear();
|
|
|
|
|
this->pool_.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-13 14:49:59 +02:00
|
|
|
ImGui::End(); // end gallery window
|
2025-08-18 22:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-22 23:13:28 +02:00
|
|
|
void pixelarium::ui::DefaultApp::LoadImage()
|
2025-08-18 22:39:43 +00:00
|
|
|
{
|
|
|
|
|
size_t last_id{};
|
|
|
|
|
auto res{pfd::open_file("Load Inputs", pfd::path::home(), {"All Files", "*"}, pfd::opt::multiselect).result()};
|
|
|
|
|
for (auto& p : res)
|
|
|
|
|
{
|
|
|
|
|
this->logger_.Debug(std::format("{}: Creating image {}", __FUNCTION__, p));
|
|
|
|
|
|
2025-09-22 23:13:28 +02:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
pool_.SetResource(PixelariumImageFactory::CreateImage(p));
|
|
|
|
|
}
|
|
|
|
|
catch (pixelarium::resources::empty_resource_exception& e)
|
|
|
|
|
{
|
|
|
|
|
logger_.Error(std::format("{}: Failed to load file '{}' with '{}'", __PRETTY_FUNCTION__, p, e.what()));
|
|
|
|
|
}
|
2025-08-18 22:39:43 +00:00
|
|
|
}
|
|
|
|
|
}
|