pivot fix
This commit is contained in:
+1
-1
@@ -262,7 +262,7 @@ namespace anm2ed
|
|||||||
out.interpolation = interpolation_read(element);
|
out.interpolation = interpolation_read(element);
|
||||||
out.origin = origin_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::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)
|
bool bake_attributes_read(const XMLElement* element, Interpolation& interpolation, int& bakeDelay)
|
||||||
|
|||||||
+1
-1
@@ -552,7 +552,7 @@ namespace anm2ed
|
|||||||
if (region->origin == Origin::TOP_LEFT)
|
if (region->origin == Origin::TOP_LEFT)
|
||||||
region->pivot = {};
|
region->pivot = {};
|
||||||
else if (region->origin == Origin::CENTER)
|
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
|
else
|
||||||
region->pivot -= region->crop - previousCrop;
|
region->pivot -= region->crop - previousCrop;
|
||||||
isChanged = true;
|
isChanged = true;
|
||||||
|
|||||||
@@ -224,7 +224,12 @@ namespace anm2ed::imgui
|
|||||||
if (ImGui::Button(localize.get(BASIC_NO), widgetSize))
|
if (ImGui::Button(localize.get(BASIC_NO), widgetSize))
|
||||||
{
|
{
|
||||||
auto index = closeDocumentIndex;
|
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();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -725,8 +725,10 @@ namespace anm2ed::imgui
|
|||||||
if (isMouseDown)
|
if (isMouseDown)
|
||||||
{
|
{
|
||||||
auto frameCrop = ivec2(frame->crop);
|
auto frameCrop = ivec2(frame->crop);
|
||||||
frame_change_apply({.pivotX = (float)(int)(mousePos.x - frameCrop.x),
|
auto pivot = mousePos - vec2(frameCrop);
|
||||||
.pivotY = (float)(int)(mousePos.y - frameCrop.y),
|
if (isGridSnap) pivot = vec2(ivec2(pivot));
|
||||||
|
frame_change_apply({.pivotX = pivot.x,
|
||||||
|
.pivotY = pivot.y,
|
||||||
.cropX = (float)frameCrop.x,
|
.cropX = (float)frameCrop.x,
|
||||||
.cropY = (float)frameCrop.y});
|
.cropY = (float)frameCrop.y});
|
||||||
}
|
}
|
||||||
@@ -735,10 +737,6 @@ namespace anm2ed::imgui
|
|||||||
if (isUpPressed) frame_change_apply({.pivotY = step}, ChangeType::SUBTRACT);
|
if (isUpPressed) frame_change_apply({.pivotY = step}, ChangeType::SUBTRACT);
|
||||||
if (isDownPressed) frame_change_apply({.pivotY = step}, ChangeType::ADD);
|
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 (isDuring)
|
||||||
{
|
{
|
||||||
if (ImGui::BeginTooltip())
|
if (ImGui::BeginTooltip())
|
||||||
|
|||||||
@@ -66,6 +66,19 @@ namespace anm2ed::imgui
|
|||||||
return container ? element_child_id_get(*container, window.elementType, key) : nullptr;
|
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)
|
int window_track_id_get(const Element& item, ElementType trackType)
|
||||||
{
|
{
|
||||||
return trackType == ElementType::LAYER_ANIMATION ? item.layerId : item.nullId;
|
return trackType == ElementType::LAYER_ANIMATION ? item.layerId : item.nullId;
|
||||||
@@ -1294,9 +1307,9 @@ namespace anm2ed::imgui
|
|||||||
if (!spritesheet || selection.empty()) return;
|
if (!spritesheet || selection.empty()) return;
|
||||||
|
|
||||||
std::string clipboardText{};
|
std::string clipboardText{};
|
||||||
for (auto& id : selection)
|
for (auto& region : spritesheet->children)
|
||||||
if (auto region = element_child_id_get(*spritesheet, ElementType::REGION, id))
|
if (region.type == ElementType::REGION && selection.contains(region.id))
|
||||||
clipboardText += element_to_string(*region);
|
clipboardText += element_to_string(region);
|
||||||
clipboard.set(clipboardText);
|
clipboard.set(clipboardText);
|
||||||
};
|
};
|
||||||
window.paste = [](Window& window, Manager&, Settings&, Document& document, Clipboard& clipboard)
|
window.paste = [](Window& window, Manager&, Settings&, Document& document, Clipboard& clipboard)
|
||||||
@@ -1309,6 +1322,7 @@ namespace anm2ed::imgui
|
|||||||
auto& selection = document.region.selection;
|
auto& selection = document.region.selection;
|
||||||
auto& reference = document.region.reference;
|
auto& reference = document.region.reference;
|
||||||
auto maxRegionIdBefore = element_child_max_id_get(*spritesheet, ElementType::REGION);
|
auto maxRegionIdBefore = element_child_max_id_get(*spritesheet, ElementType::REGION);
|
||||||
|
auto insertIndex = region_insert_index_get(*spritesheet, document.region);
|
||||||
auto pasted = anm2;
|
auto pasted = anm2;
|
||||||
std::string errorString{};
|
std::string errorString{};
|
||||||
if (pasted.regions_deserialize(spritesheetReference, clipboard.get(), true, &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);
|
auto maxRegionIdAfter = element_child_max_id_get(*pastedSpritesheet, ElementType::REGION);
|
||||||
if (maxRegionIdAfter > maxRegionIdBefore)
|
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;
|
window.newElementId = maxRegionIdAfter;
|
||||||
selection = {maxRegionIdAfter};
|
selection = {maxRegionIdAfter};
|
||||||
reference = maxRegionIdAfter;
|
reference = maxRegionIdAfter;
|
||||||
@@ -1770,7 +1790,7 @@ namespace anm2ed::imgui
|
|||||||
if (region.origin == Origin::TOP_LEFT)
|
if (region.origin == Origin::TOP_LEFT)
|
||||||
region.pivot = {};
|
region.pivot = {};
|
||||||
else if (region.origin == Origin::CENTER)
|
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();
|
ImGui::EndChild();
|
||||||
|
|
||||||
@@ -1802,7 +1822,8 @@ namespace anm2ed::imgui
|
|||||||
added.type = ElementType::REGION;
|
added.type = ElementType::REGION;
|
||||||
added.tag = "Region";
|
added.tag = "Region";
|
||||||
added.id = id;
|
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};
|
selection = {id};
|
||||||
reference = id;
|
reference = id;
|
||||||
window.newElementId = id;
|
window.newElementId = id;
|
||||||
|
|||||||
@@ -178,6 +178,17 @@ namespace anm2ed
|
|||||||
autosave_files_write();
|
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)
|
void Manager::close(int index)
|
||||||
{
|
{
|
||||||
if (!vector::in_bounds(documents, index)) return;
|
if (!vector::in_bounds(documents, index)) return;
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ namespace anm2ed
|
|||||||
bool save(int, const std::filesystem::path& = {}, Options = {});
|
bool save(int, const std::filesystem::path& = {}, Options = {});
|
||||||
bool save(const std::filesystem::path& = {}, Options = {});
|
bool save(const std::filesystem::path& = {}, Options = {});
|
||||||
void autosave(Document&, Options = {});
|
void autosave(Document&, Options = {});
|
||||||
|
void autosave_file_clear(int);
|
||||||
void set(int);
|
void set(int);
|
||||||
void close(int);
|
void close(int);
|
||||||
void layer_properties_open(int = -1);
|
void layer_properties_open(int = -1);
|
||||||
|
|||||||
Reference in New Issue
Block a user