Resources (#1)
* start some resource fiddling * start some resource fiddling * initiate a real resource manager * fix color flicker in rendering * delete unintended constructors and add a convenience function to reset the render-image (from the original image, aka. clone again) * [OpenGL deprecation warning] The compiler said that these functions are "deprecated". They seem to be useless anyway... * various improvements * add resource enumerator and documentation * fix constness stuff * use existing iterator for insertion * init unit tests * rm bogus file --------- Co-authored-by: m-aXimilian <keuffnermax@gmail.com>
This commit is contained in:
+28
-24
@@ -1,8 +1,9 @@
|
||||
#include "AppGLFW.hpp"
|
||||
|
||||
#include <format>
|
||||
#include <memory>
|
||||
|
||||
#include "imaging/Image.hpp"
|
||||
#include "imaging/PixelariumImage.hpp"
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_glfw.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
@@ -22,7 +23,8 @@ using namespace pixelarium::imaging;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*static*/ ImVec2 pixelarium::ui::ascpet_const_dimensions(const pixelarium::imaging::Image& img, const ImVec2& curr_dim)
|
||||
/*static*/ ImVec2 pixelarium::ui::aspect_const_dimensions(const pixelarium::imaging::PixelariumImage& img,
|
||||
const ImVec2& curr_dim)
|
||||
{
|
||||
const auto w_fact = (static_cast<float>(curr_dim.x) / img.GetImage().cols);
|
||||
const auto h_fact = (static_cast<float>(curr_dim.y) / img.GetImage().rows);
|
||||
@@ -133,27 +135,33 @@ int pixelarium::ui::AppGLFW::Run()
|
||||
|
||||
this->MenuBar();
|
||||
|
||||
if (this->_imagep)
|
||||
if (this->imagep_)
|
||||
{
|
||||
// auto render = render::CvMatRender(this->_img);
|
||||
ImGui::Begin("An image", &this->_imagep, ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_MenuBar);
|
||||
this->_curr_dim = ImGui::GetContentRegionAvail();
|
||||
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<size_t>(this->_curr_dim.x),
|
||||
static_cast<size_t>(this->_curr_dim.y))
|
||||
: this->_render.Render();
|
||||
auto texture = dim_changed_p(this->curr_dim_, new_dim)
|
||||
? this->render_.Render(static_cast<size_t>(this->curr_dim_.x),
|
||||
static_cast<size_t>(this->curr_dim_.y))
|
||||
: this->render_.Render();
|
||||
|
||||
this->_curr_dim = new_dim;
|
||||
this->curr_dim_ = new_dim;
|
||||
|
||||
// random aspect ratio
|
||||
// ImGui::Image(reinterpret_cast<Textured>(
|
||||
// reinterpret_cast<void*>(*texture)),
|
||||
// this->_curr_dim);
|
||||
ImVec2 dim(this->_img->GetImage().cols, this->_img->GetImage().rows);
|
||||
ImVec2 dim(this->img_->GetImage().cols, this->img_->GetImage().rows);
|
||||
// aspect ratio constant render
|
||||
ImGui::Image(reinterpret_cast<ImTextureID>(reinterpret_cast<void*>(*texture)),
|
||||
ascpet_const_dimensions(*this->_img, new_dim));
|
||||
ImGui::Image(reinterpret_cast<ImTextureID>(reinterpret_cast<void*>(texture)),
|
||||
aspect_const_dimensions(*this->img_, new_dim));
|
||||
// ImGui::Image(reinterpret_cast<ImTextureID>(reinterpret_cast<void*>(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();
|
||||
}
|
||||
@@ -162,8 +170,6 @@ int pixelarium::ui::AppGLFW::Run()
|
||||
ImGui::Render();
|
||||
int display_w, display_h;
|
||||
glfwGetFramebufferSize(this->window, &display_w, &display_h);
|
||||
glViewport(0, 0, display_w, display_h);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||
@@ -217,15 +223,13 @@ void pixelarium::ui::AppGLFW::LoadImageProt()
|
||||
auto res{pfd::open_file("Load Inputs", pfd::path::home(), {"All Files", "*"}, pfd::opt::multiselect).result()};
|
||||
for (auto& p : res)
|
||||
{
|
||||
// lg::Logger::Debug("Adding image from " + std::string(p),
|
||||
// __FUNCTION__);
|
||||
if (this->_logger)
|
||||
if (this->logger_)
|
||||
{
|
||||
this->_logger->Warn(std::format("Creating image {}", p));
|
||||
this->logger_->Debug(std::format("{}: Creating image {}", __FUNCTION__, p));
|
||||
}
|
||||
// this->_img = Image(p);
|
||||
this->_img = std::make_shared<Image>(p);
|
||||
this->_render = pixelarium::render::CvMatRender(this->_img);
|
||||
this->_imagep = true;
|
||||
|
||||
this->img_ = std::make_shared<PixelariumImage>(p);
|
||||
this->render_ = pixelarium::render::CvMatRender(this->img_);
|
||||
this->imagep_ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+30
-10
@@ -3,18 +3,20 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <format>
|
||||
#include <memory>
|
||||
|
||||
#include "Image.hpp"
|
||||
#include "PixelariumImage.hpp"
|
||||
#include "imgui.h"
|
||||
#include "rendering/CvMatRender.hpp"
|
||||
#include "resources/resource.hpp"
|
||||
#include "utilities/ILog.hpp"
|
||||
|
||||
namespace pixelarium::ui
|
||||
{
|
||||
static bool dim_changed_p(const ImVec2& ref_rect, const ImVec2& new_rect);
|
||||
|
||||
static ImVec2 ascpet_const_dimensions(const pixelarium::imaging::Image& img, const ImVec2& curr_dim);
|
||||
static ImVec2 aspect_const_dimensions(const pixelarium::imaging::PixelariumImage& img, const ImVec2& curr_dim);
|
||||
|
||||
enum LogLevelSelection
|
||||
{
|
||||
@@ -28,7 +30,24 @@ class AppGLFW
|
||||
{
|
||||
public:
|
||||
AppGLFW() { this->InitMainWindow(); }
|
||||
AppGLFW(std::unique_ptr<utils::log::ILog>& log) : _logger(log.get()) { this->InitMainWindow(); }
|
||||
AppGLFW(std::unique_ptr<utils::log::ILog>& log) : AppGLFW()
|
||||
{
|
||||
logger_ = log.get();
|
||||
if (logger_)
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
AppGLFW(std::unique_ptr<utils::log::ILog>& log, std::unique_ptr<pixelarium::resources::ImageResourcePool>& pool)
|
||||
: AppGLFW(log)
|
||||
{
|
||||
pool_ = pool.get();
|
||||
};
|
||||
int Run();
|
||||
|
||||
private:
|
||||
@@ -38,17 +57,18 @@ class AppGLFW
|
||||
|
||||
private:
|
||||
// LogLevelSelection log_level_ = static_cast<LogLevelSelection>(0);
|
||||
utils::log::ILog* _logger;
|
||||
utils::log::ILog* logger_;
|
||||
resources::ImageResourcePool* pool_;
|
||||
GLFWwindow* window = nullptr;
|
||||
ImGuiWindowFlags window_flags = 0;
|
||||
std::shared_ptr<pixelarium::imaging::Image> _img;
|
||||
pixelarium::render::CvMatRender _render;
|
||||
bool _imagep{false};
|
||||
ImVec2 _curr_dim;
|
||||
ImGuiWindowFlags window_flags_ = 0;
|
||||
std::shared_ptr<pixelarium::imaging::PixelariumImage> img_;
|
||||
pixelarium::render::CvMatRender render_;
|
||||
bool imagep_{false};
|
||||
ImVec2 curr_dim_;
|
||||
};
|
||||
|
||||
static void glfw_error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "GLFW Error %d: %s\n", error, description);
|
||||
}
|
||||
} // namespace pixelarium::ui
|
||||
} // namespace pixelarium::ui
|
||||
|
||||
+11
-8
@@ -2,25 +2,28 @@
|
||||
#include <memory>
|
||||
|
||||
#include "AppGLFW.hpp"
|
||||
#include "resources/resource.hpp"
|
||||
#include "uiresources.h"
|
||||
#include "utilities/ILog.hpp"
|
||||
#include "utilities/SpdLogger.hpp"
|
||||
#include "uiresources.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
using namespace pixelarium::utils::log;
|
||||
using namespace pixelarium;
|
||||
using namespace std;
|
||||
cout << "ok\n";
|
||||
unique_ptr<ILog> logger;
|
||||
unique_ptr<utils::log::ILog> logger;
|
||||
#ifdef _WIN32
|
||||
logger = make_unique<SpdLogger>(string(getenv("APPDATA")) + "/pixelarium/logfile.log", "default");
|
||||
logger = make_unique<utils::log::SpdLogger>(string(getenv("APPDATA")) + "/pixelarium/logfile.log", "default");
|
||||
#else
|
||||
logger = make_unique<SpdLogger>(std::string(getenv("HOME")) + "/.cache/pixelarium/log.log", "default");
|
||||
logger = make_unique<utils::log::SpdLogger>(std::string(getenv("HOME")) + "/.cache/pixelarium/log.log", "default");
|
||||
#endif
|
||||
logger->Info(std::format("{}: Starting Application {}", __FUNCTION__, PIXELARIUM_TITLE));
|
||||
|
||||
auto app = pixelarium::ui::AppGLFW(logger);
|
||||
logger->ChangeLevel(utils::log::LogLevel::Debug);
|
||||
auto image_pool{std::make_unique<resources::ImageResourcePool>()};
|
||||
|
||||
auto app = pixelarium::ui::AppGLFW(logger, image_pool);
|
||||
|
||||
logger->Info(std::format("Starting Application {}", PIXELARIUM_TITLE));
|
||||
logger->Error("Starting Application");
|
||||
return app.Run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user