Route animation panel view through app core
This commit is contained in:
@@ -346,6 +346,19 @@ struct PlanAnimationPanelActionArgs {
|
||||
bool playback_active = false;
|
||||
};
|
||||
|
||||
struct PlanAnimationPanelViewArgs {
|
||||
int layer_count = 2;
|
||||
int frame_count = 2;
|
||||
int frame_duration = 1;
|
||||
int total_duration = 2;
|
||||
int current_layer = 0;
|
||||
int current_frame = 0;
|
||||
std::uint32_t selected_layer_id = 10;
|
||||
int selected_frame = 0;
|
||||
int onion_size = 1;
|
||||
int hidden_layer = -1;
|
||||
};
|
||||
|
||||
struct PlanAnimationTimelineScrubArgs {
|
||||
int total_duration = 1;
|
||||
float cursor_x = 0.0F;
|
||||
@@ -1928,6 +1941,7 @@ void print_help()
|
||||
<< " 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|select|goto|next|prev|playback|toggle-playback|onion [--frame-count N] [--total-duration N] [--current-frame N] [--selected-frame N] [--layer-index N] [--layer-id N] [--current-duration N] [--delta N] [--offset N] [--onion-size N] [--playing]\n"
|
||||
<< " plan-animation-panel-action --action goto|next|prev|playback|toggle-playback [--total-duration N] [--current-frame N] [--target-frame N] [--playing]\n"
|
||||
<< " plan-animation-panel-view [--layer-count N] [--frame-count N] [--frame-duration N] [--total-duration N] [--current-layer N] [--current-frame N] [--selected-layer-id N] [--selected-frame N] [--onion-size N] [--hidden-layer N]\n"
|
||||
<< " plan-animation-timeline-scrub [--total-duration N] [--cursor-x N] [--frame-width 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-brush-texture-list --kind add|remove|move [--dir NAME] [--data-path DIR] [--source FILE] [--item-count N] [--current-index N] [--offset N] [--user-texture]\n"
|
||||
@@ -4834,6 +4848,133 @@ int plan_animation_panel_action(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_animation_panel_view_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
PlanAnimationPanelViewArgs& args)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
const std::string_view key(argv[i]);
|
||||
if (key == "--layer-count" || key == "--frame-count" || key == "--frame-duration"
|
||||
|| key == "--total-duration" || key == "--current-layer" || key == "--current-frame"
|
||||
|| key == "--selected-layer-id" || key == "--selected-frame" || key == "--onion-size"
|
||||
|| key == "--hidden-layer") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
const auto value = parse_i32_arg(argv[++i]);
|
||||
if (!value) {
|
||||
return value.status();
|
||||
}
|
||||
if (key == "--layer-count") {
|
||||
args.layer_count = value.value();
|
||||
} else if (key == "--frame-count") {
|
||||
args.frame_count = value.value();
|
||||
} else if (key == "--frame-duration") {
|
||||
args.frame_duration = value.value();
|
||||
} else if (key == "--total-duration") {
|
||||
args.total_duration = value.value();
|
||||
} else if (key == "--current-layer") {
|
||||
args.current_layer = value.value();
|
||||
} else if (key == "--current-frame") {
|
||||
args.current_frame = value.value();
|
||||
} else if (key == "--selected-layer-id") {
|
||||
if (value.value() < 0) {
|
||||
return pp::foundation::Status::out_of_range("selected animation layer id must not be negative");
|
||||
}
|
||||
args.selected_layer_id = static_cast<std::uint32_t>(value.value());
|
||||
} else if (key == "--selected-frame") {
|
||||
args.selected_frame = value.value();
|
||||
} else if (key == "--onion-size") {
|
||||
args.onion_size = value.value();
|
||||
} else {
|
||||
args.hidden_layer = value.value();
|
||||
}
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
int plan_animation_panel_view(int argc, char** argv)
|
||||
{
|
||||
PlanAnimationPanelViewArgs args;
|
||||
const auto status = parse_plan_animation_panel_view_args(argc, argv, args);
|
||||
if (!status.ok()) {
|
||||
print_error("plan-animation-panel-view", status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::vector<pp::app::DocumentAnimationLayerInput> layers;
|
||||
if (args.layer_count > 0) {
|
||||
layers.reserve(static_cast<std::size_t>(args.layer_count));
|
||||
}
|
||||
for (int i = 0; i < args.layer_count; ++i) {
|
||||
pp::app::DocumentAnimationLayerInput layer;
|
||||
layer.layer_index = i;
|
||||
layer.layer_id = static_cast<std::uint32_t>((i + 1) * 10);
|
||||
layer.name = "Layer " + std::to_string(i);
|
||||
layer.visible = i != args.hidden_layer;
|
||||
if (args.frame_count > 0) {
|
||||
layer.frame_durations.assign(static_cast<std::size_t>(args.frame_count), args.frame_duration);
|
||||
}
|
||||
layers.push_back(std::move(layer));
|
||||
}
|
||||
|
||||
const auto view = pp::app::plan_animation_panel_view(
|
||||
layers,
|
||||
args.total_duration,
|
||||
args.current_layer,
|
||||
args.current_frame,
|
||||
args.selected_layer_id,
|
||||
args.selected_frame,
|
||||
args.onion_size);
|
||||
if (!view) {
|
||||
print_error("plan-animation-panel-view", view.status().message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto& value = view.value();
|
||||
int selected_count = 0;
|
||||
int visible_count = 0;
|
||||
for (const auto& layer : value.layers) {
|
||||
if (layer.visible) {
|
||||
visible_count += 1;
|
||||
}
|
||||
for (const auto& frame : layer.frames) {
|
||||
if (frame.selected) {
|
||||
selected_count += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "{\"ok\":true,\"command\":\"plan-animation-panel-view\""
|
||||
<< ",\"state\":{\"layerCount\":" << args.layer_count
|
||||
<< ",\"frameCount\":" << args.frame_count
|
||||
<< ",\"frameDuration\":" << args.frame_duration
|
||||
<< ",\"totalDuration\":" << args.total_duration
|
||||
<< ",\"currentLayer\":" << args.current_layer
|
||||
<< ",\"currentFrame\":" << args.current_frame
|
||||
<< ",\"selectedLayerId\":" << args.selected_layer_id
|
||||
<< ",\"selectedFrame\":" << args.selected_frame
|
||||
<< ",\"onionSize\":" << args.onion_size
|
||||
<< ",\"hiddenLayer\":" << args.hidden_layer
|
||||
<< "},\"view\":{\"totalDuration\":" << value.total_duration
|
||||
<< ",\"currentFrame\":" << value.current_frame
|
||||
<< ",\"onionSize\":" << value.onion_size
|
||||
<< ",\"layers\":" << value.layers.size()
|
||||
<< ",\"visibleLayers\":" << visible_count
|
||||
<< ",\"selectedFrames\":" << selected_count
|
||||
<< ",\"hasSelectedFrame\":" << json_bool(value.has_selected_frame)
|
||||
<< ",\"currentLayerId\":" << value.layers[static_cast<std::size_t>(args.current_layer)].layer_id
|
||||
<< ",\"firstLayerName\":\"" << json_escape(value.layers.front().name)
|
||||
<< "\",\"firstLayerFrames\":" << value.layers.front().frames.size()
|
||||
<< "}}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_animation_timeline_scrub_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
@@ -9045,6 +9186,10 @@ int main(int argc, char** argv)
|
||||
return plan_animation_panel_action(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-animation-panel-view") {
|
||||
return plan_animation_panel_view(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-animation-timeline-scrub") {
|
||||
return plan_animation_timeline_scrub(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user