Extract document resize planning
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "app_core/document_cloud.h"
|
||||
#include "app_core/document_platform_io.h"
|
||||
#include "app_core/document_recording.h"
|
||||
#include "app_core/document_resize.h"
|
||||
#include "app_core/document_route.h"
|
||||
#include "app_core/document_sharing.h"
|
||||
#include "app_core/document_session.h"
|
||||
@@ -213,6 +214,11 @@ struct PlanAppStatusArgs {
|
||||
std::uint32_t encoded_frames = 0;
|
||||
};
|
||||
|
||||
struct PlanDocumentResizeArgs {
|
||||
int current_resolution = 512;
|
||||
int selected_resolution_index = 0;
|
||||
};
|
||||
|
||||
struct SimulateAppSessionArgs {
|
||||
bool has_canvas = true;
|
||||
bool new_document = false;
|
||||
@@ -682,6 +688,7 @@ void print_help()
|
||||
<< " plan-recording-session [--running] [--frame-count N] [--platform-deletes-recorded-files]\n"
|
||||
<< " plan-app-preferences [--ui-scale N] [--display-density N] [--current-scale N] [--scale-option N] [--viewport-scale N] [--rtl] [--timelapse-disabled] [--recording-running] [--vr-controllers-disabled] [--cursor-mode N]\n"
|
||||
<< " plan-app-status [--doc-name NAME] [--unsaved] [--resolution N] [--resolution-index N] [--zoom N] [--history-bytes N] [--recording-running] [--encoder-available] [--encoded-frames N]\n"
|
||||
<< " plan-document-resize [--current-resolution N] [--selected-resolution-index N]\n"
|
||||
<< " plan-share-file [--path FILE]\n"
|
||||
<< " plan-picked-path [--path FILE]\n"
|
||||
<< " plan-display-file [--path FILE]\n"
|
||||
@@ -2219,6 +2226,63 @@ int plan_app_status(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_document_resize_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
PlanDocumentResizeArgs& args)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
const std::string_view key(argv[i]);
|
||||
if (key == "--current-resolution" || key == "--selected-resolution-index") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
const auto value = pp::foundation::parse_u32(argv[++i]);
|
||||
if (!value) {
|
||||
return value.status();
|
||||
}
|
||||
if (key == "--current-resolution") {
|
||||
args.current_resolution = static_cast<int>(value.value());
|
||||
} else {
|
||||
args.selected_resolution_index = static_cast<int>(value.value());
|
||||
}
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
int plan_document_resize(int argc, char** argv)
|
||||
{
|
||||
PlanDocumentResizeArgs args;
|
||||
const auto status = parse_plan_document_resize_args(argc, argv, args);
|
||||
if (!status.ok()) {
|
||||
print_error("plan-document-resize", status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto state = pp::app::make_document_resize_dialog_state(args.current_resolution);
|
||||
const auto plan = pp::app::plan_document_resize(args.selected_resolution_index);
|
||||
if (!plan) {
|
||||
print_error("plan-document-resize", plan.status().message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::cout << "{\"ok\":true,\"command\":\"plan-document-resize\""
|
||||
<< ",\"state\":{\"currentResolution\":" << state.current_resolution
|
||||
<< ",\"currentResolutionText\":\"" << json_escape(state.current_resolution_text)
|
||||
<< "\",\"currentResolutionIndex\":" << state.current_resolution_index
|
||||
<< ",\"selectedResolutionIndex\":" << args.selected_resolution_index
|
||||
<< "},\"plan\":{\"resolution\":" << plan.value().resolution
|
||||
<< ",\"width\":" << plan.value().width
|
||||
<< ",\"height\":" << plan.value().height
|
||||
<< ",\"clearsHistory\":" << json_bool(plan.value().clears_history)
|
||||
<< "}}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_share_file_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
@@ -4619,6 +4683,10 @@ int main(int argc, char** argv)
|
||||
return plan_app_status(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-document-resize") {
|
||||
return plan_document_resize(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-share-file") {
|
||||
return plan_share_file(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user