SVG spritesheets: pack, merge, rasterize

Packing an SVG sheet makes a new SVG holding its drawing once (as a symbol),
each region a clipped view of it at its new place; merging makes an SVG
whenever any sheet is one, with PNG sheets embedded as images (the merged
sheet's file name takes the matching extension). Both go through
Image::compose, which also does the pixel versions, so merge_append is gone.
Vector sheets save as their SVG (autosaves too, and images load as PNG or
SVG by content), and their asset key includes the SVG. Rasterize in the
Spritesheets menu turns selected SVG sheets into PNGs beside them, with a
toast for each.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-21 00:15:56 -04:00
1 parent bec89bf48f
commit 5f01e8065d
14 files changed
+316 -82

No files matched your search

+1
View File
@@ -34,6 +34,7 @@ namespace anm2ed::imgui
X(ACTION_OPEN_DIRECTORY, BASIC_OPEN_DIRECTORY, -1) \
X(ACTION_SET_FILE_PATH, BASIC_SET_FILE_PATH, -1) \
X(ACTION_PACK, BASIC_PACK, -1) \
X(ACTION_RASTERIZE, LABEL_RASTERIZE, -1) \
X(ACTION_TRIM, BASIC_TRIM, -1) \
X(ACTION_PLAY, LABEL_PLAY, SHORTCUT_PLAY_PAUSE) \
X(ACTION_CENTER_VIEW, LABEL_CENTER_VIEW, SHORTCUT_CENTER_VIEW) \
+1 -1
View File
@@ -313,7 +313,7 @@ namespace anm2ed::imgui
auto pathString = path::to_utf8(spritesheet.path);
auto savePath = closeDocument.directory_get() / spritesheet.path;
path::ensure_directory(savePath.parent_path());
if (texture->write_png(savePath))
if (texture->write(savePath))
{
closeDocument.spritesheet_hash_set_saved(id);
toast_log(Level::INFO, TOAST_SAVE_SPRITESHEET, id, pathString);
+1 -1
View File
@@ -395,7 +395,7 @@ namespace anm2ed::imgui
shortcut(manager.chords[isConverted ? SHORTCUT_CONFIRM : SHORTCUT_CANCEL]);
if (!ImGui::Button(localize.get(label), widgetSize) || !document) continue;
if (isConverted)
document->spritesheets_vector_convert();
document->spritesheets_vector_convert(model::spritesheets_vector_used_get(document->model));
else
document->isVectorKept = true;
vectorPopup.close();
+20 -3
View File
@@ -38,11 +38,11 @@ namespace anm2ed::imgui
{
auto spritesheet = spritesheet_get(document, id);
auto texture = document.texture_get(id);
if (!spritesheet || !texture || texture->is_vector()) continue;
if (!spritesheet || !texture) continue;
auto pathString = path::to_utf8(spritesheet->path);
WorkingDirectory workingDirectory(document.directory_get());
path::ensure_directory(spritesheet->path.parent_path());
auto isSaved = texture->write_png(spritesheet->path);
auto isSaved = texture->write(spritesheet->path);
if (isSaved) document.spritesheet_hash_set_saved(id);
toast_log(isSaved ? Level::INFO : Level::ERROR, isSaved ? TOAST_SAVE_SPRITESHEET : TOAST_SAVE_SPRITESHEET_FAILED,
id, pathString);
@@ -65,7 +65,7 @@ namespace anm2ed::imgui
{
WorkingDirectory workingDirectory(document.directory_get());
path::ensure_directory(newPath.parent_path());
if (!texture->write_png(newPath))
if (!texture->write(newPath))
return toast_log(Level::ERROR, TOAST_SAVE_SPRITESHEET_FAILED, id, pathString);
}
spritesheet->path = newPath;
@@ -287,6 +287,23 @@ namespace anm2ed::imgui
spritesheets.packPopup.open();
},
TOOLTIP_PACK_SPRITESHEET);
// SVG sheets become PNGs beside them; greyed when none of the selection is an SVG.
actions.add(
ACTION_RASTERIZE,
[&]()
{
return std::ranges::any_of(selection,
[&](int id)
{
auto texture = document.texture_get(id);
return texture && texture->is_vector();
});
},
[&]()
{
command_push(panel, [selection](Document& document) { document.spritesheets_vector_convert(selection); });
},
TOOLTIP_RASTERIZE_SPRITESHEETS);
actions.add(
ACTION_SAVE, isAny,
[&]()