Route brush preset list planning
This commit is contained in:
@@ -28,6 +28,14 @@ enum class BrushTextureListOperation {
|
||||
move_texture,
|
||||
};
|
||||
|
||||
enum class BrushPresetListOperation {
|
||||
add_current_brush,
|
||||
remove_preset,
|
||||
move_preset,
|
||||
select_preset,
|
||||
clear_presets,
|
||||
};
|
||||
|
||||
enum class BrushStrokeControlOperation {
|
||||
set_float,
|
||||
set_bool,
|
||||
@@ -139,6 +147,20 @@ struct BrushTextureListPlan {
|
||||
bool no_op = false;
|
||||
};
|
||||
|
||||
struct BrushPresetListPlan {
|
||||
BrushPresetListOperation operation = BrushPresetListOperation::select_preset;
|
||||
int item_count = 0;
|
||||
int current_index = -1;
|
||||
int target_index = -1;
|
||||
int move_offset = 0;
|
||||
bool saves_list = false;
|
||||
bool updates_empty_notification = false;
|
||||
bool selects_target = false;
|
||||
bool clears_selection = false;
|
||||
bool notifies_brush_changed = false;
|
||||
bool no_op = false;
|
||||
};
|
||||
|
||||
struct BrushStrokeControlPlan {
|
||||
BrushStrokeControlOperation operation = BrushStrokeControlOperation::set_float;
|
||||
BrushStrokeFloatSetting float_setting = BrushStrokeFloatSetting::tip_size;
|
||||
@@ -474,6 +496,122 @@ public:
|
||||
return pp::foundation::Result<BrushTextureListPlan>::success(plan);
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Result<BrushPresetListPlan> plan_brush_preset_list_add(
|
||||
int item_count,
|
||||
bool has_current_brush)
|
||||
{
|
||||
if (item_count < 0) {
|
||||
return pp::foundation::Result<BrushPresetListPlan>::failure(
|
||||
pp::foundation::Status::out_of_range("brush preset item count must not be negative"));
|
||||
}
|
||||
if (!has_current_brush) {
|
||||
return pp::foundation::Result<BrushPresetListPlan>::failure(
|
||||
pp::foundation::Status::invalid_argument("current brush must be available to add a preset"));
|
||||
}
|
||||
|
||||
BrushPresetListPlan plan;
|
||||
plan.operation = BrushPresetListOperation::add_current_brush;
|
||||
plan.item_count = item_count;
|
||||
plan.target_index = item_count;
|
||||
plan.saves_list = true;
|
||||
plan.updates_empty_notification = true;
|
||||
return pp::foundation::Result<BrushPresetListPlan>::success(plan);
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Result<BrushPresetListPlan> plan_brush_preset_list_remove(
|
||||
int item_count,
|
||||
int current_index)
|
||||
{
|
||||
if (item_count <= 0) {
|
||||
return pp::foundation::Result<BrushPresetListPlan>::failure(
|
||||
pp::foundation::Status::invalid_argument("brush preset list must contain an item to remove"));
|
||||
}
|
||||
if (current_index < 0 || current_index >= item_count) {
|
||||
return pp::foundation::Result<BrushPresetListPlan>::failure(
|
||||
pp::foundation::Status::out_of_range("selected brush preset index is outside the list"));
|
||||
}
|
||||
|
||||
BrushPresetListPlan plan;
|
||||
plan.operation = BrushPresetListOperation::remove_preset;
|
||||
plan.item_count = item_count;
|
||||
plan.current_index = current_index;
|
||||
plan.target_index = item_count > 1 ? std::min(current_index, item_count - 2) : -1;
|
||||
plan.saves_list = true;
|
||||
plan.updates_empty_notification = true;
|
||||
plan.selects_target = plan.target_index >= 0;
|
||||
plan.clears_selection = plan.target_index < 0;
|
||||
return pp::foundation::Result<BrushPresetListPlan>::success(plan);
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Result<BrushPresetListPlan> plan_brush_preset_list_move(
|
||||
int item_count,
|
||||
int current_index,
|
||||
int offset)
|
||||
{
|
||||
if (item_count <= 0) {
|
||||
return pp::foundation::Result<BrushPresetListPlan>::failure(
|
||||
pp::foundation::Status::invalid_argument("brush preset list must contain an item to move"));
|
||||
}
|
||||
if (current_index < 0 || current_index >= item_count) {
|
||||
return pp::foundation::Result<BrushPresetListPlan>::failure(
|
||||
pp::foundation::Status::out_of_range("selected brush preset index is outside the list"));
|
||||
}
|
||||
if (offset == 0) {
|
||||
return pp::foundation::Result<BrushPresetListPlan>::failure(
|
||||
pp::foundation::Status::invalid_argument("brush preset move offset must not be zero"));
|
||||
}
|
||||
|
||||
BrushPresetListPlan plan;
|
||||
plan.operation = BrushPresetListOperation::move_preset;
|
||||
plan.item_count = item_count;
|
||||
plan.current_index = current_index;
|
||||
plan.target_index = std::clamp(current_index + offset, 0, item_count - 1);
|
||||
plan.move_offset = offset;
|
||||
plan.saves_list = true;
|
||||
plan.no_op = plan.target_index == current_index;
|
||||
return pp::foundation::Result<BrushPresetListPlan>::success(plan);
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Result<BrushPresetListPlan> plan_brush_preset_list_select(
|
||||
int item_count,
|
||||
int index)
|
||||
{
|
||||
if (item_count <= 0) {
|
||||
return pp::foundation::Result<BrushPresetListPlan>::failure(
|
||||
pp::foundation::Status::invalid_argument("brush preset list must contain an item to select"));
|
||||
}
|
||||
if (index < 0 || index >= item_count) {
|
||||
return pp::foundation::Result<BrushPresetListPlan>::failure(
|
||||
pp::foundation::Status::out_of_range("selected brush preset index is outside the list"));
|
||||
}
|
||||
|
||||
BrushPresetListPlan plan;
|
||||
plan.operation = BrushPresetListOperation::select_preset;
|
||||
plan.item_count = item_count;
|
||||
plan.current_index = index;
|
||||
plan.target_index = index;
|
||||
plan.selects_target = true;
|
||||
plan.notifies_brush_changed = true;
|
||||
return pp::foundation::Result<BrushPresetListPlan>::success(plan);
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Result<BrushPresetListPlan> plan_brush_preset_list_clear(int item_count)
|
||||
{
|
||||
if (item_count < 0) {
|
||||
return pp::foundation::Result<BrushPresetListPlan>::failure(
|
||||
pp::foundation::Status::out_of_range("brush preset item count must not be negative"));
|
||||
}
|
||||
|
||||
BrushPresetListPlan plan;
|
||||
plan.operation = BrushPresetListOperation::clear_presets;
|
||||
plan.item_count = item_count;
|
||||
plan.saves_list = true;
|
||||
plan.updates_empty_notification = true;
|
||||
plan.clears_selection = true;
|
||||
plan.no_op = item_count == 0;
|
||||
return pp::foundation::Result<BrushPresetListPlan>::success(plan);
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Status execute_brush_ui_plan(
|
||||
const BrushUiPlan& plan,
|
||||
BrushUiServices& services)
|
||||
|
||||
Reference in New Issue
Block a user