Centralize legacy document canvas bridge
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include "app_core/document_resize.h"
|
||||
#include "app_core/document_export.h"
|
||||
#include "app_core/document_session.h"
|
||||
#include "legacy_document_canvas_services.h"
|
||||
#include "legacy_history_services.h"
|
||||
#include "settings.h"
|
||||
#include "node_dialog_open.h"
|
||||
#include "node_dialog_browse.h"
|
||||
@@ -282,7 +284,7 @@ void App::dialog_newdoc()
|
||||
canvas->m_canvas->m_layers.clear();
|
||||
canvas->m_canvas->resize(plan.resolution, plan.resolution);
|
||||
canvas->reset_camera();
|
||||
ActionManager::clear();
|
||||
pp::panopainter::clear_legacy_history();
|
||||
|
||||
layers->add_layer("Default", false, true);
|
||||
|
||||
@@ -622,33 +624,6 @@ void App::dialog_export_depth()
|
||||
|
||||
void App::dialog_resize()
|
||||
{
|
||||
class LegacyDocumentResizeServices final : public pp::app::DocumentResizeServices {
|
||||
public:
|
||||
explicit LegacyDocumentResizeServices(App& app) noexcept
|
||||
: app_(app)
|
||||
{
|
||||
}
|
||||
|
||||
void resize_document(int width, int height) override
|
||||
{
|
||||
if (app_.canvas)
|
||||
app_.canvas->m_canvas->resize(width, height);
|
||||
}
|
||||
|
||||
void update_title() override
|
||||
{
|
||||
app_.title_update();
|
||||
}
|
||||
|
||||
void clear_history() override
|
||||
{
|
||||
ActionManager::clear();
|
||||
}
|
||||
|
||||
private:
|
||||
App& app_;
|
||||
};
|
||||
|
||||
auto dialog = std::make_shared<NodeDialogResize>();
|
||||
dialog->set_manager(&layout);
|
||||
dialog->init();
|
||||
@@ -666,8 +641,7 @@ void App::dialog_resize()
|
||||
dialog->destroy();
|
||||
return;
|
||||
}
|
||||
LegacyDocumentResizeServices services(*this);
|
||||
const auto status = pp::app::execute_document_resize_plan(plan.value(), services);
|
||||
const auto status = pp::panopainter::execute_legacy_document_resize_plan(*this, plan.value());
|
||||
if (!status.ok())
|
||||
LOG("Document resize failed: %s", status.message);
|
||||
dialog->destroy();
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "app_core/app_status.h"
|
||||
#include "app_core/main_toolbar.h"
|
||||
#include "app_core/tools_menu.h"
|
||||
#include "legacy_document_canvas_services.h"
|
||||
#include "legacy_history_services.h"
|
||||
#include "settings.h"
|
||||
#include "serializer.h"
|
||||
@@ -140,33 +141,6 @@ bool apply_brush_preset_plan(App& app, const std::shared_ptr<Brush>& brush)
|
||||
return status.ok();
|
||||
}
|
||||
|
||||
class LegacyDocumentCanvasClearServices final : public pp::app::DocumentCanvasClearServices {
|
||||
public:
|
||||
explicit LegacyDocumentCanvasClearServices(App& app) noexcept
|
||||
: app_(app)
|
||||
{
|
||||
}
|
||||
|
||||
void clear_current_canvas(float r, float g, float b, float a) override
|
||||
{
|
||||
if (!app_.canvas || !app_.canvas->m_canvas)
|
||||
return;
|
||||
|
||||
app_.canvas->m_canvas->clear({ r, g, b, a });
|
||||
}
|
||||
|
||||
private:
|
||||
App& app_;
|
||||
};
|
||||
|
||||
void execute_document_canvas_clear_plan(App& app, const pp::app::DocumentCanvasClearPlan& plan)
|
||||
{
|
||||
LegacyDocumentCanvasClearServices services(app);
|
||||
const auto status = pp::app::execute_document_canvas_clear_plan(plan, services);
|
||||
if (!status.ok())
|
||||
LOG("Canvas clear failed: %s", status.message);
|
||||
}
|
||||
|
||||
void execute_document_layer_merge_plan(App& app, const pp::app::DocumentLayerMergePlan& plan);
|
||||
|
||||
bool apply_document_export_menu_plan(App& app, pp::app::DocumentExportMenuKind kind)
|
||||
@@ -420,7 +394,9 @@ public:
|
||||
|
||||
void clear_canvas(const pp::app::DocumentCanvasClearPlan& plan) override
|
||||
{
|
||||
execute_document_canvas_clear_plan(app_, plan);
|
||||
const auto status = pp::panopainter::execute_legacy_document_canvas_clear_plan(app_, plan);
|
||||
if (!status.ok())
|
||||
LOG("Canvas clear failed: %s", status.message);
|
||||
}
|
||||
|
||||
void show_message_box() override
|
||||
@@ -578,7 +554,9 @@ public:
|
||||
if (!plan)
|
||||
return;
|
||||
|
||||
execute_document_canvas_clear_plan(app_, plan.value());
|
||||
const auto status = pp::panopainter::execute_legacy_document_canvas_clear_plan(app_, plan.value());
|
||||
if (!status.ok())
|
||||
LOG("Canvas clear failed: %s", status.message);
|
||||
}
|
||||
|
||||
void show_rename_dialog() override
|
||||
|
||||
84
src/legacy_document_canvas_services.cpp
Normal file
84
src/legacy_document_canvas_services.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include "legacy_document_canvas_services.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "legacy_history_services.h"
|
||||
|
||||
namespace pp::panopainter {
|
||||
namespace {
|
||||
|
||||
class LegacyDocumentCanvasClearServices final : public pp::app::DocumentCanvasClearServices {
|
||||
public:
|
||||
explicit LegacyDocumentCanvasClearServices(App& app) noexcept
|
||||
: app_(app)
|
||||
{
|
||||
}
|
||||
|
||||
void clear_current_canvas(float r, float g, float b, float a) override
|
||||
{
|
||||
if (!legacy_document_canvas_available(app_)) {
|
||||
return;
|
||||
}
|
||||
|
||||
app_.canvas->m_canvas->clear({ r, g, b, a });
|
||||
}
|
||||
|
||||
private:
|
||||
App& app_;
|
||||
};
|
||||
|
||||
class LegacyDocumentResizeServices final : public pp::app::DocumentResizeServices {
|
||||
public:
|
||||
explicit LegacyDocumentResizeServices(App& app) noexcept
|
||||
: app_(app)
|
||||
{
|
||||
}
|
||||
|
||||
void resize_document(int width, int height) override
|
||||
{
|
||||
if (!legacy_document_canvas_available(app_)) {
|
||||
return;
|
||||
}
|
||||
|
||||
app_.canvas->m_canvas->resize(width, height);
|
||||
}
|
||||
|
||||
void update_title() override
|
||||
{
|
||||
app_.title_update();
|
||||
}
|
||||
|
||||
void clear_history() override
|
||||
{
|
||||
clear_legacy_history();
|
||||
}
|
||||
|
||||
private:
|
||||
App& app_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
bool legacy_document_canvas_available(const App& app) noexcept
|
||||
{
|
||||
return app.canvas != nullptr && app.canvas->m_canvas != nullptr;
|
||||
}
|
||||
|
||||
pp::foundation::Status execute_legacy_document_canvas_clear_plan(
|
||||
App& app,
|
||||
const pp::app::DocumentCanvasClearPlan& plan)
|
||||
{
|
||||
LegacyDocumentCanvasClearServices services(app);
|
||||
return pp::app::execute_document_canvas_clear_plan(plan, services);
|
||||
}
|
||||
|
||||
pp::foundation::Status execute_legacy_document_resize_plan(
|
||||
App& app,
|
||||
const pp::app::DocumentResizePlan& plan)
|
||||
{
|
||||
LegacyDocumentResizeServices services(app);
|
||||
return pp::app::execute_document_resize_plan(plan, services);
|
||||
}
|
||||
|
||||
} // namespace pp::panopainter
|
||||
19
src/legacy_document_canvas_services.h
Normal file
19
src/legacy_document_canvas_services.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_core/document_canvas.h"
|
||||
#include "app_core/document_resize.h"
|
||||
#include "foundation/result.h"
|
||||
|
||||
class App;
|
||||
|
||||
namespace pp::panopainter {
|
||||
|
||||
[[nodiscard]] bool legacy_document_canvas_available(const App& app) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status execute_legacy_document_canvas_clear_plan(
|
||||
App& app,
|
||||
const pp::app::DocumentCanvasClearPlan& plan);
|
||||
[[nodiscard]] pp::foundation::Status execute_legacy_document_resize_plan(
|
||||
App& app,
|
||||
const pp::app::DocumentResizePlan& plan);
|
||||
|
||||
} // namespace pp::panopainter
|
||||
Reference in New Issue
Block a user