pivot fix

This commit is contained in:
2026-06-13 14:56:02 -04:00
parent 71e799f536
commit 0ea0afe1e3
7 changed files with 50 additions and 14 deletions
+1 -1
View File
@@ -262,7 +262,7 @@ namespace anm2ed
out.interpolation = interpolation_read(element);
out.origin = origin_read(element);
if (out.type == ElementType::REGION && out.origin == Origin::TOP_LEFT) out.pivot = {};
if (out.type == ElementType::REGION && out.origin == Origin::CENTER) out.pivot = glm::ivec2(out.size / 2.0f);
if (out.type == ElementType::REGION && out.origin == Origin::CENTER) out.pivot = out.size * 0.5f;
}
bool bake_attributes_read(const XMLElement* element, Interpolation& interpolation, int& bakeDelay)
+1 -1
View File
@@ -552,7 +552,7 @@ namespace anm2ed
if (region->origin == Origin::TOP_LEFT)
region->pivot = {};
else if (region->origin == Origin::CENTER)
region->pivot = {static_cast<int>(region->size.x / 2.0f), static_cast<int>(region->size.y / 2.0f)};
region->pivot = region->size * 0.5f;
else
region->pivot -= region->crop - previousCrop;
isChanged = true;
+6 -1
View File
@@ -224,7 +224,12 @@ namespace anm2ed::imgui
if (ImGui::Button(localize.get(BASIC_NO), widgetSize))
{
auto index = closeDocumentIndex;
manager.command_push({.runManager = [index](Manager& manager) { manager.close(index); }});
manager.command_push({.runManager =
[index](Manager& manager)
{
manager.autosave_file_clear(index);
manager.close(index);
}});
close();
}
+4 -6
View File
@@ -725,8 +725,10 @@ namespace anm2ed::imgui
if (isMouseDown)
{
auto frameCrop = ivec2(frame->crop);
frame_change_apply({.pivotX = (float)(int)(mousePos.x - frameCrop.x),
.pivotY = (float)(int)(mousePos.y - frameCrop.y),
auto pivot = mousePos - vec2(frameCrop);
if (isGridSnap) pivot = vec2(ivec2(pivot));
frame_change_apply({.pivotX = pivot.x,
.pivotY = pivot.y,
.cropX = (float)frameCrop.x,
.cropY = (float)frameCrop.y});
}
@@ -735,10 +737,6 @@ namespace anm2ed::imgui
if (isUpPressed) frame_change_apply({.pivotY = step}, ChangeType::SUBTRACT);
if (isDownPressed) frame_change_apply({.pivotY = step}, ChangeType::ADD);
frame_change_from_current_apply(
[](const Element& frame)
{ return FrameChange{.pivotX = (float)(int)frame.pivot.x, .pivotY = (float)(int)frame.pivot.y}; });
if (isDuring)
{
if (ImGui::BeginTooltip())
+26 -5
View File
@@ -66,6 +66,19 @@ namespace anm2ed::imgui
return container ? element_child_id_get(*container, window.elementType, key) : nullptr;
}
int region_insert_index_get(const Element& spritesheet, const Storage& storage)
{
int index = (int)spritesheet.children.size();
for (int i = 0; i < (int)spritesheet.children.size(); i++)
{
const auto& child = spritesheet.children[i];
if (child.type != ElementType::REGION) continue;
if (storage.selection.contains(child.id) || (storage.selection.empty() && storage.reference == child.id))
index = i + 1;
}
return index;
}
int window_track_id_get(const Element& item, ElementType trackType)
{
return trackType == ElementType::LAYER_ANIMATION ? item.layerId : item.nullId;
@@ -1294,9 +1307,9 @@ namespace anm2ed::imgui
if (!spritesheet || selection.empty()) return;
std::string clipboardText{};
for (auto& id : selection)
if (auto region = element_child_id_get(*spritesheet, ElementType::REGION, id))
clipboardText += element_to_string(*region);
for (auto& region : spritesheet->children)
if (region.type == ElementType::REGION && selection.contains(region.id))
clipboardText += element_to_string(region);
clipboard.set(clipboardText);
};
window.paste = [](Window& window, Manager&, Settings&, Document& document, Clipboard& clipboard)
@@ -1309,6 +1322,7 @@ namespace anm2ed::imgui
auto& selection = document.region.selection;
auto& reference = document.region.reference;
auto maxRegionIdBefore = element_child_max_id_get(*spritesheet, ElementType::REGION);
auto insertIndex = region_insert_index_get(*spritesheet, document.region);
auto pasted = anm2;
std::string errorString{};
if (pasted.regions_deserialize(spritesheetReference, clipboard.get(), true, &errorString))
@@ -1320,6 +1334,12 @@ namespace anm2ed::imgui
auto maxRegionIdAfter = element_child_max_id_get(*pastedSpritesheet, ElementType::REGION);
if (maxRegionIdAfter > maxRegionIdBefore)
{
std::vector<int> pastedIndices{};
for (int i = 0; i < (int)pastedSpritesheet->children.size(); i++)
if (pastedSpritesheet->children[i].type == ElementType::REGION &&
pastedSpritesheet->children[i].id > maxRegionIdBefore)
pastedIndices.push_back(i);
vector::move_indices_to_position(pastedSpritesheet->children, pastedIndices, insertIndex);
window.newElementId = maxRegionIdAfter;
selection = {maxRegionIdAfter};
reference = maxRegionIdAfter;
@@ -1770,7 +1790,7 @@ namespace anm2ed::imgui
if (region.origin == Origin::TOP_LEFT)
region.pivot = {};
else if (region.origin == Origin::CENTER)
region.pivot = {(int)(region.size.x / 2.0f), (int)(region.size.y / 2.0f)};
region.pivot = region.size * 0.5f;
}
ImGui::EndChild();
@@ -1802,7 +1822,8 @@ namespace anm2ed::imgui
added.type = ElementType::REGION;
added.tag = "Region";
added.id = id;
spritesheet->children.push_back(added);
auto insertIndex = region_insert_index_get(*spritesheet, document.region);
spritesheet->children.insert(spritesheet->children.begin() + insertIndex, added);
selection = {id};
reference = id;
window.newElementId = id;
+11
View File
@@ -178,6 +178,17 @@ namespace anm2ed
autosave_files_write();
}
void Manager::autosave_file_clear(int index)
{
auto document = get(index);
if (!document) return;
auto autosavePath = document->autosave_path_get();
autosaveFiles.erase(std::remove(autosaveFiles.begin(), autosaveFiles.end(), autosavePath), autosaveFiles.end());
autosave_file_remove(autosavePath);
autosave_files_write();
}
void Manager::close(int index)
{
if (!vector::in_bounds(documents, index)) return;
+1
View File
@@ -87,6 +87,7 @@ namespace anm2ed
bool save(int, const std::filesystem::path& = {}, Options = {});
bool save(const std::filesystem::path& = {}, Options = {});
void autosave(Document&, Options = {});
void autosave_file_clear(int);
void set(int);
void close(int);
void layer_properties_open(int = -1);