Add brush preset list executor bridge

This commit is contained in:
2026-06-04 15:25:54 +02:00
parent 47c35fb859
commit 0c7bc98d5b
7 changed files with 356 additions and 54 deletions

View File

@@ -201,6 +201,23 @@ public:
virtual void save_texture_list() = 0;
};
class BrushPresetListServices {
public:
virtual ~BrushPresetListServices() = default;
virtual pp::foundation::Status add_current_brush_preset(int target_index) = 0;
virtual void remove_brush_preset(
int current_index,
int target_index,
bool selects_target,
bool clears_selection) = 0;
virtual void move_brush_preset(int from_index, int to_index) = 0;
virtual void select_brush_preset(int index, bool notify_brush_changed) = 0;
virtual void clear_brush_presets(bool clears_selection) = 0;
virtual void update_preset_empty_notification() = 0;
virtual void save_preset_list() = 0;
};
class BrushStrokeControlServices {
public:
virtual ~BrushStrokeControlServices() = default;
@@ -763,4 +780,83 @@ public:
return pp::foundation::Status::invalid_argument("unknown brush texture list operation");
}
[[nodiscard]] inline pp::foundation::Status execute_brush_preset_list_plan(
const BrushPresetListPlan& plan,
BrushPresetListServices& services)
{
switch (plan.operation) {
case BrushPresetListOperation::add_current_brush:
{
if (plan.item_count < 0 || plan.target_index != plan.item_count) {
return pp::foundation::Status::out_of_range("brush preset add plan has invalid target");
}
const auto add_status = services.add_current_brush_preset(plan.target_index);
if (!add_status.ok()) {
return add_status;
}
if (plan.updates_empty_notification) {
services.update_preset_empty_notification();
}
if (plan.saves_list) {
services.save_preset_list();
}
return pp::foundation::Status::success();
}
case BrushPresetListOperation::remove_preset:
if (plan.item_count <= 0 || plan.current_index < 0 || plan.current_index >= plan.item_count) {
return pp::foundation::Status::out_of_range("brush preset remove plan has invalid selection");
}
if (plan.selects_target && (plan.target_index < 0 || plan.target_index >= plan.item_count - 1)) {
return pp::foundation::Status::out_of_range("brush preset remove plan has invalid target");
}
services.remove_brush_preset(
plan.current_index,
plan.target_index,
plan.selects_target,
plan.clears_selection);
if (plan.updates_empty_notification) {
services.update_preset_empty_notification();
}
if (plan.saves_list) {
services.save_preset_list();
}
return pp::foundation::Status::success();
case BrushPresetListOperation::move_preset:
if (plan.item_count <= 0 || plan.current_index < 0 || plan.current_index >= plan.item_count
|| plan.target_index < 0 || plan.target_index >= plan.item_count) {
return pp::foundation::Status::out_of_range("brush preset move plan has invalid indices");
}
services.move_brush_preset(plan.current_index, plan.target_index);
if (plan.saves_list) {
services.save_preset_list();
}
return pp::foundation::Status::success();
case BrushPresetListOperation::select_preset:
if (plan.item_count <= 0 || plan.target_index < 0 || plan.target_index >= plan.item_count) {
return pp::foundation::Status::out_of_range("brush preset select plan has invalid target");
}
services.select_brush_preset(plan.target_index, plan.notifies_brush_changed);
return pp::foundation::Status::success();
case BrushPresetListOperation::clear_presets:
if (plan.item_count < 0) {
return pp::foundation::Status::out_of_range("brush preset clear plan has invalid item count");
}
services.clear_brush_presets(plan.clears_selection);
if (plan.updates_empty_notification) {
services.update_preset_empty_notification();
}
if (plan.saves_list) {
services.save_preset_list();
}
return pp::foundation::Status::success();
}
return pp::foundation::Status::invalid_argument("unknown brush preset list operation");
}
} // namespace pp::app