Centralize legacy brush UI bridge
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include "app_core/main_toolbar.h"
|
||||
#include "app_core/tools_menu.h"
|
||||
#include "legacy_app_shell_services.h"
|
||||
#include "legacy_brush_ui_services.h"
|
||||
#include "legacy_canvas_tool_services.h"
|
||||
#include "legacy_document_layer_services.h"
|
||||
#include "legacy_history_services.h"
|
||||
@@ -31,115 +32,19 @@
|
||||
|
||||
namespace {
|
||||
|
||||
class LegacyBrushUiServices final : public pp::app::BrushUiServices {
|
||||
public:
|
||||
LegacyBrushUiServices(
|
||||
App& app,
|
||||
bool update_quick = false,
|
||||
bool update_color_panel = false,
|
||||
const std::shared_ptr<Brush>& preset_brush = nullptr) noexcept
|
||||
: app_(app)
|
||||
, update_quick_(update_quick)
|
||||
, update_color_panel_(update_color_panel)
|
||||
, preset_brush_(preset_brush)
|
||||
{
|
||||
}
|
||||
|
||||
void set_tip_color(float r, float g, float b, float a) override
|
||||
{
|
||||
if (!Canvas::I || !Canvas::I->m_current_brush)
|
||||
return;
|
||||
|
||||
Canvas::I->m_current_brush->m_tip_color = glm::vec4(r, g, b, a);
|
||||
if (update_quick_ && app_.quick)
|
||||
app_.quick->set_color(Canvas::I->m_current_brush->m_tip_color);
|
||||
if (update_color_panel_ && app_.color)
|
||||
app_.color->set_color(Canvas::I->m_current_brush->m_tip_color);
|
||||
}
|
||||
|
||||
void set_texture(
|
||||
pp::app::BrushUiTextureSlot slot,
|
||||
std::string_view path,
|
||||
std::string_view thumbnail_path) override
|
||||
{
|
||||
if (!Canvas::I || !Canvas::I->m_current_brush)
|
||||
return;
|
||||
|
||||
const std::string texture_path(path);
|
||||
const std::string thumbnail(thumbnail_path);
|
||||
switch (slot)
|
||||
{
|
||||
case pp::app::BrushUiTextureSlot::tip:
|
||||
Canvas::I->m_current_brush->load_tip(texture_path, thumbnail);
|
||||
break;
|
||||
case pp::app::BrushUiTextureSlot::pattern:
|
||||
Canvas::I->m_current_brush->load_pattern(texture_path, thumbnail);
|
||||
break;
|
||||
case pp::app::BrushUiTextureSlot::dual:
|
||||
Canvas::I->m_current_brush->load_dual(texture_path, thumbnail);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void replace_brush_from_preset(bool preserve_existing_color, bool load_resources) override
|
||||
{
|
||||
if (!Canvas::I || !Canvas::I->m_current_brush || !preset_brush_)
|
||||
return;
|
||||
|
||||
const auto color = Canvas::I->m_current_brush->m_tip_color;
|
||||
*Canvas::I->m_current_brush = *preset_brush_;
|
||||
if (preserve_existing_color)
|
||||
Canvas::I->m_current_brush->m_tip_color = color;
|
||||
if (load_resources)
|
||||
Canvas::I->m_current_brush->load();
|
||||
}
|
||||
|
||||
void refresh_brush_ui(bool update_color_ui, bool update_brush_ui) override
|
||||
{
|
||||
app_.brush_update(update_color_ui, update_brush_ui);
|
||||
}
|
||||
|
||||
private:
|
||||
App& app_;
|
||||
bool update_quick_ = false;
|
||||
bool update_color_panel_ = false;
|
||||
std::shared_ptr<Brush> preset_brush_;
|
||||
};
|
||||
|
||||
bool apply_brush_color_plan(App& app, glm::vec4 color, bool update_quick, bool update_color_panel)
|
||||
{
|
||||
const auto plan = pp::app::plan_brush_ui_color(color.r, color.g, color.b, color.a);
|
||||
if (!plan)
|
||||
return false;
|
||||
LegacyBrushUiServices services(app, update_quick, update_color_panel);
|
||||
const auto status = pp::app::execute_brush_ui_plan(plan.value(), services);
|
||||
if (!status.ok())
|
||||
LOG("Brush color action failed: %s", status.message);
|
||||
return status.ok();
|
||||
return pp::panopainter::apply_legacy_brush_color_plan(app, color, update_quick, update_color_panel);
|
||||
}
|
||||
|
||||
bool apply_brush_texture_plan(pp::app::BrushUiTextureSlot slot, const std::string& path, const std::string& thumb)
|
||||
bool apply_brush_texture_plan(App& app, pp::app::BrushUiTextureSlot slot, const std::string& path, const std::string& thumb)
|
||||
{
|
||||
const auto plan = pp::app::plan_brush_ui_texture(slot, path, thumb);
|
||||
if (!plan)
|
||||
return false;
|
||||
LegacyBrushUiServices services(*App::I);
|
||||
const auto status = pp::app::execute_brush_ui_plan(plan.value(), services);
|
||||
if (!status.ok())
|
||||
LOG("Brush texture action failed: %s", status.message);
|
||||
return status.ok();
|
||||
return pp::panopainter::apply_legacy_brush_texture_plan(app, slot, path, thumb);
|
||||
}
|
||||
|
||||
bool apply_brush_preset_plan(App& app, const std::shared_ptr<Brush>& brush)
|
||||
{
|
||||
const auto plan = pp::app::plan_brush_ui_preset_replace(static_cast<bool>(brush));
|
||||
if (!plan)
|
||||
return false;
|
||||
LegacyBrushUiServices services(app, false, false, brush);
|
||||
const auto status = pp::app::execute_brush_ui_plan(plan.value(), services);
|
||||
if (!status.ok())
|
||||
LOG("Brush preset action failed: %s", status.message);
|
||||
return status.ok();
|
||||
return pp::panopainter::apply_legacy_brush_preset_plan(app, brush);
|
||||
}
|
||||
|
||||
bool apply_document_export_menu_plan(App& app, pp::app::DocumentExportMenuKind kind)
|
||||
@@ -410,18 +315,16 @@ void App::init_sidebar()
|
||||
};
|
||||
|
||||
stroke->on_brush_changed = [this](Node* target, const std::string& path, const std::string& thumb) {
|
||||
apply_brush_texture_plan(pp::app::BrushUiTextureSlot::tip, path, thumb);
|
||||
apply_brush_texture_plan(*this, pp::app::BrushUiTextureSlot::tip, path, thumb);
|
||||
};
|
||||
stroke->on_pattern_changed = [this](Node*target, const std::string& path, const std::string& thumb) {
|
||||
apply_brush_texture_plan(pp::app::BrushUiTextureSlot::pattern, path, thumb);
|
||||
apply_brush_texture_plan(*this, pp::app::BrushUiTextureSlot::pattern, path, thumb);
|
||||
};
|
||||
stroke->on_dual_changed = [this](Node*target, const std::string& path, const std::string& thumb) {
|
||||
apply_brush_texture_plan(pp::app::BrushUiTextureSlot::dual, path, thumb);
|
||||
apply_brush_texture_plan(*this, pp::app::BrushUiTextureSlot::dual, path, thumb);
|
||||
};
|
||||
stroke->on_stroke_change = [this](Node*) {
|
||||
const auto plan = pp::app::plan_brush_ui_stroke_settings_changed();
|
||||
LegacyBrushUiServices services(*this);
|
||||
const auto status = pp::app::execute_brush_ui_plan(plan, services);
|
||||
const auto status = pp::panopainter::execute_legacy_brush_stroke_changed_plan(*this);
|
||||
if (!status.ok())
|
||||
LOG("Brush stroke settings action failed: %s", status.message);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user