diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-04 11:09:41 +0100 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-04 21:36:58 +0100 |
| commit | 14167171aff17b9bc4b5531fffd3f729e12f8a59 (patch) | |
| tree | c15e56a4ec716f6cb83419cea37dc63f484859ab | |
| parent | b16ab0038a0ec70c59a3bbfef4aa4dee0b04cf15 (diff) | |
src: make anim_scale easier to construct
| -rw-r--r-- | anim-crop-tool/main.cpp | 8 | ||||
| -rw-r--r-- | serialize/anim.cpp | 4 | ||||
| -rw-r--r-- | src/anim.hpp | 7 |
3 files changed, 12 insertions, 7 deletions
diff --git a/anim-crop-tool/main.cpp b/anim-crop-tool/main.cpp index 6cfaf8aa..9c09a413 100644 --- a/anim-crop-tool/main.cpp +++ b/anim-crop-tool/main.cpp @@ -94,7 +94,7 @@ static bool load_file(anim_group& group, options& opts, anim_atlas_& atlas, Stri if (opts.scale.type != anim_scale_type::ratio) { float new_width = opts.scale.scale_to_({(unsigned)size.width, (unsigned)size.height})[0]; - opts.scale = {{.r = {new_width / (float)size.width}}, anim_scale_type::ratio}; + opts.scale = {new_width / (float)size.width}; } const auto dest_size = fm_begin( @@ -211,11 +211,11 @@ static std::tuple<options, Arguments, bool> parse_cmdline(int argc, const char* options opts; if (!args.value<StringView>("width").isEmpty()) - opts.scale = { { .f = {true, args.value<unsigned>("width")} }, anim_scale_type::fixed }; + opts.scale = {args.value<unsigned>("width"), true}; else if (!args.value<StringView>("height").isEmpty()) - opts.scale = { { .f = {false, args.value<unsigned>("height")} }, anim_scale_type::fixed }; + opts.scale = {args.value<unsigned>("height"), false}; else if (!args.value<StringView>("scale").isEmpty()) - opts.scale = { { .r = {args.value<float>("scale")} } , anim_scale_type::ratio }; + opts.scale = {args.value<float>("scale")}; opts.output_dir = Path::join(loader.startup_directory(), args.value<StringView>("output")); opts.input_file = Path::join(loader.startup_directory(), args.value<StringView>("input")); diff --git a/serialize/anim.cpp b/serialize/anim.cpp index 42f39328..7be6323b 100644 --- a/serialize/anim.cpp +++ b/serialize/anim.cpp @@ -129,11 +129,11 @@ void adl_serializer<floormat::anim_scale>::from_json(const json& j, floormat::an { auto factor = (float)j[1]; fm_soft_assert(factor > 0 && factor <= 1); - val = { { .r = {factor} }, anim_scale_type::ratio }; + val = {factor}; } else if (bool is_width = type == "width"_s; is_width || type == "height"_s) { - val = { { .f = {is_width, (unsigned)j[1]} }, anim_scale_type::fixed }; + val = {(unsigned)j[1], is_width}; fm_soft_assert(val.f.width_or_height > 0); } else diff --git a/src/anim.hpp b/src/anim.hpp index c2a2d0d1..f21e24ae 100644 --- a/src/anim.hpp +++ b/src/anim.hpp @@ -41,6 +41,11 @@ struct anim_scale final struct empty e = {}; }; anim_scale_type type = anim_scale_type::invalid; + constexpr anim_scale() = default; + constexpr anim_scale(const anim_scale&) = default; + constexpr anim_scale& operator=(const anim_scale&) = default; + constexpr anim_scale(float ratio) : r{ratio}, type{anim_scale_type::ratio} {} + constexpr anim_scale(unsigned width_or_height, bool is_width) : f{is_width, width_or_height}, type{anim_scale_type::ratio} {} Vector2ui scale_to(Vector2ui image_size) const; Vector2 scale_to_(Vector2ui image_size) const; }; @@ -50,7 +55,7 @@ struct anim_def final String object_name, anim_name; std::vector<anim_group> groups; Vector2ui pixel_size; - anim_scale scale; + anim_scale scale = anim_scale{1}; std::size_t nframes = 0, fps = 0, actionframe = 0; }; |
