Remove namespaces, and make file-local helpers static
Names that only a namespace told apart get prefixes: TOOL_PAN, FONT_BOLD, ICON_FOLDER, COLOR_WHITE, path_to_utf8 and so on. The OpenGL shader class is ShaderProgram, and its uniform ShaderUniform, beside the document's Shader and Uniform. Free functions a member of the same name would hide are called through :: for now. Two unused shader window helpers are gone.
This commit is contained in:
1 parent
7fb2c607c2
commit
666f65bf3a
174 files changed
+2396
-3154
No files matched your search
+16
-21
@@ -2,10 +2,6 @@
|
||||
|
||||
#include "model/xml.h"
|
||||
|
||||
using namespace anm2ed::model;
|
||||
|
||||
namespace anm2ed::edit
|
||||
{
|
||||
constexpr std::string_view ANIMATION_MERGED_SUFFIX = " (Merged)";
|
||||
|
||||
using AnimationPointer = std::shared_ptr<const Animation>;
|
||||
@@ -33,7 +29,7 @@ namespace anm2ed::edit
|
||||
std::vector<AnimationGroup> groups{};
|
||||
};
|
||||
|
||||
AnimationsTaken animations_take(Model& model, const std::set<int>& indices, const std::set<int>& groupIds)
|
||||
static AnimationsTaken animations_take(Model& model, const std::set<int>& indices, const std::set<int>& groupIds)
|
||||
{
|
||||
AnimationsTaken taken{};
|
||||
int index{};
|
||||
@@ -73,7 +69,7 @@ namespace anm2ed::edit
|
||||
int position{-1};
|
||||
};
|
||||
|
||||
AnimationPlace animation_place_get(Model& model, std::uint64_t uid)
|
||||
static AnimationPlace animation_place_get(Model& model, std::uint64_t uid)
|
||||
{
|
||||
auto& entries = model.animations.entries;
|
||||
for (int i = 0; i < (int)entries.size(); ++i)
|
||||
@@ -90,7 +86,7 @@ namespace anm2ed::edit
|
||||
return {};
|
||||
}
|
||||
|
||||
int animation_group_entry_get(const Model& model, int groupId)
|
||||
static int animation_group_entry_get(const Model& model, int groupId)
|
||||
{
|
||||
auto& entries = model.animations.entries;
|
||||
for (int i = 0; i < (int)entries.size(); ++i)
|
||||
@@ -98,14 +94,14 @@ namespace anm2ed::edit
|
||||
return -1;
|
||||
}
|
||||
|
||||
AnimationGroup* animation_group_find(Model& model, int groupId)
|
||||
static AnimationGroup* animation_group_find(Model& model, int groupId)
|
||||
{
|
||||
auto entry = animation_group_entry_get(model, groupId);
|
||||
return entry == -1 ? nullptr : &std::get<AnimationGroup>(model.animations.entries[entry]);
|
||||
}
|
||||
|
||||
// Inserts animations before the animation at a flat index (or at the end), inside `groupId` when given.
|
||||
void animations_insert(Model& model, int index, int groupId, std::vector<AnimationPointer> animations)
|
||||
static void animations_insert(Model& model, int index, int groupId, std::vector<AnimationPointer> animations)
|
||||
{
|
||||
auto before = model.animation_get(index);
|
||||
auto place = before ? animation_place_get(model, before->uid) : AnimationPlace{};
|
||||
@@ -135,7 +131,7 @@ namespace anm2ed::edit
|
||||
}
|
||||
|
||||
// An empty copy of a track list: same tracks and groups, no frames.
|
||||
std::vector<TrackEntry> track_entries_shell_get(const std::vector<TrackEntry>& entries)
|
||||
static std::vector<TrackEntry> track_entries_shell_get(const std::vector<TrackEntry>& entries)
|
||||
{
|
||||
std::vector<TrackEntry> shell{};
|
||||
auto track_shell_get = [](const Track& track)
|
||||
@@ -287,20 +283,20 @@ namespace anm2ed::edit
|
||||
return uids;
|
||||
}
|
||||
|
||||
void track_merge(Track& destination, const Track& source, types::merge::Type type)
|
||||
static void track_merge(Track& destination, const Track& source, Merge type)
|
||||
{
|
||||
std::vector<Frame> frames{};
|
||||
for (const auto& frame : source.frames)
|
||||
frames.push_back(frame_clone(frame));
|
||||
switch (type)
|
||||
{
|
||||
case types::merge::APPEND:
|
||||
case MERGE_APPEND:
|
||||
destination.frames.insert(destination.frames.end(), frames.begin(), frames.end());
|
||||
break;
|
||||
case types::merge::PREPEND:
|
||||
case MERGE_PREPEND:
|
||||
destination.frames.insert(destination.frames.begin(), frames.begin(), frames.end());
|
||||
break;
|
||||
case types::merge::REPLACE:
|
||||
case MERGE_REPLACE:
|
||||
if (destination.frames.size() < frames.size()) destination.frames.resize(frames.size());
|
||||
std::ranges::copy(frames, destination.frames.begin());
|
||||
break;
|
||||
@@ -311,8 +307,8 @@ namespace anm2ed::edit
|
||||
|
||||
// Merges a source animation's layer or null tracks: groups match by name (else are added), tracks match by id
|
||||
// within their group (else are added).
|
||||
void track_entries_merge(std::vector<TrackEntry>& destination, const std::vector<TrackEntry>& source,
|
||||
types::merge::Type type)
|
||||
static void track_entries_merge(std::vector<TrackEntry>& destination, const std::vector<TrackEntry>& source,
|
||||
Merge type)
|
||||
{
|
||||
std::map<int, int> groupRemap{};
|
||||
std::set<int> matchedGroupIds{};
|
||||
@@ -378,7 +374,7 @@ namespace anm2ed::edit
|
||||
|
||||
// Merges source animations into the target (frames appended, prepended, replacing or ignored), optionally deleting
|
||||
// the sources; `ungroupIds` dissolves groups afterwards. Returns the merged animation's uid.
|
||||
Uids animations_merge(Model& model, int target, std::set<int> sources, types::merge::Type type, bool isDeleteAfter,
|
||||
Uids animations_merge(Model& model, int target, std::set<int> sources, Merge type, bool isDeleteAfter,
|
||||
const std::set<int>& ungroupIds)
|
||||
{
|
||||
if (!model.animation_get(target)) return {};
|
||||
@@ -396,13 +392,13 @@ namespace anm2ed::edit
|
||||
if (!source) continue;
|
||||
auto sourceCopy = *source;
|
||||
auto& destination = *model.animation_edit(target);
|
||||
if (type == types::merge::APPEND)
|
||||
if (type == MERGE_APPEND)
|
||||
for (auto& trigger : sourceCopy.triggers.frames)
|
||||
trigger.atFrame += length;
|
||||
if (type == types::merge::PREPEND)
|
||||
if (type == MERGE_PREPEND)
|
||||
for (auto& trigger : destination.triggers.frames)
|
||||
trigger.atFrame += sourceCopy.frameNum;
|
||||
if (type == types::merge::APPEND || type == types::merge::PREPEND) length += sourceCopy.frameNum;
|
||||
if (type == MERGE_APPEND || type == MERGE_PREPEND) length += sourceCopy.frameNum;
|
||||
track_merge(destination.root, sourceCopy.root, type);
|
||||
track_entries_merge(destination.layers, sourceCopy.layers, type);
|
||||
track_entries_merge(destination.nulls, sourceCopy.nulls, type);
|
||||
@@ -428,4 +424,3 @@ namespace anm2ed::edit
|
||||
animation_groups_remove(model, ungroupIds);
|
||||
return {uid};
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,6 @@
|
||||
#include "model/frames.h"
|
||||
#include "model/xml.h"
|
||||
|
||||
using namespace anm2ed::model;
|
||||
|
||||
namespace anm2ed::edit
|
||||
{
|
||||
std::string region_name_get(const std::string& format, int number)
|
||||
{
|
||||
try
|
||||
@@ -22,14 +18,14 @@ namespace anm2ed::edit
|
||||
}
|
||||
}
|
||||
|
||||
bool is_region_matched(const Region& region, const Frame& frame)
|
||||
static bool is_region_matched(const Region& region, const Frame& frame)
|
||||
{
|
||||
return glm::ivec2(region.crop) == glm::ivec2(frame.crop) && glm::ivec2(region.size) == glm::ivec2(frame.size) &&
|
||||
glm::ivec2(region.pivot) == glm::ivec2(frame.pivot);
|
||||
}
|
||||
|
||||
// Every frame of every layer track whose layer has a spritesheet, with that spritesheet's id.
|
||||
template <class Callback> void layer_frames_each(Model& model, int animationIndex, Callback&& callback)
|
||||
template <class Callback> static void layer_frames_each(Model& model, int animationIndex, Callback&& callback)
|
||||
{
|
||||
auto animation = model.animation_get(animationIndex);
|
||||
if (!animation) return;
|
||||
@@ -545,4 +541,3 @@ namespace anm2ed::edit
|
||||
defaultAnimationName.empty() ? source.animations.defaultAnimation : defaultAnimationName;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+43
-46
@@ -14,10 +14,8 @@
|
||||
|
||||
// Document edits as plain functions of the model. Each returns the uids of the elements it created or changed that
|
||||
// the caller may want to select (the first one is the focus); selection itself stays with the UI.
|
||||
namespace anm2ed::edit
|
||||
{
|
||||
using Uids = std::vector<std::uint64_t>;
|
||||
using ImageGet = std::function<const resource::Image*(int)>;
|
||||
using ImageGet = std::function<const Image*(int)>;
|
||||
|
||||
struct RowTarget
|
||||
{
|
||||
@@ -90,59 +88,58 @@ namespace anm2ed::edit
|
||||
};
|
||||
|
||||
bool is_frame_property_valid(FrameProperty, ItemType);
|
||||
void frame_property_copy(model::Frame&, const model::Frame&, FrameProperty);
|
||||
Uids frames_property_set(model::Model&, const std::set<Reference>&, FrameProperty, const model::Frame&);
|
||||
void frame_property_copy(Frame&, const Frame&, FrameProperty);
|
||||
Uids frames_property_set(Model&, const std::set<Reference>&, FrameProperty, const Frame&);
|
||||
|
||||
std::map<Reference, std::set<int>> frames_by_track_get(const std::set<Reference>&);
|
||||
|
||||
Uids frame_insert(model::Model&, Reference, int);
|
||||
Uids frames_delete(model::Model&, const std::set<Reference>&);
|
||||
Uids frames_duplicate(model::Model&, const std::set<Reference>&, Reference);
|
||||
Uids frames_reverse(model::Model&, const std::set<Reference>&);
|
||||
Uids frames_bake(model::Model&, const std::set<Reference>&, int, bool, bool);
|
||||
Uids frame_split(model::Model&, Reference, int);
|
||||
Uids frames_split(model::Model&, const std::set<Reference>&, int);
|
||||
Uids frames_move(model::Model&, const std::set<Reference>&, Reference, int);
|
||||
Uids frame_durations_set(model::Model&, const std::map<Reference, int>&);
|
||||
Uids trigger_at_frame_set(model::Model&, Reference, int);
|
||||
Uids frames_paste(model::Model&, Reference, const std::set<Reference>&, const std::string&, int, std::string*);
|
||||
Uids root_bake_into(model::Model&, const std::set<Reference>&, const std::set<Reference>&, RootBakeOptions);
|
||||
Uids frame_insert(Model&, Reference, int);
|
||||
Uids frames_delete(Model&, const std::set<Reference>&);
|
||||
Uids frames_duplicate(Model&, const std::set<Reference>&, Reference);
|
||||
Uids frames_reverse(Model&, const std::set<Reference>&);
|
||||
Uids frames_bake(Model&, const std::set<Reference>&, int, bool, bool);
|
||||
Uids frame_split(Model&, Reference, int);
|
||||
Uids frames_split(Model&, const std::set<Reference>&, int);
|
||||
Uids frames_move(Model&, const std::set<Reference>&, Reference, int);
|
||||
Uids frame_durations_set(Model&, const std::map<Reference, int>&);
|
||||
Uids trigger_at_frame_set(Model&, Reference, int);
|
||||
Uids frames_paste(Model&, Reference, const std::set<Reference>&, const std::string&, int, std::string*);
|
||||
Uids root_bake_into(Model&, const std::set<Reference>&, const std::set<Reference>&, RootBakeOptions);
|
||||
|
||||
Uids items_remove(model::Model&, int, const std::map<int, std::set<int>>&, const std::map<int, std::set<int>>&);
|
||||
Uids items_group(model::Model&, int, int, const std::set<int>&, const std::string&);
|
||||
Uids items_move(model::Model&, int, int, const std::set<int>&, const std::set<int>&, RowTarget, bool, bool);
|
||||
Uids animation_length_fit(model::Model&, int);
|
||||
int item_add(model::Model&, ItemType, int, int, model::Layer, model::Null, int, types::destination::Type);
|
||||
Uids items_remove(Model&, int, const std::map<int, std::set<int>>&, const std::map<int, std::set<int>>&);
|
||||
Uids items_group(Model&, int, int, const std::set<int>&, const std::string&);
|
||||
Uids items_move(Model&, int, int, const std::set<int>&, const std::set<int>&, RowTarget, bool, bool);
|
||||
Uids animation_length_fit(Model&, int);
|
||||
int item_add(Model&, ItemType, int, int, Layer, Null, int, Destination);
|
||||
|
||||
std::set<int> animation_group_ids_get(const model::Model&);
|
||||
std::set<int> animation_group_indices_get(const model::Model&, int);
|
||||
void animation_groups_remove(model::Model&, const std::set<int>&);
|
||||
Uids animation_add(model::Model&, int, int, int, const std::string&);
|
||||
Uids animations_remove(model::Model&, const std::set<int>&, const std::set<int>&);
|
||||
Uids animations_move(model::Model&, const std::set<int>&, const std::set<int>&, AnimationTarget);
|
||||
Uids animations_group(model::Model&, const std::set<int>&, const std::string&);
|
||||
Uids animations_paste(model::Model&, const std::string&, int, int, std::set<int>&, std::string*);
|
||||
Uids animations_merge(model::Model&, int, std::set<int>, types::merge::Type, bool, const std::set<int>&);
|
||||
std::set<int> animation_group_ids_get(const Model&);
|
||||
std::set<int> animation_group_indices_get(const Model&, int);
|
||||
void animation_groups_remove(Model&, const std::set<int>&);
|
||||
Uids animation_add(Model&, int, int, int, const std::string&);
|
||||
Uids animations_remove(Model&, const std::set<int>&, const std::set<int>&);
|
||||
Uids animations_move(Model&, const std::set<int>&, const std::set<int>&, AnimationTarget);
|
||||
Uids animations_group(Model&, const std::set<int>&, const std::string&);
|
||||
Uids animations_paste(Model&, const std::string&, int, int, std::set<int>&, std::string*);
|
||||
Uids animations_merge(Model&, int, std::set<int>, Merge, bool, const std::set<int>&);
|
||||
|
||||
std::string region_name_get(const std::string&, int);
|
||||
Uids regions_generate(model::Model&, const std::set<int>&, const std::set<Reference>&, const std::string&,
|
||||
Uids regions_generate(Model&, const std::set<int>&, const std::set<Reference>&, const std::string&,
|
||||
RegionFrameMapping);
|
||||
Uids regions_scan(model::Model&);
|
||||
Uids region_frames_sync(model::Model&);
|
||||
Uids regions_paste(model::Model&, int, const std::string&, int, std::string*);
|
||||
Uids animation_grid_generate(model::Model&, const std::vector<Reference>&, const GridOptions&);
|
||||
Uids frames_change_apply(model::Model&, const ChangeTargets&, FrameChange, ChangeType);
|
||||
bool regions_trim(model::Model&, int, const std::set<int>&, const resource::Image&);
|
||||
std::optional<resource::Image> spritesheet_pack(model::Model&, int, const resource::Image&, int);
|
||||
std::optional<resource::Image> spritesheets_merge(model::Model&, const std::set<int>&, const ImageGet&, bool, bool,
|
||||
Uids regions_scan(Model&);
|
||||
Uids region_frames_sync(Model&);
|
||||
Uids regions_paste(Model&, int, const std::string&, int, std::string*);
|
||||
Uids animation_grid_generate(Model&, const std::vector<Reference>&, const GridOptions&);
|
||||
Uids frames_change_apply(Model&, const ChangeTargets&, FrameChange, ChangeType);
|
||||
bool regions_trim(Model&, int, const std::set<int>&, const Image&);
|
||||
std::optional<Image> spritesheet_pack(Model&, int, const Image&, int);
|
||||
std::optional<Image> spritesheets_merge(Model&, const std::set<int>&, const ImageGet&, bool, bool,
|
||||
bool, Origin);
|
||||
|
||||
// Where a spritesheet path of a document (this one, or a library) points, from this document.
|
||||
using SpritesheetPathGet = std::function<std::filesystem::path(const model::Model&, const std::filesystem::path&)>;
|
||||
model::Model animation_layers_flatten(model::Model, const model::LibraryGet&, const SpritesheetPathGet&,
|
||||
using SpritesheetPathGet = std::function<std::filesystem::path(const Model&, const std::filesystem::path&)>;
|
||||
Model animation_layers_flatten(Model, const LibraryGet&, const SpritesheetPathGet&,
|
||||
const std::set<int>& = {});
|
||||
Uids content_remove(model::Model&, ElementType, const std::set<int>&, int, const model::LibraryGet&,
|
||||
Uids content_remove(Model&, ElementType, const std::set<int>&, int, const LibraryGet&,
|
||||
const SpritesheetPathGet&);
|
||||
model::Model isaac_bridge(model::Model);
|
||||
bool file_merge(model::Model&, const std::filesystem::path&, const std::filesystem::path&, FileMergePreset);
|
||||
}
|
||||
Model isaac_bridge(Model);
|
||||
bool file_merge(Model&, const std::filesystem::path&, const std::filesystem::path&, FileMergePreset);
|
||||
@@ -7,14 +7,9 @@
|
||||
#include "math_util.h"
|
||||
#include "model/frames.h"
|
||||
|
||||
using namespace anm2ed::model;
|
||||
using namespace anm2ed::util;
|
||||
|
||||
namespace anm2ed::edit
|
||||
{
|
||||
// A draw as a plain layer frame of one frame: its transform (parents included) taken apart into position, scale and
|
||||
// rotation. Skew has no place in a plain frame, and is dropped.
|
||||
Frame draw_frame_bake(const Draw& draw)
|
||||
static Frame draw_frame_bake(const Draw& draw)
|
||||
{
|
||||
auto frame = draw.frame;
|
||||
auto size = glm::max(frame.size, glm::vec2(1.0f));
|
||||
@@ -24,7 +19,7 @@ namespace anm2ed::edit
|
||||
auto scaleX = glm::length(column0);
|
||||
auto determinant = column0.x * column1.y - column0.y * column1.x;
|
||||
frame.position = glm::vec2(model * glm::vec4(frame.pivot / size, 0.0f, 1.0f));
|
||||
frame.scale = math::unit_to_percent(glm::vec2(scaleX, scaleX > 0.0f ? determinant / scaleX : 0.0f));
|
||||
frame.scale = unit_to_percent(glm::vec2(scaleX, scaleX > 0.0f ? determinant / scaleX : 0.0f));
|
||||
frame.rotation = glm::degrees(std::atan2(column0.y, column0.x));
|
||||
frame.skew = {};
|
||||
frame.depth = 0;
|
||||
@@ -35,7 +30,7 @@ namespace anm2ed::edit
|
||||
return frame;
|
||||
}
|
||||
|
||||
bool is_frame_baked_equal(Frame a, const Frame& b)
|
||||
static bool is_frame_baked_equal(Frame a, const Frame& b)
|
||||
{
|
||||
a.uid = b.uid;
|
||||
a.duration = b.duration;
|
||||
@@ -163,4 +158,3 @@ namespace anm2ed::edit
|
||||
std::erase_if(content.layers, is_flattened);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
+1
-7
@@ -7,11 +7,6 @@
|
||||
#include "model/frames.h"
|
||||
#include "model/xml.h"
|
||||
|
||||
using namespace anm2ed::util;
|
||||
using namespace anm2ed::model;
|
||||
|
||||
namespace anm2ed::edit
|
||||
{
|
||||
std::map<Reference, std::set<int>> frames_by_track_get(const std::set<Reference>& frames)
|
||||
{
|
||||
std::map<Reference, std::set<int>> result{};
|
||||
@@ -23,7 +18,7 @@ namespace anm2ed::edit
|
||||
return result;
|
||||
}
|
||||
|
||||
Uids frames_uids_get(const Track& track, int start, int count)
|
||||
static Uids frames_uids_get(const Track& track, int start, int count)
|
||||
{
|
||||
Uids uids{};
|
||||
for (int i = std::max(start, 0); i < std::min(start + count, (int)track.frames.size()); ++i)
|
||||
@@ -446,4 +441,3 @@ namespace anm2ed::edit
|
||||
model.track_edit(rootReference)->frames = std::move(rewritten);
|
||||
return uids;
|
||||
}
|
||||
}
|
||||
+3
-9
@@ -7,15 +7,10 @@
|
||||
#include "math_util.h"
|
||||
#include "model/frames.h"
|
||||
|
||||
using namespace anm2ed::model;
|
||||
using namespace anm2ed::util;
|
||||
|
||||
namespace anm2ed::edit
|
||||
{
|
||||
// An alpha offset joins the alpha tint: exact on opaque pixels, which the offset can only fade.
|
||||
void alpha_offsets_bridge(Model& model)
|
||||
static void alpha_offsets_bridge(Model& model)
|
||||
{
|
||||
auto is_offset = [](const Frame& frame) { return math::float_to_uint8(frame.colorOffset.a) != 0; };
|
||||
auto is_offset = [](const Frame& frame) { return float_to_uint8(frame.colorOffset.a) != 0; };
|
||||
for (int i = 0; i < model.animations_count_get(); ++i)
|
||||
{
|
||||
auto isUsed = false;
|
||||
@@ -38,7 +33,7 @@ namespace anm2ed::edit
|
||||
// A layer frame's depth becomes a copy of its layer, named for the depth, standing where the editor draws it (the
|
||||
// layer at the copy's place + depth, past the layer already there), and showing only the frames at that depth; the
|
||||
// layer itself shows the rest. Groups can't stand apart in the game, so their roots go into their tracks first.
|
||||
void depths_bridge(Model& model)
|
||||
static void depths_bridge(Model& model)
|
||||
{
|
||||
auto& content = model.content;
|
||||
std::map<std::pair<int, int>, int> copyIds{};
|
||||
@@ -117,4 +112,3 @@ namespace anm2ed::edit
|
||||
depths_bridge(model);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -9,13 +9,7 @@
|
||||
#include "pack.h"
|
||||
#include "path.h"
|
||||
|
||||
using namespace anm2ed::model;
|
||||
using namespace anm2ed::resource;
|
||||
using namespace anm2ed::util;
|
||||
|
||||
// Spritesheet pixel edits: the model changes in place, and a new image is returned for the document to store.
|
||||
namespace anm2ed::edit
|
||||
{
|
||||
bool regions_trim(Model& model, int spritesheetId, const std::set<int>& ids, const Image& source)
|
||||
{
|
||||
auto spritesheet = item_get(model.content.spritesheets, spritesheetId);
|
||||
@@ -35,9 +29,9 @@ namespace anm2ed::edit
|
||||
for (int y = minPoint.y; y < maxPoint.y; ++y)
|
||||
for (int x = minPoint.x; x < maxPoint.x; ++x)
|
||||
{
|
||||
auto index = ((std::size_t)y * source.size.x + x) * image::CHANNELS;
|
||||
if (index + image::CHANNELS > source.pixels.size()) continue;
|
||||
if (std::all_of(source.pixels.begin() + index, source.pixels.begin() + index + image::CHANNELS,
|
||||
auto index = ((std::size_t)y * source.size.x + x) * IMAGE_CHANNELS;
|
||||
if (index + IMAGE_CHANNELS > source.pixels.size()) continue;
|
||||
if (std::all_of(source.pixels.begin() + index, source.pixels.begin() + index + IMAGE_CHANNELS,
|
||||
[](auto channel) { return channel == 0; }))
|
||||
continue;
|
||||
contentMin = glm::min(contentMin, glm::ivec2(x, y));
|
||||
@@ -100,7 +94,7 @@ namespace anm2ed::edit
|
||||
|
||||
glm::ivec2 packedSize{};
|
||||
std::vector<glm::ivec2> positions{};
|
||||
if (!util::pack::rects_pack(sizes, packedSize, positions) || packedSize.x <= 0 || packedSize.y <= 0) return {};
|
||||
if (!rects_pack(sizes, packedSize, positions) || packedSize.x <= 0 || packedSize.y <= 0) return {};
|
||||
|
||||
std::vector<ImagePart> parts{};
|
||||
for (int i = 0; i < (int)items.size(); ++i)
|
||||
@@ -132,7 +126,7 @@ namespace anm2ed::edit
|
||||
auto source = item_get(model.content.spritesheets, sourceId);
|
||||
Region region{};
|
||||
region.id = item_next_id_get(base->regions);
|
||||
auto stem = path::to_utf8(source->path.stem());
|
||||
auto stem = path_to_utf8(source->path.stem());
|
||||
region.name = stem.empty() ? std::format("#{}", sourceId) : stem;
|
||||
region.crop = crop;
|
||||
region.size = size;
|
||||
@@ -157,7 +151,7 @@ namespace anm2ed::edit
|
||||
{
|
||||
auto sourceRegionId = sourceRegion.id;
|
||||
sourceRegion.id = item_next_id_get(base->regions);
|
||||
sourceRegion.uid = util::uid_next();
|
||||
sourceRegion.uid = uid_next();
|
||||
sourceRegion.crop += offset;
|
||||
base->regions.push_back(sourceRegion);
|
||||
regionIdMap[id][sourceRegionId] = sourceRegion.id;
|
||||
@@ -185,10 +179,9 @@ namespace anm2ed::edit
|
||||
});
|
||||
|
||||
auto isVector = std::ranges::any_of(parts, [](const ImagePart& part) { return part.image->is_vector(); });
|
||||
if (isVector != path::is_extension(base->path, image::SVG_EXTENSION))
|
||||
base->path.replace_extension(isVector ? image::SVG_EXTENSION : image::PNG_EXTENSION);
|
||||
if (isVector != is_path_extension(base->path, SVG_EXTENSION))
|
||||
base->path.replace_extension(isVector ? SVG_EXTENSION : PNG_EXTENSION);
|
||||
std::erase_if(model.content.spritesheets, [&](const Spritesheet& spritesheet)
|
||||
{ return spritesheet.id != baseId && ids.contains(spritesheet.id); });
|
||||
return Image::compose(parts, mergedSize, isVector);
|
||||
}
|
||||
}
|
||||
+3
-8
@@ -1,10 +1,6 @@
|
||||
#include "edit/edit.h"
|
||||
|
||||
using namespace anm2ed::model;
|
||||
|
||||
namespace anm2ed::edit
|
||||
{
|
||||
std::vector<TrackEntry>* track_entries_edit(Model& model, int animationIndex, int type)
|
||||
static std::vector<TrackEntry>* track_entries_edit(Model& model, int animationIndex, int type)
|
||||
{
|
||||
if (type != LAYER && type != NULL_) return nullptr;
|
||||
auto animation = model.animation_edit(animationIndex);
|
||||
@@ -161,7 +157,7 @@ namespace anm2ed::edit
|
||||
// Adds a layer or null (or updates the one with the item's id) and gives it a track in one or every animation.
|
||||
// Adds track `id` (a new item, from `layer` or `null`, at -1) to an animation or all of them.
|
||||
int item_add(Model& model, ItemType type, int animationIndex, int id, Layer layer, Null null, int insertBeforeId,
|
||||
types::destination::Type destination)
|
||||
Destination destination)
|
||||
{
|
||||
auto& content = model.content;
|
||||
auto item_insert = [&](auto& items, auto item)
|
||||
@@ -192,11 +188,10 @@ namespace anm2ed::edit
|
||||
entries.insert(insertBeforeId == -1 ? entries.end() : before, Track{.type = type, .id = id});
|
||||
};
|
||||
|
||||
if (destination == types::destination::ALL)
|
||||
if (destination == DESTINATION_ALL)
|
||||
for (int i = 0; i < model.animations_count_get(); ++i)
|
||||
add(i);
|
||||
else if (model.animation_get(animationIndex))
|
||||
add(animationIndex);
|
||||
return id;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user