Route layer panel view through app core
This commit is contained in:
@@ -315,6 +315,15 @@ struct PlanLayerMenuArgs {
|
||||
std::string lower_name = "Layer 0";
|
||||
};
|
||||
|
||||
struct PlanLayerPanelViewArgs {
|
||||
int layer_count = 2;
|
||||
int current_index = 0;
|
||||
int hidden_index = -1;
|
||||
int locked_index = -1;
|
||||
float current_opacity = 1.0F;
|
||||
int current_blend_mode = 0;
|
||||
};
|
||||
|
||||
struct PlanLayerMergeArgs {
|
||||
int layer_count = 2;
|
||||
int from_index = 1;
|
||||
@@ -1937,6 +1946,7 @@ void print_help()
|
||||
<< " plan-document-resize [--current-resolution N] [--selected-resolution-index N]\n"
|
||||
<< " plan-layer-rename --old-name NAME --new-name NAME\n"
|
||||
<< " plan-layer-menu --command clear|rename|merge [--no-current-layer] [--current-index N] [--animation-duration N] [--current-name NAME] [--lower-name NAME]\n"
|
||||
<< " plan-layer-panel-view [--layer-count N] [--current-index N] [--hidden-index N] [--locked-index N] [--current-opacity N] [--current-blend-mode N]\n"
|
||||
<< " plan-layer-merge [--layer-count N] [--from-index N] [--to-index N] [--animation-duration N] [--no-history]\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|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"
|
||||
@@ -4380,6 +4390,119 @@ int plan_layer_menu(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_layer_panel_view_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
PlanLayerPanelViewArgs& args)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
const std::string_view key(argv[i]);
|
||||
if (key == "--layer-count" || key == "--current-index" || key == "--hidden-index"
|
||||
|| key == "--locked-index" || key == "--current-blend-mode") {
|
||||
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 == "--current-index") {
|
||||
args.current_index = value.value();
|
||||
} else if (key == "--hidden-index") {
|
||||
args.hidden_index = value.value();
|
||||
} else if (key == "--locked-index") {
|
||||
args.locked_index = value.value();
|
||||
} else {
|
||||
args.current_blend_mode = value.value();
|
||||
}
|
||||
} else if (key == "--current-opacity") {
|
||||
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();
|
||||
}
|
||||
args.current_opacity = value.value();
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
int plan_layer_panel_view(int argc, char** argv)
|
||||
{
|
||||
PlanLayerPanelViewArgs args;
|
||||
const auto status = parse_plan_layer_panel_view_args(argc, argv, args);
|
||||
if (!status.ok()) {
|
||||
print_error("plan-layer-panel-view", status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::vector<pp::app::DocumentLayerPanelInput> 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) {
|
||||
layers.push_back(pp::app::DocumentLayerPanelInput {
|
||||
.layer_index = i,
|
||||
.name = "Layer " + std::to_string(i),
|
||||
.opacity = i == args.current_index ? args.current_opacity : 1.0F,
|
||||
.visible = i != args.hidden_index,
|
||||
.alpha_locked = i == args.locked_index,
|
||||
.blend_mode = i == args.current_index ? args.current_blend_mode : 0,
|
||||
});
|
||||
}
|
||||
|
||||
const auto view = pp::app::plan_document_layer_panel_view(layers, args.current_index);
|
||||
if (!view) {
|
||||
print_error("plan-layer-panel-view", view.status().message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
int visible_count = 0;
|
||||
int locked_count = 0;
|
||||
for (const auto& layer : view.value().layers) {
|
||||
if (layer.visible) {
|
||||
visible_count += 1;
|
||||
}
|
||||
if (layer.alpha_locked) {
|
||||
locked_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
const auto current_layer = std::find_if(
|
||||
view.value().layers.begin(),
|
||||
view.value().layers.end(),
|
||||
[](const pp::app::DocumentLayerPanelLayerView& layer) { return layer.current; });
|
||||
if (current_layer == view.value().layers.end()) {
|
||||
print_error("plan-layer-panel-view", "layer panel view did not include the current layer");
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::cout << "{\"ok\":true,\"command\":\"plan-layer-panel-view\""
|
||||
<< ",\"state\":{\"layerCount\":" << args.layer_count
|
||||
<< ",\"currentIndex\":" << args.current_index
|
||||
<< ",\"hiddenIndex\":" << args.hidden_index
|
||||
<< ",\"lockedIndex\":" << args.locked_index
|
||||
<< ",\"currentOpacity\":" << args.current_opacity
|
||||
<< ",\"currentBlendMode\":" << args.current_blend_mode
|
||||
<< "},\"view\":{\"layers\":" << view.value().layers.size()
|
||||
<< ",\"currentIndex\":" << view.value().current_index
|
||||
<< ",\"currentName\":\"" << json_escape(current_layer->name)
|
||||
<< "\",\"currentOpacity\":" << view.value().current_opacity
|
||||
<< ",\"currentAlphaLocked\":" << json_bool(view.value().current_alpha_locked)
|
||||
<< ",\"currentBlendMode\":" << view.value().current_blend_mode
|
||||
<< ",\"visibleLayers\":" << visible_count
|
||||
<< ",\"lockedLayers\":" << locked_count
|
||||
<< "}}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_layer_merge_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
@@ -9170,6 +9293,10 @@ int main(int argc, char** argv)
|
||||
return plan_layer_menu(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-layer-panel-view") {
|
||||
return plan_layer_panel_view(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-layer-merge") {
|
||||
return plan_layer_merge(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user