Extract brush UI operation planning
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "app_core/app_preferences.h"
|
||||
#include "app_core/app_status.h"
|
||||
#include "app_core/brush_ui.h"
|
||||
#include "app_core/document_animation.h"
|
||||
#include "app_core/document_export.h"
|
||||
#include "app_core/document_cloud.h"
|
||||
@@ -251,6 +252,17 @@ struct PlanAnimationOperationArgs {
|
||||
int onion_size = 1;
|
||||
};
|
||||
|
||||
struct PlanBrushOperationArgs {
|
||||
std::string kind = "settings";
|
||||
std::string path;
|
||||
std::string thumbnail_path;
|
||||
float r = 1.0F;
|
||||
float g = 1.0F;
|
||||
float b = 1.0F;
|
||||
float a = 1.0F;
|
||||
bool has_brush = true;
|
||||
};
|
||||
|
||||
struct SimulateAppSessionArgs {
|
||||
bool has_canvas = true;
|
||||
bool new_document = false;
|
||||
@@ -550,6 +562,36 @@ const char* document_animation_operation_name(pp::app::DocumentAnimationOperatio
|
||||
return "goto-frame";
|
||||
}
|
||||
|
||||
const char* brush_ui_texture_slot_name(pp::app::BrushUiTextureSlot slot) noexcept
|
||||
{
|
||||
switch (slot) {
|
||||
case pp::app::BrushUiTextureSlot::tip:
|
||||
return "tip";
|
||||
case pp::app::BrushUiTextureSlot::pattern:
|
||||
return "pattern";
|
||||
case pp::app::BrushUiTextureSlot::dual:
|
||||
return "dual";
|
||||
}
|
||||
|
||||
return "tip";
|
||||
}
|
||||
|
||||
const char* brush_ui_operation_name(pp::app::BrushUiOperation operation) noexcept
|
||||
{
|
||||
switch (operation) {
|
||||
case pp::app::BrushUiOperation::set_tip_color:
|
||||
return "set-tip-color";
|
||||
case pp::app::BrushUiOperation::set_texture:
|
||||
return "set-texture";
|
||||
case pp::app::BrushUiOperation::replace_brush_from_preset:
|
||||
return "replace-brush-from-preset";
|
||||
case pp::app::BrushUiOperation::stroke_settings_changed:
|
||||
return "stroke-settings-changed";
|
||||
}
|
||||
|
||||
return "stroke-settings-changed";
|
||||
}
|
||||
|
||||
const char* document_file_write_decision_name(pp::app::DocumentFileWriteDecision decision) noexcept
|
||||
{
|
||||
switch (decision) {
|
||||
@@ -804,6 +846,7 @@ void print_help()
|
||||
<< " plan-layer-rename --old-name NAME --new-name NAME\n"
|
||||
<< " plan-layer-operation --kind add|duplicate|select|reorder|remove|opacity|visibility|alpha-lock|blend-mode|highlight [--layer-count N] [--index N] [--from-index N] [--to-index N] [--source-index N] [--name NAME] [--opacity N] [--blend-mode N] [--enabled]\n"
|
||||
<< " plan-animation-operation --kind add|duplicate|remove|duration|move|goto|next|prev|onion [--frame-count N] [--total-duration N] [--current-frame N] [--selected-frame N] [--current-duration N] [--delta N] [--offset N] [--onion-size N]\n"
|
||||
<< " plan-brush-operation --kind color|tip|pattern|dual|preset|settings [--path FILE] [--thumb FILE] [--r N] [--g N] [--b N] [--a N] [--no-brush]\n"
|
||||
<< " plan-share-file [--path FILE]\n"
|
||||
<< " plan-picked-path [--path FILE]\n"
|
||||
<< " plan-display-file [--path FILE]\n"
|
||||
@@ -2719,6 +2762,129 @@ int plan_animation_operation(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_brush_operation_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
PlanBrushOperationArgs& args)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
const std::string_view key(argv[i]);
|
||||
if (key == "--kind" || key == "--path" || key == "--thumb") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
if (key == "--kind") {
|
||||
args.kind = argv[++i];
|
||||
} else if (key == "--path") {
|
||||
args.path = argv[++i];
|
||||
} else {
|
||||
args.thumbnail_path = argv[++i];
|
||||
}
|
||||
} else if (key == "--r" || key == "--g" || key == "--b" || key == "--a") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
const auto value = parse_float_arg(argv[++i]);
|
||||
if (!value) {
|
||||
return value.status();
|
||||
}
|
||||
if (key == "--r") {
|
||||
args.r = value.value();
|
||||
} else if (key == "--g") {
|
||||
args.g = value.value();
|
||||
} else if (key == "--b") {
|
||||
args.b = value.value();
|
||||
} else {
|
||||
args.a = value.value();
|
||||
}
|
||||
} else if (key == "--no-brush") {
|
||||
args.has_brush = false;
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Result<pp::app::BrushUiPlan> make_brush_operation_plan(
|
||||
const PlanBrushOperationArgs& args)
|
||||
{
|
||||
if (args.kind == "color") {
|
||||
return pp::app::plan_brush_ui_color(args.r, args.g, args.b, args.a);
|
||||
}
|
||||
if (args.kind == "tip") {
|
||||
return pp::app::plan_brush_ui_texture(
|
||||
pp::app::BrushUiTextureSlot::tip,
|
||||
args.path,
|
||||
args.thumbnail_path);
|
||||
}
|
||||
if (args.kind == "pattern") {
|
||||
return pp::app::plan_brush_ui_texture(
|
||||
pp::app::BrushUiTextureSlot::pattern,
|
||||
args.path,
|
||||
args.thumbnail_path);
|
||||
}
|
||||
if (args.kind == "dual") {
|
||||
return pp::app::plan_brush_ui_texture(
|
||||
pp::app::BrushUiTextureSlot::dual,
|
||||
args.path,
|
||||
args.thumbnail_path);
|
||||
}
|
||||
if (args.kind == "preset") {
|
||||
return pp::app::plan_brush_ui_preset_replace(args.has_brush);
|
||||
}
|
||||
if (args.kind == "settings") {
|
||||
return pp::foundation::Result<pp::app::BrushUiPlan>::success(
|
||||
pp::app::plan_brush_ui_stroke_settings_changed());
|
||||
}
|
||||
|
||||
return pp::foundation::Result<pp::app::BrushUiPlan>::failure(
|
||||
pp::foundation::Status::invalid_argument("unknown brush operation kind"));
|
||||
}
|
||||
|
||||
int plan_brush_operation(int argc, char** argv)
|
||||
{
|
||||
PlanBrushOperationArgs args;
|
||||
const auto status = parse_plan_brush_operation_args(argc, argv, args);
|
||||
if (!status.ok()) {
|
||||
print_error("plan-brush-operation", status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto plan = make_brush_operation_plan(args);
|
||||
if (!plan) {
|
||||
print_error("plan-brush-operation", plan.status().message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto& value = plan.value();
|
||||
std::cout << "{\"ok\":true,\"command\":\"plan-brush-operation\""
|
||||
<< ",\"state\":{\"kind\":\"" << json_escape(args.kind)
|
||||
<< "\",\"path\":\"" << json_escape(args.path)
|
||||
<< "\",\"thumb\":\"" << json_escape(args.thumbnail_path)
|
||||
<< "\",\"r\":" << args.r
|
||||
<< ",\"g\":" << args.g
|
||||
<< ",\"b\":" << args.b
|
||||
<< ",\"a\":" << args.a
|
||||
<< ",\"hasBrush\":" << json_bool(args.has_brush)
|
||||
<< "},\"plan\":{\"operation\":\"" << brush_ui_operation_name(value.operation)
|
||||
<< "\",\"textureSlot\":\"" << brush_ui_texture_slot_name(value.texture_slot)
|
||||
<< "\",\"path\":\"" << json_escape(value.path)
|
||||
<< "\",\"thumb\":\"" << json_escape(value.thumbnail_path)
|
||||
<< "\",\"r\":" << value.r
|
||||
<< ",\"g\":" << value.g
|
||||
<< ",\"b\":" << value.b
|
||||
<< ",\"a\":" << value.a
|
||||
<< ",\"mutatesBrush\":" << json_bool(value.mutates_brush)
|
||||
<< ",\"preservesExistingColor\":" << json_bool(value.preserves_existing_color)
|
||||
<< ",\"loadsBrushResources\":" << json_bool(value.loads_brush_resources)
|
||||
<< ",\"updateColorUi\":" << json_bool(value.update_color_ui)
|
||||
<< ",\"updateBrushUi\":" << json_bool(value.update_brush_ui)
|
||||
<< "}}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_share_file_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
@@ -5135,6 +5301,10 @@ int main(int argc, char** argv)
|
||||
return plan_animation_operation(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-brush-operation") {
|
||||
return plan_brush_operation(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-share-file") {
|
||||
return plan_share_file(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user