From 233b2139fd6d1bdaaee2cdfebf9c16a4ebd5f4f2 Mon Sep 17 00:00:00 2001 From: shweet Date: Sun, 28 Dec 2025 14:29:36 -0500 Subject: [PATCH] change all frame properties adjustments --- src/anm2/frame.h | 2 ++ src/anm2/item.cpp | 13 +++++++------ src/anm2/item.h | 2 +- src/imgui/window/animation_preview.cpp | 2 +- src/imgui/window/spritesheet_editor.cpp | 2 +- src/imgui/wizard/change_all_frame_properties.cpp | 12 +++++++++++- src/settings.h | 4 ++++ 7 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/anm2/frame.h b/src/anm2/frame.h index 9b2ee17..c03676a 100644 --- a/src/anm2/frame.h +++ b/src/anm2/frame.h @@ -71,6 +71,8 @@ namespace anm2ed::anm2 std::optional tintG{}; std::optional tintB{}; std::optional tintA{}; + std::optional isFlipX{}; + std::optional isFlipY{}; }; } diff --git a/src/anm2/item.cpp b/src/anm2/item.cpp index ba651d3..75d7e40 100644 --- a/src/anm2/item.cpp +++ b/src/anm2/item.cpp @@ -126,16 +126,14 @@ namespace anm2ed::anm2 return frame; } - void Item::frames_change(FrameChange change, ChangeType type, int start, int numberFrames) + void Item::frames_change(FrameChange change, ChangeType type, std::set& selection) { - auto useStart = numberFrames > -1 ? start : 0; - auto end = numberFrames > -1 ? start + numberFrames : (int)frames.size(); - end = glm::clamp(end, start, (int)frames.size()); - const auto clamp_identity = [](auto value) { return value; }; const auto clamp01 = [](auto value) { return glm::clamp(value, 0.0f, 1.0f); }; const auto clamp_duration = [](int value) { return std::max(FRAME_DURATION_MIN, value); }; + if (selection.empty()) return; + auto apply_scalar_with_clamp = [&](auto& target, const auto& optionalValue, auto clampFunc) { if (!optionalValue) return; @@ -165,12 +163,15 @@ namespace anm2ed::anm2 auto apply_scalar = [&](auto& target, const auto& optionalValue) { apply_scalar_with_clamp(target, optionalValue, clamp_identity); }; - for (int i = useStart; i < end; i++) + for (auto i : selection) { + if (!vector::in_bounds(frames, i)) continue; Frame& frame = frames[i]; if (change.isVisible) frame.isVisible = *change.isVisible; if (change.isInterpolated) frame.isInterpolated = *change.isInterpolated; + if (change.isFlipX) frame.scale.x = -frame.scale.y; + if (change.isFlipY) frame.scale.y = -frame.scale.y; apply_scalar(frame.rotation, change.rotation); apply_scalar_with_clamp(frame.duration, change.duration, clamp_duration); diff --git a/src/anm2/item.h b/src/anm2/item.h index 82b1cfd..6fc4c13 100644 --- a/src/anm2/item.h +++ b/src/anm2/item.h @@ -20,7 +20,7 @@ namespace anm2ed::anm2 std::string to_string(Type, int = -1); int length(Type); Frame frame_generate(float, Type); - void frames_change(FrameChange, ChangeType, int, int = 0); + void frames_change(FrameChange, ChangeType, std::set&); bool frames_deserialize(const std::string&, Type, int, std::set&, std::string*); void frames_bake(int, int, bool, bool); void frames_generate_from_grid(glm::ivec2, glm::ivec2, glm::ivec2, int, int, int); diff --git a/src/imgui/window/animation_preview.cpp b/src/imgui/window/animation_preview.cpp index 677bdb5..c170747 100644 --- a/src/imgui/window/animation_preview.cpp +++ b/src/imgui/window/animation_preview.cpp @@ -746,7 +746,7 @@ namespace anm2ed::imgui if (tool == tool::SCALE && isMouseRightDown) useTool = tool::MOVE; auto frame_change_apply = [&](anm2::FrameChange frameChange, anm2::ChangeType changeType = anm2::ADJUST) - { item->frames_change(frameChange, changeType, *frames.begin(), frames.size()); }; + { item->frames_change(frameChange, changeType, frames); }; auto& toolInfo = tool::INFO[useTool]; auto& areaType = toolInfo.areaType; diff --git a/src/imgui/window/spritesheet_editor.cpp b/src/imgui/window/spritesheet_editor.cpp index 2f6a637..7042f26 100644 --- a/src/imgui/window/spritesheet_editor.cpp +++ b/src/imgui/window/spritesheet_editor.cpp @@ -302,7 +302,7 @@ namespace anm2ed::imgui }; auto frame_change_apply = [&](anm2::FrameChange frameChange, anm2::ChangeType changeType = anm2::ADJUST) - { item->frames_change(frameChange, changeType, *frames.begin(), frames.size()); }; + { item->frames_change(frameChange, changeType, frames); }; if (isMouseMiddleDown) useTool = tool::PAN; if (tool == tool::MOVE && isMouseRightDown) useTool = tool::CROP; diff --git a/src/imgui/wizard/change_all_frame_properties.cpp b/src/imgui/wizard/change_all_frame_properties.cpp index fb2179f..2aec230 100644 --- a/src/imgui/wizard/change_all_frame_properties.cpp +++ b/src/imgui/wizard/change_all_frame_properties.cpp @@ -35,6 +35,8 @@ namespace anm2ed::imgui::wizard auto& isColorOffsetB = settings.changeIsColorOffsetB; auto& isVisibleSet = settings.changeIsVisibleSet; auto& isInterpolatedSet = settings.changeIsInterpolatedSet; + auto& isFlipXSet = settings.changeIsFlipXSet; + auto& isFlipYSet = settings.changeIsFlipYSet; auto& crop = settings.changeCrop; auto& size = settings.changeSize; auto& position = settings.changePosition; @@ -46,6 +48,8 @@ namespace anm2ed::imgui::wizard auto& colorOffset = settings.changeColorOffset; auto& isVisible = settings.changeIsVisible; auto& isInterpolated = settings.changeIsInterpolated; + auto& isFlipX = settings.changeIsFlipX; + auto& isFlipY = settings.changeIsFlipY; #define PROPERTIES_WIDGET(body, checkboxLabel, isEnabled) \ ImGui::Checkbox(checkboxLabel, &isEnabled); \ @@ -196,6 +200,10 @@ namespace anm2ed::imgui::wizard ImGui::SameLine(); bool_value("##Is Interpolated", localize.get(BASIC_INTERPOLATED), isInterpolatedSet, isInterpolated); + bool_value("##Is Flip X", localize.get(LABEL_FLIP_X), isFlipXSet, isFlipX); + ImGui::SameLine(); + bool_value("##Is Flip Y", localize.get(LABEL_FLIP_Y), isFlipYSet, isFlipY); + ImGui::PopStyleVar(); auto frame_change = [&](anm2::ChangeType type) @@ -222,9 +230,11 @@ namespace anm2ed::imgui::wizard if (isColorOffsetB) frameChange.colorOffsetB = colorOffset.b; if (isVisibleSet) frameChange.isVisible = std::make_optional(isVisible); if (isInterpolatedSet) frameChange.isInterpolated = std::make_optional(isInterpolated); + if (isFlipXSet) frameChange.isFlipX = std::make_optional(isFlipX); + if (isFlipYSet) frameChange.isFlipY = std::make_optional(isFlipY); DOCUMENT_EDIT(document, localize.get(EDIT_CHANGE_FRAME_PROPERTIES), Document::FRAMES, - document.item_get()->frames_change(frameChange, type, *frames.begin(), (int)frames.size())); + document.item_get()->frames_change(frameChange, type, frames)); isChanged = true; }; diff --git a/src/settings.h b/src/settings.h index 15e063b..c2c3396 100644 --- a/src/settings.h +++ b/src/settings.h @@ -93,6 +93,8 @@ namespace anm2ed X(CHANGE_IS_COLOR_OFFSET_A, changeIsColorOffsetA, STRING_UNDEFINED, BOOL, false) \ X(CHANGE_IS_VISIBLE_SET, changeIsVisibleSet, STRING_UNDEFINED, BOOL, false) \ X(CHANGE_IS_INTERPOLATED_SET, changeIsInterpolatedSet, STRING_UNDEFINED, BOOL, false) \ + X(CHANGE_IS_FLIP_X_SET, changeIsFlipXSet, STRING_UNDEFINED, BOOL, false) \ + X(CHANGE_IS_FLIP_Y_SET, changeIsFlipYSet, STRING_UNDEFINED, BOOL, false) \ X(CHANGE_CROP, changeCrop, STRING_UNDEFINED, VEC2, {}) \ X(CHANGE_SIZE, changeSize, STRING_UNDEFINED, VEC2, {}) \ X(CHANGE_POSITION, changePosition, STRING_UNDEFINED, VEC2, {}) \ @@ -104,6 +106,8 @@ namespace anm2ed X(CHANGE_COLOR_OFFSET, changeColorOffset, STRING_UNDEFINED, VEC3, {}) \ X(CHANGE_IS_VISIBLE, changeIsVisible, STRING_UNDEFINED, BOOL, false) \ X(CHANGE_IS_INTERPOLATED, changeIsInterpolated, STRING_UNDEFINED, BOOL, false) \ + X(CHANGE_IS_FLIP_X, changeIsFlipX, STRING_UNDEFINED, BOOL, false) \ + X(CHANGE_IS_FLIP_Y, changeIsFlipY, STRING_UNDEFINED, BOOL, false) \ \ X(SCALE_VALUE, scaleValue, STRING_UNDEFINED, FLOAT, 1.0f) \ \