Slim Document: move data-model code out, unify edit plumbing

- Region generate/scan move to anm2/regions.cpp; both generators number from 1
- file_merge moves to anm2/merge.cpp and is table-driven
- MaxRects packer moves to util/pack
- Uniform config apply/trim/save move to resource/shader
- Snapshots push from their owned state; Document snapshot wrappers removed
- DocumentData base replaces the hand-written move constructor
- toast_log replaces 55 duplicated toast + English log pairs
- Apply repo .clang-format to touched files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-03 13:08:00 -04:00
1 parent a9f48bc3a0
commit 3f31cedeed
32 files changed
+3405 -4428

No files matched your search

+31 -38
View File
@@ -27,18 +27,18 @@ namespace anm2ed::imgui
uint64_t documentId{};
};
#define ANM2_DRAG_DROP_MERGE_PRESETS \
#define ANM2_DRAG_DROP_MERGE_PRESETS \
X(FILE_MERGE_PRESET_MERGE_BY_NAME, BASIC_MERGE, TOOLTIP_MERGE_PRESET_MERGE_BY_NAME) \
X(FILE_MERGE_PRESET_APPEND_AS_NEW, BASIC_APPEND, TOOLTIP_MERGE_PRESET_APPEND_AS_NEW) \
X(FILE_MERGE_PRESET_APPEND_AS_NEW, BASIC_APPEND, TOOLTIP_MERGE_PRESET_APPEND_AS_NEW) \
X(FILE_MERGE_PRESET_REPLACE_MATCHING, BASIC_REPLACE, TOOLTIP_MERGE_PRESET_REPLACE_MATCHING)
constexpr StringType ANM2_DRAG_DROP_MERGE_PRESET_LABELS[Document::FILE_MERGE_PRESET_COUNT] = {
constexpr StringType ANM2_DRAG_DROP_MERGE_PRESET_LABELS[FILE_MERGE_PRESET_COUNT] = {
#define X(preset, label, tooltip) label,
ANM2_DRAG_DROP_MERGE_PRESETS
#undef X
};
constexpr StringType ANM2_DRAG_DROP_MERGE_PRESET_TOOLTIPS[Document::FILE_MERGE_PRESET_COUNT] = {
constexpr StringType ANM2_DRAG_DROP_MERGE_PRESET_TOOLTIPS[FILE_MERGE_PRESET_COUNT] = {
#define X(preset, label, tooltip) tooltip,
ANM2_DRAG_DROP_MERGE_PRESETS
#undef X
@@ -47,13 +47,13 @@ namespace anm2ed::imgui
#undef ANM2_DRAG_DROP_MERGE_PRESETS
void anm2_drag_drop_merge_queue(Manager& manager, const std::vector<std::filesystem::path>& paths,
Document::FileMergePreset preset)
FileMergePreset preset)
{
manager.command_push({manager.selected,
[paths, preset](Manager&, Document& document)
manager.command_push({manager.selected, [paths, preset](Manager&, Document& document)
{
document.anm2_snapshot(localize.get(EDIT_MERGE_ANM2));
for (auto& path : paths) document.file_merge(path, preset);
document.snapshots.anm2_push(localize.get(EDIT_MERGE_ANM2));
for (auto& path : paths)
document.anm2.file_merge(path, document.directory_get(), preset);
document.change(Document::ALL);
}});
}
@@ -70,8 +70,8 @@ namespace anm2ed::imgui
order.reserve(manager.documents.size());
for (auto documentId : pendingDocumentTabIds)
{
auto it = std::ranges::find_if(manager.documents, [documentId](const Document& document)
{ return document.tabId == documentId; });
auto it = std::ranges::find_if(manager.documents,
[documentId](const Document& document) { return document.tabId == documentId; });
if (it == manager.documents.end())
{
pendingDocumentTabIds.clear();
@@ -115,7 +115,8 @@ namespace anm2ed::imgui
index_remap(manager.selected);
index_remap(manager.pendingSelected);
index_remap(closeDocumentIndex);
for (auto& index : manager.selectionHistory) index_remap(index);
for (auto& index : manager.selectionHistory)
index_remap(index);
for (auto& command : manager.commands)
if (!command.runManager) index_remap(command.documentIndex);
std::erase(manager.selectionHistory, -1);
@@ -151,8 +152,8 @@ namespace anm2ed::imgui
if (document.lastAutosaveTime > time::SECOND_M)
{
auto options = settings.anm2_options_get();
manager.command_push({i, [options](Manager& manager, Document& document)
{ manager.autosave(document, options); }});
manager.command_push(
{i, [options](Manager& manager, Document& document) { manager.autosave(document, options); }});
}
}
}
@@ -324,17 +325,11 @@ namespace anm2ed::imgui
if (texture->write_png(savePath))
{
closeDocument.spritesheet_hash_set_saved(id);
toasts.push(
std::vformat(localize.get(TOAST_SAVE_SPRITESHEET), std::make_format_args(id, pathString)));
logger.info(std::vformat(localize.get(TOAST_SAVE_SPRITESHEET, anm2ed::ENGLISH),
std::make_format_args(id, pathString)));
toast_log(Level::INFO, TOAST_SAVE_SPRITESHEET, id, pathString);
}
else
{
toasts.push(std::vformat(localize.get(TOAST_SAVE_SPRITESHEET_FAILED),
std::make_format_args(id, pathString)));
logger.error(std::vformat(localize.get(TOAST_SAVE_SPRITESHEET_FAILED, anm2ed::ENGLISH),
std::make_format_args(id, pathString)));
toast_log(Level::ERROR, TOAST_SAVE_SPRITESHEET_FAILED, id, pathString);
}
}
}
@@ -350,12 +345,11 @@ namespace anm2ed::imgui
if (ImGui::Button(localize.get(BASIC_NO), widgetSize))
{
auto index = closeDocumentIndex;
manager.command_push({.runManager =
[index](Manager& manager)
{
manager.autosave_file_clear(index);
manager.close(index);
}});
manager.command_push({.runManager = [index](Manager& manager)
{
manager.autosave_file_clear(index);
manager.close(index);
}});
close();
}
@@ -389,7 +383,7 @@ namespace anm2ed::imgui
manager.anm2DragDropPaths.clear();
manager.anm2DragDropPopup.close();
manager.anm2DragDropMergePopup.close();
manager.anm2DragDropMergePreset = Document::FILE_MERGE_PRESET_MERGE_BY_NAME;
manager.anm2DragDropMergePreset = FILE_MERGE_PRESET_MERGE_BY_NAME;
};
if (manager.anm2DragDropPaths.empty())
@@ -402,10 +396,9 @@ namespace anm2ed::imgui
ImGuiWindowFlags_NoResize))
{
auto document = manager.get();
manager.anm2DragDropMergePreset =
std::clamp(manager.anm2DragDropMergePreset, 0, Document::FILE_MERGE_PRESET_COUNT - 1);
manager.anm2DragDropMergePreset = std::clamp(manager.anm2DragDropMergePreset, 0, FILE_MERGE_PRESET_COUNT - 1);
for (int preset = 0; preset < Document::FILE_MERGE_PRESET_COUNT; ++preset)
for (int preset = 0; preset < FILE_MERGE_PRESET_COUNT; ++preset)
{
ImGui::PushID(preset);
ImGui::RadioButton(localize.get(ANM2_DRAG_DROP_MERGE_PRESET_LABELS[preset]),
@@ -420,7 +413,7 @@ namespace anm2ed::imgui
if (ImGui::Button(localize.get(BASIC_MERGE), widgetSize))
{
auto paths = manager.anm2DragDropPaths;
auto preset = (Document::FileMergePreset)manager.anm2DragDropMergePreset;
auto preset = (FileMergePreset)manager.anm2DragDropMergePreset;
anm2_drag_drop_merge_queue(manager, paths, preset);
drag_drop_reset();
}
@@ -452,11 +445,11 @@ namespace anm2ed::imgui
: localize.get(LABEL_DOCUMENTS_OPEN_NEW)))
{
auto paths = manager.anm2DragDropPaths;
manager.command_push({.runManager =
[paths](Manager& manager)
{
for (auto& path : paths) manager.open(path);
}});
manager.command_push({.runManager = [paths](Manager& manager)
{
for (auto& path : paths)
manager.open(path);
}});
drag_drop_reset();
}
+6 -7
View File
@@ -195,8 +195,7 @@ namespace anm2ed::imgui::popup
auto queuedAddItemSpritesheetID = addItemSpritesheetID;
auto queuedAddItemIsShowRect = addItemIsShowRect;
manager.command_push({manager.selected,
[=](Manager&, Document& document)
manager.command_push({manager.selected, [=](Manager&, Document& document)
{
Element item{};
item.id = queuedAddItemID;
@@ -204,12 +203,12 @@ namespace anm2ed::imgui::popup
item.spritesheetId = queuedAddItemSpritesheetID;
item.isShowRect = queuedAddItemIsShowRect;
document.anm2_snapshot(localize.get(EDIT_ADD_ITEM));
auto addId = document.anm2.item_add((ItemType)queuedType, queuedAnimationIndex, item,
queuedInsertBeforeID,
(destination::Type)queuedDestination);
document.snapshots.anm2_push(localize.get(EDIT_ADD_ITEM));
auto addId =
document.anm2.item_add((ItemType)queuedType, queuedAnimationIndex, item,
queuedInsertBeforeID, (destination::Type)queuedDestination);
document.anm2_change(Document::ITEMS);
document.change(Document::ITEMS);
if (addId != -1)
{
+19 -27
View File
@@ -38,9 +38,7 @@ namespace anm2ed::imgui
auto path = request.path;
auto options = request.options;
manager.command_push({.runManager =
[=](Manager& manager)
{ manager.save(index, path, options); }});
manager.command_push({.runManager = [=](Manager& manager) { manager.save(index, path, options); }});
}
bool Taskbar::save_request(Manager& manager, Settings& settings, int index, const std::filesystem::path& path,
@@ -145,11 +143,11 @@ namespace anm2ed::imgui
if (dialog.is_selected(Dialog::ANM2_OPEN))
{
auto paths = dialog.paths;
manager.command_push({.runManager =
[paths](Manager& manager)
{
for (auto& path : paths) manager.open(path);
}});
manager.command_push({.runManager = [paths](Manager& manager)
{
for (auto& path : paths)
manager.open(path);
}});
dialog.reset();
}
@@ -172,15 +170,13 @@ namespace anm2ed::imgui
if (ImGui::MenuItem(localize.get(LABEL_SCAN_AND_SET_REGIONS), nullptr, false, document && hasRegions))
{
manager.command_push({manager.selected,
[](Manager&, Document& document)
manager.command_push({manager.selected, [](Manager&, Document& document)
{
document.anm2_snapshot(localize.get(EDIT_SCAN_AND_SET_REGIONS));
document.scan_and_set_regions();
document.snapshots.anm2_push(localize.get(EDIT_SCAN_AND_SET_REGIONS));
document.anm2.regions_scan();
document.change(Document::FRAMES);
}});
toasts.push(localize.get(TOAST_SCAN_AND_SET_REGIONS));
logger.info(localize.get(TOAST_SCAN_AND_SET_REGIONS, anm2ed::ENGLISH));
toast_log(Level::INFO, TOAST_SCAN_AND_SET_REGIONS);
}
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_WIZARD_SCAN_AND_SET_REGIONS));
@@ -284,19 +280,15 @@ namespace anm2ed::imgui
auto queuedAnimationIndices = animationIndices;
auto queuedFormat = settings.generateRegionNameFormat;
auto queuedMapping = isGenerateRegionsMapFrames ? Document::RegionFrameMapping::SET
: Document::RegionFrameMapping::PRESERVE;
manager.command_push({manager.selected,
[=](Manager&, Document& document)
{
if (queuedAnimationIndices.empty()) return;
document.anm2_snapshot(localize.get(EDIT_GENERATE_REGIONS_FROM_ANIMATIONS));
if (document.regions_generate_from_animations(queuedAnimationIndices, queuedFormat,
queuedMapping))
document.anm2_change(queuedMapping == Document::RegionFrameMapping::SET
? Document::ALL
: Document::SPRITESHEETS);
}});
auto queuedMapping = isGenerateRegionsMapFrames ? RegionFrameMapping::SET : RegionFrameMapping::PRESERVE;
manager.command_push(
{manager.selected, [=](Manager&, Document& document)
{
if (queuedAnimationIndices.empty()) return;
document.snapshots.anm2_push(localize.get(EDIT_GENERATE_REGIONS_FROM_ANIMATIONS));
if (document.anm2.regions_generate(queuedAnimationIndices, {}, queuedFormat, queuedMapping))
document.change(queuedMapping == RegionFrameMapping::SET ? Document::ALL : Document::SPRITESHEETS);
}});
generateRegionsPopup.close();
}
+20
View File
@@ -1,8 +1,12 @@
#pragma once
#include <format>
#include <string>
#include <vector>
#include "log.hpp"
#include "strings.hpp"
namespace anm2ed::imgui
{
class Toast
@@ -26,3 +30,19 @@ namespace anm2ed::imgui
}
extern anm2ed::imgui::Toasts toasts;
namespace anm2ed
{
template <class... Args> void toast_log(Level level, StringType type, Args&&... args)
{
auto format = [&](Language language) -> std::string
{
if constexpr (sizeof...(Args) == 0)
return localize.get(type, language);
else
return std::vformat(localize.get(type, language), std::make_format_args(args...));
};
toasts.push(format(localize.language));
logger.write(level, format(ENGLISH));
}
}
+12 -35
View File
@@ -306,16 +306,11 @@ namespace anm2ed::imgui
{
if (!renderTempFrames.empty())
{
toasts.push(std::vformat(localize.get(TOAST_EXPORT_RENDERED_FRAMES), std::make_format_args(pathString)));
logger.info(std::vformat(localize.get(TOAST_EXPORT_RENDERED_FRAMES, anm2ed::ENGLISH),
std::make_format_args(pathString)));
toast_log(Level::INFO, TOAST_EXPORT_RENDERED_FRAMES, pathString);
}
else
{
toasts.push(
std::vformat(localize.get(TOAST_EXPORT_RENDERED_FRAMES_FAILED), std::make_format_args(pathString)));
logger.error(std::vformat(localize.get(TOAST_EXPORT_RENDERED_FRAMES_FAILED, anm2ed::ENGLISH),
std::make_format_args(pathString)));
toast_log(Level::ERROR, TOAST_EXPORT_RENDERED_FRAMES_FAILED, pathString);
}
}
else if (type == render::SPRITESHEET)
@@ -328,16 +323,14 @@ namespace anm2ed::imgui
if (renderTempFrames.empty())
{
toasts.push(localize.get(TOAST_SPRITESHEET_NO_FRAMES));
logger.warning(localize.get(TOAST_SPRITESHEET_NO_FRAMES, anm2ed::ENGLISH));
toast_log(Level::WARNING, TOAST_SPRITESHEET_NO_FRAMES);
}
else
{
auto firstFrame = Texture(renderTempFrames.front());
if (firstFrame.size.x <= 0 || firstFrame.size.y <= 0 || firstFrame.pixels.empty())
{
toasts.push(localize.get(TOAST_SPRITESHEET_EMPTY));
logger.error(localize.get(TOAST_SPRITESHEET_EMPTY, anm2ed::ENGLISH));
toast_log(Level::ERROR, TOAST_SPRITESHEET_EMPTY);
}
else
{
@@ -368,16 +361,11 @@ namespace anm2ed::imgui
Texture spritesheetTexture(spritesheet.data(), spritesheetSize);
if (spritesheetTexture.write_png(path))
{
toasts.push(std::vformat(localize.get(TOAST_EXPORT_SPRITESHEET), std::make_format_args(pathString)));
logger.info(std::vformat(localize.get(TOAST_EXPORT_SPRITESHEET, anm2ed::ENGLISH),
std::make_format_args(pathString)));
toast_log(Level::INFO, TOAST_EXPORT_SPRITESHEET, pathString);
}
else
{
toasts.push(
std::vformat(localize.get(TOAST_EXPORT_SPRITESHEET_FAILED), std::make_format_args(pathString)));
logger.error(std::vformat(localize.get(TOAST_EXPORT_SPRITESHEET_FAILED, anm2ed::ENGLISH),
std::make_format_args(pathString)));
toast_log(Level::ERROR, TOAST_EXPORT_SPRITESHEET_FAILED, pathString);
}
}
}
@@ -398,16 +386,11 @@ namespace anm2ed::imgui
if (animation_render(ffmpegPath, path, renderTempFrames, audioStream, (render::Type)type, renderFrameRate))
{
toasts.push(std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION), std::make_format_args(pathString)));
logger.info(std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION, anm2ed::ENGLISH),
std::make_format_args(pathString)));
toast_log(Level::INFO, TOAST_EXPORT_RENDERED_ANIMATION, pathString);
}
else
{
toasts.push(
std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED), std::make_format_args(pathString)));
logger.error(std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED, anm2ed::ENGLISH),
std::make_format_args(pathString)));
toast_log(Level::ERROR, TOAST_EXPORT_RENDERED_ANIMATION_FAILED, pathString);
}
}
@@ -791,10 +774,7 @@ namespace anm2ed::imgui
}
auto pathString = path::to_utf8(settings.renderPath);
toasts.push(
std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED), std::make_format_args(pathString)));
logger.error(std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED, anm2ed::ENGLISH),
std::make_format_args(pathString)));
toast_log(Level::ERROR, TOAST_EXPORT_RENDERED_ANIMATION_FAILED, pathString);
manager.isRecording = false;
manager.isRecordingStart = false;
renderFrameIndex = 0;
@@ -1240,10 +1220,7 @@ namespace anm2ed::imgui
auto render_capture_fail = [&]()
{
auto pathString = path::to_utf8(settings.renderPath);
toasts.push(
std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED), std::make_format_args(pathString)));
logger.error(std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED, anm2ed::ENGLISH),
std::make_format_args(pathString)));
toast_log(Level::ERROR, TOAST_EXPORT_RENDERED_ANIMATION_FAILED, pathString);
if (renderType != render::PNGS) render_temp_cleanup(renderTempDirectory, renderTempFrames);
renderFrameSoundIDs.clear();
if (isRenderPreviewOverridden)
@@ -1407,7 +1384,7 @@ namespace anm2ed::imgui
{
auto queuedFrameReferences = selectedFrameReferences;
manager.command_push({manager.selected, [message, queuedFrameReferences](Manager&, Document& document)
{ document.frames_snapshot(localize.get(message), queuedFrameReferences); }});
{ document.snapshots.frames_push(localize.get(message), queuedFrameReferences); }});
};
auto frame_change_apply = [&](FrameChange frameChange, ChangeType changeType = ChangeType::ADJUST)
{
@@ -1450,7 +1427,7 @@ namespace anm2ed::imgui
auto frames_changed = [&]()
{
manager.command_push(
{manager.selected, [](Manager&, Document& document) { document.anm2_change(Document::FRAMES); }});
{manager.selected, [](Manager&, Document& document) { document.change(Document::FRAMES); }});
};
auto null_rect_change = [&](vec2 topLeft, vec2 rectSize)
{
+4 -4
View File
@@ -49,9 +49,9 @@ namespace anm2ed::imgui
auto item = document.anm2.element_get(itemReference);
if (!frame) return;
document.frames_snapshot(localize.get(message), {queuedReference});
document.snapshots.frames_push(localize.get(message), {queuedReference});
behavior(document, *frame, item, queuedReference);
document.anm2_change(Document::FRAMES);
document.change(Document::FRAMES);
}});
};
@@ -70,9 +70,9 @@ namespace anm2ed::imgui
if (!frame) return;
if (state == edit::START)
document.frames_snapshot(localize.get(message), {queuedReference});
document.snapshots.frames_push(localize.get(message), {queuedReference});
behavior(document, *frame, item, queuedReference);
if (state == edit::END) document.anm2_change(Document::FRAMES);
if (state == edit::END) document.change(Document::FRAMES);
}});
};
+11 -53
View File
@@ -124,57 +124,20 @@ namespace anm2ed::imgui
void shader_uniform_config_save(Document& document, Element& shaderElement, const resource::shader::Uniform& uniform)
{
auto config = shader_uniform_get(shaderElement, uniform.name);
if (!config)
{
config = &shaderElement.children.emplace_back(element_make(ElementType::UNIFORM));
config->name = uniform.name;
}
config->binding = std::string(resource::shader::uniform_binding_value_get(uniform.binding));
config->value = resource::shader::uniform_value_string_get(uniform);
if (uniform.binding == resource::shader::UNIFORM_BINDING_COMPONENTS)
{
for (int index = 0; index < (int)uniform.components.size(); ++index)
{
auto component = shader_uniform_component_get(*config, index);
if (!component)
{
component = &config->children.emplace_back(element_make(ElementType::COMPONENT));
component->index = index;
}
component->binding =
std::string(resource::shader::uniform_binding_value_get(uniform.components[index].binding));
component->value = std::format("{:.6g}", uniform.components[index].value);
}
}
else
std::erase_if(config->children, [](const Element& child) { return child.type == ElementType::COMPONENT; });
resource::shader::uniform_config_save(shaderElement, uniform);
document.change(Document::SHADERS);
}
int shader_uniform_component_count_get(resource::shader::UniformValueType type)
{
if (type == resource::shader::UNIFORM_VALUE_VEC2) return 2;
if (type == resource::shader::UNIFORM_VALUE_VEC3) return 3;
if (type == resource::shader::UNIFORM_VALUE_VEC4) return 4;
return 0;
}
void shader_uniform_components_from_value_set(resource::shader::Uniform& uniform)
{
uniform.components[0].value = uniform.value.x;
uniform.components[1].value = uniform.value.y;
uniform.components[2].value = uniform.value.z;
uniform.components[3].value = uniform.value.w;
for (int i = 0; i < (int)uniform.components.size(); ++i)
uniform.components[i].value = uniform.value[i];
}
void shader_uniform_value_from_components_set(resource::shader::Uniform& uniform)
{
uniform.value.x = uniform.components[0].value;
uniform.value.y = uniform.components[1].value;
uniform.value.z = uniform.components[2].value;
uniform.value.w = uniform.components[3].value;
for (int i = 0; i < (int)uniform.components.size(); ++i)
uniform.value[i] = uniform.components[i].value;
}
bool shader_uniform_value_update(resource::shader::Uniform& uniform)
@@ -227,7 +190,7 @@ namespace anm2ed::imgui
{
bool isChanged{};
constexpr const char* labels[] = {"X", "Y", "Z", "W"};
auto componentCount = shader_uniform_component_count_get(uniform.valueType);
auto componentCount = resource::shader::UNIFORM_VALUE_TYPE_INFOS[uniform.valueType].componentCount;
for (int index = 0; index < componentCount; ++index)
{
@@ -328,12 +291,7 @@ namespace anm2ed::imgui
if (ImGui::Begin(localize.get(LABEL_SHADERS_WINDOW), &settings.windowIsShaders))
{
auto document = manager.get();
if (!document)
{
ImGui::End();
return;
}
auto shaders = document->anm2.element_get(ElementType::SHADERS);
auto shaders = document ? document->anm2.element_get(ElementType::SHADERS) : nullptr;
if (!shaders)
{
ImGui::End();
@@ -354,12 +312,12 @@ namespace anm2ed::imgui
shader.id = element_child_next_id_get(*shaders, ElementType::SHADER);
shader.name = localize.get(TEXT_NEW_SHADER);
document.anm2_snapshot(localize.get(EDIT_ADD_SHADER));
document.snapshots.anm2_push(localize.get(EDIT_ADD_SHADER));
shaders->children.push_back(shader);
document.shader.selection = {shader.id};
document.shader.reference = shader.id;
newElementId = shader.id;
document.anm2_change(Document::SHADERS);
document.change(Document::SHADERS);
}});
};
@@ -372,7 +330,7 @@ namespace anm2ed::imgui
auto unused = document.anm2.element_unused(ElementType::SHADER);
if (unused.empty()) return;
document.anm2_snapshot(localize.get(EDIT_REMOVE_UNUSED_SHADERS));
document.snapshots.anm2_push(localize.get(EDIT_REMOVE_UNUSED_SHADERS));
for (auto id : unused)
{
element_child_id_erase(*shaders, ElementType::SHADER, id);
@@ -380,7 +338,7 @@ namespace anm2ed::imgui
if (document.shader.reference == id) document.shader.reference = -1;
if (popupShaderId == id) propertiesPopup.close();
}
document.anm2_change(Document::SHADERS);
document.change(Document::SHADERS);
}});
};
+51 -52
View File
@@ -238,7 +238,8 @@ namespace anm2ed::imgui
auto spritesheetModel = math::quad_model_get(viewTexture->size);
auto spritesheetTransform = transform * spritesheetModel;
if (baseTexture && baseTexture->is_valid()) texture_render(shaderTexture, baseTexture->id, spritesheetTransform);
if (baseTexture && baseTexture->is_valid())
texture_render(shaderTexture, baseTexture->id, spritesheetTransform);
if (isGrid) grid_render(shaderGrid, zoom, pan, gridSize, gridOffset, gridColor);
@@ -431,9 +432,8 @@ namespace anm2ed::imgui
{
auto message = std::string(localize.get(messageType));
auto queuedFrameReferences = frameReferences;
manager.command_push({manager.selected,
[message, queuedFrameReferences](Manager&, Document& document)
{ document.frames_snapshot(message, queuedFrameReferences); }});
manager.command_push({manager.selected, [message, queuedFrameReferences](Manager&, Document& document)
{ document.snapshots.frames_push(message, queuedFrameReferences); }});
};
auto region_snapshot_push = [&](StringType messageType, const std::set<int>& regionIds)
{
@@ -442,42 +442,41 @@ namespace anm2ed::imgui
auto queuedRegionIds = regionIds;
manager.command_push({manager.selected,
[message, queuedSpritesheet, queuedRegionIds](Manager&, Document& document)
{ document.regions_snapshot(message, queuedSpritesheet, queuedRegionIds); }});
{ document.snapshots.regions_push(message, queuedSpritesheet, queuedRegionIds); }});
};
auto texture_snapshot_push = [&](StringType messageType)
{
auto message = std::string(localize.get(messageType));
manager.command_push(
{manager.selected, [message](Manager&, Document& document) { document.textures_snapshot(message); }});
manager.command_push({manager.selected, [message](Manager&, Document& document)
{ document.snapshots.textures_push(message); }});
};
auto document_change_push = [&](Document::ChangeType changeType)
{
manager.command_push(
{manager.selected, [changeType](Manager&, Document& document) { document.anm2_change(changeType); }});
{manager.selected, [changeType](Manager&, Document& document) { document.change(changeType); }});
};
auto frame_change_apply_to = [&](const std::set<Reference>& frameReferences, FrameChange frameChange,
ChangeType changeType = ChangeType::ADJUST)
{
auto queuedFrameReferences = frameReferences;
manager.command_push(
{manager.selected, [=](Manager&, Document& document)
{
std::map<Reference, std::set<int>> groupedFrames{};
for (auto frameReference : queuedFrameReferences)
{
auto itemReference = frameReference;
itemReference.frameIndex = -1;
groupedFrames[itemReference].insert(frameReference.frameIndex);
}
manager.command_push({manager.selected, [=](Manager&, Document& document)
{
std::map<Reference, std::set<int>> groupedFrames{};
for (auto frameReference : queuedFrameReferences)
{
auto itemReference = frameReference;
itemReference.frameIndex = -1;
groupedFrames[itemReference].insert(frameReference.frameIndex);
}
for (auto& [itemReference, itemFrames] : groupedFrames)
{
auto itemType = static_cast<ItemType>(itemReference.itemType);
auto item = document.anm2.element_get(itemReference);
if (!item) continue;
frames_change(*item, frameChange, itemType, changeType, itemFrames);
}
}});
for (auto& [itemReference, itemFrames] : groupedFrames)
{
auto itemType = static_cast<ItemType>(itemReference.itemType);
auto item = document.anm2.element_get(itemReference);
if (!item) continue;
frames_change(*item, frameChange, itemType, changeType, itemFrames);
}
}});
};
auto frame_change_apply = [&](FrameChange frameChange, ChangeType changeType = ChangeType::ADJUST)
{ frame_change_apply_to(selectedFrameReferences, frameChange, changeType); };
@@ -486,29 +485,28 @@ namespace anm2ed::imgui
{
auto queuedReference = editReference;
auto queuedFrameReferences = frameReferences;
manager.command_push(
{manager.selected, [=](Manager&, Document& document)
{
if (queuedReference.frameIndex < 0) return;
auto frame = document.anm2.element_get(queuedReference);
if (!frame) return;
manager.command_push({manager.selected, [=](Manager&, Document& document)
{
if (queuedReference.frameIndex < 0) return;
auto frame = document.anm2.element_get(queuedReference);
if (!frame) return;
std::map<Reference, std::set<int>> groupedFrames{};
for (auto frameReference : queuedFrameReferences)
{
auto itemReference = frameReference;
itemReference.frameIndex = -1;
groupedFrames[itemReference].insert(frameReference.frameIndex);
}
std::map<Reference, std::set<int>> groupedFrames{};
for (auto frameReference : queuedFrameReferences)
{
auto itemReference = frameReference;
itemReference.frameIndex = -1;
groupedFrames[itemReference].insert(frameReference.frameIndex);
}
for (auto& [itemReference, itemFrames] : groupedFrames)
{
auto itemType = static_cast<ItemType>(itemReference.itemType);
auto item = document.anm2.element_get(itemReference);
if (!item) continue;
frames_change(*item, frameChangeGet(*frame), itemType, changeType, itemFrames);
}
}});
for (auto& [itemReference, itemFrames] : groupedFrames)
{
auto itemType = static_cast<ItemType>(itemReference.itemType);
auto item = document.anm2.element_get(itemReference);
if (!item) continue;
frames_change(*item, frameChangeGet(*frame), itemType, changeType, itemFrames);
}
}});
};
auto frame_crop_normalize_apply_to =
[&](const std::set<Reference>& frameReferences, bool isSnap, ivec2 snapGridSize, ivec2 snapGridOffset)
@@ -639,8 +637,7 @@ namespace anm2ed::imgui
{
auto queuedSpritesheet = referenceSpritesheet;
manager.command_push(
{manager.selected, [=](Manager&, Document& document)
{ document.texture_change(queuedSpritesheet); }});
{manager.selected, [=](Manager&, Document& document) { document.texture_change(queuedSpritesheet); }});
};
auto region_selection_set = [&](int id)
@@ -808,7 +805,8 @@ namespace anm2ed::imgui
if (isEnd) document_change_push(Document::FRAMES);
break;
case tool::CROP:
if ((isRegionEditTarget || isRegionInUse || selectedFrameToolReferences.empty()) && !regionSelection.empty())
if ((isRegionEditTarget || isRegionInUse || selectedFrameToolReferences.empty()) &&
!regionSelection.empty())
{
if (!spritesheet || regionSelection.empty()) break;
if (isBegin) region_snapshot_push(EDIT_REGION_CROP, regionSelection);
@@ -1022,8 +1020,9 @@ namespace anm2ed::imgui
actions_undo_redo_add(actions, manager, document);
actions.separator();
actions.add(ACTION_CENTER_VIEW, []() { return true; }, center_view);
actions.add(ACTION_FIT_VIEW, [&]()
{ return (baseTexture && baseTexture->is_valid()) || (texture && texture->is_valid()); }, fit_view);
actions.add(
ACTION_FIT_VIEW,
[&]() { return (baseTexture && baseTexture->is_valid()) || (texture && texture->is_valid()); }, fit_view);
actions.separator();
actions.add(ACTION_ZOOM_IN, []() { return true; }, zoom_in);
actions.add(ACTION_ZOOM_OUT, []() { return true; }, zoom_out);
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+24 -23
View File
@@ -36,11 +36,10 @@ namespace anm2ed::imgui
{
auto targetFrames = makeManyRegionReferences;
auto format = settings.generateRegionNameFormat;
auto mapping = isMakeManyRegionsMapFrames ? Document::RegionFrameMapping::SET
: Document::RegionFrameMapping::PRESERVE;
auto mapping = isMakeManyRegionsMapFrames ? RegionFrameMapping::SET : RegionFrameMapping::PRESERVE;
edit_command_push(EDIT_GENERATE_REGIONS_FROM_ANIMATIONS, Document::ALL,
[=, this](Manager&, Document& document) mutable
{ document.regions_generate_from_frames(targetFrames, format, mapping); });
{ document.anm2.regions_generate({}, targetFrames, format, mapping); });
makeManyRegionsPopup.close();
}
@@ -178,16 +177,17 @@ namespace anm2ed::imgui
if (!selectedFrames.empty())
{
if (!isShortenChordHeld) frames_snapshot_command_push(EDIT_SHORTEN_FRAME, selectedFrames);
command_push([=, this](Manager&, Document& document)
{
for (auto frameReference : selectedFrames)
{
auto frame = command_frame_get(document, frameReference);
if (!frame) continue;
frame->duration = std::max(FRAME_DURATION_MIN, frame->duration - 1);
}
document.anm2_change(Document::FRAMES);
});
command_push(
[=, this](Manager&, Document& document)
{
for (auto frameReference : selectedFrames)
{
auto frame = command_frame_get(document, frameReference);
if (!frame) continue;
frame->duration = std::max(FRAME_DURATION_MIN, frame->duration - 1);
}
document.change(Document::FRAMES);
});
}
}
isShortenChordHeld = isShortenFrame;
@@ -203,16 +203,17 @@ namespace anm2ed::imgui
if (!selectedFrames.empty())
{
if (!isExtendChordHeld) frames_snapshot_command_push(EDIT_EXTEND_FRAME, selectedFrames);
command_push([=, this](Manager&, Document& document)
{
for (auto frameReference : selectedFrames)
{
auto frame = command_frame_get(document, frameReference);
if (!frame) continue;
frame->duration = std::min(FRAME_DURATION_MAX, frame->duration + 1);
}
document.anm2_change(Document::FRAMES);
});
command_push(
[=, this](Manager&, Document& document)
{
for (auto frameReference : selectedFrames)
{
auto frame = command_frame_get(document, frameReference);
if (!frame) continue;
frame->duration = std::min(FRAME_DURATION_MAX, frame->duration + 1);
}
document.change(Document::FRAMES);
});
}
}
isExtendChordHeld = isExtendFrame;
File diff suppressed because it is too large. Load diff
@@ -413,7 +413,7 @@ namespace anm2ed::imgui::wizard
groupedFrames[itemReference].insert(frameReference.frameIndex);
}
document.anm2_snapshot(localize.get(EDIT_CHANGE_FRAME_PROPERTIES));
document.snapshots.anm2_push(localize.get(EDIT_CHANGE_FRAME_PROPERTIES));
for (auto& [itemReference, selection] : groupedFrames)
{
auto item = anm2.element_get(itemReference);
@@ -421,13 +421,13 @@ namespace anm2ed::imgui::wizard
frames_change(*item, frameChange, static_cast<ItemType>(itemReference.itemType),
changeType, selection);
}
document.anm2_change(Document::FRAMES);
document.change(Document::FRAMES);
return;
}
if (queuedIsItemsDestination)
{
document.anm2_snapshot(localize.get(EDIT_CHANGE_FRAME_PROPERTIES));
document.snapshots.anm2_push(localize.get(EDIT_CHANGE_FRAME_PROPERTIES));
for (auto itemReference : queuedItemReferences)
{
if (itemReference.itemType == TRIGGER) continue;
@@ -438,11 +438,11 @@ namespace anm2ed::imgui::wizard
frames_change(*item, frameChange, static_cast<ItemType>(itemReference.itemType),
changeType, selection);
}
document.anm2_change(Document::FRAMES);
document.change(Document::FRAMES);
return;
}
document.anm2_snapshot(localize.get(EDIT_CHANGE_FRAME_PROPERTIES));
document.snapshots.anm2_push(localize.get(EDIT_CHANGE_FRAME_PROPERTIES));
for (auto animationIndex : queuedAnimations)
{
auto animation = anm2.element_get(ElementType::ANIMATION, animationIndex);
@@ -459,8 +459,7 @@ namespace anm2ed::imgui::wizard
if (queuedIsLayers)
{
auto layerAnimations =
child_first_get(*animation, ElementType::LAYER_ANIMATIONS);
auto layerAnimations = child_first_get(*animation, ElementType::LAYER_ANIMATIONS);
if (layerAnimations)
{
auto item_change = [&](auto&& self, Element& item) -> void
@@ -484,8 +483,7 @@ namespace anm2ed::imgui::wizard
if (queuedIsNulls)
{
auto nullAnimations =
child_first_get(*animation, ElementType::NULL_ANIMATIONS);
auto nullAnimations = child_first_get(*animation, ElementType::NULL_ANIMATIONS);
if (nullAnimations)
{
auto item_change = [&](auto&& self, Element& item) -> void
@@ -507,7 +505,7 @@ namespace anm2ed::imgui::wizard
}
}
}
document.anm2_change(Document::FRAMES);
document.change(Document::FRAMES);
}});
isChanged = true;
};
@@ -1,12 +1,12 @@
#include "generate_animation_from_grid.hpp"
#include <algorithm>
#include <format>
#include "math.hpp"
#include "types.hpp"
#include "util/imgui/draw.hpp"
#include "util/imgui/input.hpp"
#include "util/imgui/layout.hpp"
#include <algorithm>
#include <format>
using namespace anm2ed::types;
using namespace anm2ed::util;
@@ -102,10 +102,10 @@ namespace anm2ed::imgui::wizard
{
auto uvMin = frame.crop / textureSize;
auto uvMax = (frame.crop + frame.size) / textureSize;
mat4 transform = transform_get(zoom) *
math::quad_model_get(frame.size, frame.position, frame.pivot,
math::percent_to_unit(frame.scale), frame.rotation,
math::percent_to_unit(frame.shear));
mat4 transform =
transform_get(zoom) * math::quad_model_get(frame.size, frame.position, frame.pivot,
math::percent_to_unit(frame.scale), frame.rotation,
math::percent_to_unit(frame.shear));
auto vertices = math::uv_vertices_get(uvMin, uvMax);
texture_render(shaderTexture, sourceTexture->id, transform, frame.tint, frame.colorOffset, vertices.data());
@@ -144,64 +144,60 @@ namespace anm2ed::imgui::wizard
auto queuedIsMakeRegions = isMakeRegions;
auto queuedRegionNameFormat = regionNameFormat;
manager.command_push({manager.selected,
[=](Manager&, Document& document)
{
auto region_name_get = [](const std::string& format, int frameNumber)
{
try
{
return std::vformat(format, std::make_format_args(frameNumber));
}
catch (const std::format_error&)
{
return format;
}
};
manager.command_push(
{manager.selected, [=](Manager&, Document& document)
{
auto region_name_get = [](const std::string& format, int frameNumber)
{
try
{
return std::vformat(format, std::make_format_args(frameNumber));
}
catch (const std::format_error&)
{
return format;
}
};
bool isChanged{};
bool isRegionsChanged{};
for (auto queuedReference : queuedLayerReferences)
{
auto item = document.anm2.element_get(queuedReference);
auto animation =
document.anm2.element_get(ElementType::ANIMATION, queuedReference.animationIndex);
auto layer = document.anm2.element_get(ElementType::LAYER_ELEMENT,
queuedReference.itemID);
auto spritesheet = layer ? document.anm2.element_get(ElementType::SPRITESHEET,
layer->spritesheetId)
: nullptr;
if (!item || !animation) continue;
bool isChanged{};
bool isRegionsChanged{};
for (auto queuedReference : queuedLayerReferences)
{
auto item = document.anm2.element_get(queuedReference);
auto animation = document.anm2.element_get(ElementType::ANIMATION, queuedReference.animationIndex);
auto layer = document.anm2.element_get(ElementType::LAYER_ELEMENT, queuedReference.itemID);
auto spritesheet =
layer ? document.anm2.element_get(ElementType::SPRITESHEET, layer->spritesheetId) : nullptr;
if (!item || !animation) continue;
if (!isChanged)
{
document.anm2_snapshot(localize.get(EDIT_GENERATE_ANIMATION_FROM_GRID));
isChanged = true;
}
auto frameIndexStart = (int)item->children.size();
frames_generate_from_grid(*item, queuedStartPosition, queuedSize, queuedPivot,
queuedColumns, queuedCount, queuedDelay);
if (queuedIsMakeRegions && spritesheet)
for (int frameIndex = frameIndexStart; frameIndex < (int)item->children.size();
++frameIndex)
{
auto& frame = item->children[frameIndex];
if (frame.type != ElementType::FRAME) continue;
if (!isChanged)
{
document.snapshots.anm2_push(localize.get(EDIT_GENERATE_ANIMATION_FROM_GRID));
isChanged = true;
}
auto frameIndexStart = (int)item->children.size();
frames_generate_from_grid(*item, queuedStartPosition, queuedSize, queuedPivot, queuedColumns,
queuedCount, queuedDelay);
if (queuedIsMakeRegions && spritesheet)
for (int frameIndex = frameIndexStart; frameIndex < (int)item->children.size(); ++frameIndex)
{
auto& frame = item->children[frameIndex];
if (frame.type != ElementType::FRAME) continue;
auto region = element_make(ElementType::REGION);
region.id = element_child_next_id_get(*spritesheet, ElementType::REGION);
region.name = region_name_get(queuedRegionNameFormat, frameIndex - frameIndexStart);
region.crop = frame.crop;
region.size = frame.size;
region.pivot = frame.pivot;
frame.regionId = region.id;
spritesheet->children.push_back(region);
isRegionsChanged = true;
}
animation->frameNum = animation_length_get(*animation);
}
if (isChanged) document.anm2_change(isRegionsChanged ? Document::ALL : Document::FRAMES);
}});
auto region = element_make(ElementType::REGION);
region.id = element_child_next_id_get(*spritesheet, ElementType::REGION);
region.name = region_name_get(queuedRegionNameFormat, frameIndex - frameIndexStart);
region.crop = frame.crop;
region.size = frame.size;
region.pivot = frame.pivot;
frame.regionId = region.id;
spritesheet->children.push_back(region);
isRegionsChanged = true;
}
animation->frameNum = animation_length_get(*animation);
}
if (isChanged) document.change(isRegionsChanged ? Document::ALL : Document::FRAMES);
}});
isEnd = true;
}
ImGui::EndDisabled();
+7 -11
View File
@@ -37,7 +37,8 @@ namespace anm2ed::imgui::wizard
{
return frameReference.animationIndex != reference.animationIndex ||
frameReference.itemType != reference.itemType || frameReference.itemID != reference.itemID ||
frameReference.groupType != reference.groupType || frameReference.groupId != reference.groupId;
frameReference.groupType != reference.groupType ||
frameReference.groupId != reference.groupId;
});
if (!frameReferences.empty())
{
@@ -283,8 +284,7 @@ namespace anm2ed::imgui::wizard
{
if (!ffmpeg_is_valid())
{
toasts.push(localize.get(TOAST_INVALID_FFMPEG));
logger.error(localize.get(TOAST_INVALID_FFMPEG, anm2ed::ENGLISH));
toast_log(Level::ERROR, TOAST_INVALID_FFMPEG);
return false;
}
return true;
@@ -295,8 +295,7 @@ namespace anm2ed::imgui::wizard
auto formatString = path::to_utf8(format);
if (!formatString.contains("{}"))
{
toasts.push(localize.get(TOAST_PNG_FORMAT_INVALID));
logger.error(localize.get(TOAST_PNG_FORMAT_INVALID, anm2ed::ENGLISH));
toast_log(Level::ERROR, TOAST_PNG_FORMAT_INVALID);
return false;
}
return true;
@@ -306,8 +305,7 @@ namespace anm2ed::imgui::wizard
{
if (path.empty())
{
toasts.push(localize.get(TOAST_RENDER_PATH_EMPTY));
logger.error(localize.get(TOAST_RENDER_PATH_EMPTY, anm2ed::ENGLISH));
toast_log(Level::ERROR, TOAST_RENDER_PATH_EMPTY);
return false;
}
return true;
@@ -317,8 +315,7 @@ namespace anm2ed::imgui::wizard
{
if (!path::ensure_directory(path))
{
toasts.push(localize.get(TOAST_PNG_DIRECTORY_INVALID));
logger.error(localize.get(TOAST_PNG_DIRECTORY_INVALID, anm2ed::ENGLISH));
toast_log(Level::ERROR, TOAST_PNG_DIRECTORY_INVALID);
return false;
}
return true;
@@ -328,8 +325,7 @@ namespace anm2ed::imgui::wizard
{
if (rows <= 0 && columns <= 0)
{
toasts.push(localize.get(TOAST_RENDER_PATH_EMPTY));
logger.error(localize.get(TOAST_RENDER_PATH_EMPTY, anm2ed::ENGLISH));
toast_log(Level::ERROR, TOAST_RENDER_PATH_EMPTY);
return false;
}
return true;