change all frame properties adjustments

This commit is contained in:
2025-12-28 14:29:36 -05:00
parent 8096521f28
commit 233b2139fd
7 changed files with 27 additions and 10 deletions

View File

@@ -71,6 +71,8 @@ namespace anm2ed::anm2
std::optional<float> tintG{};
std::optional<float> tintB{};
std::optional<float> tintA{};
std::optional<bool> isFlipX{};
std::optional<bool> isFlipY{};
};
}

View File

@@ -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<int>& 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);

View File

@@ -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<int>&);
bool frames_deserialize(const std::string&, Type, int, std::set<int>&, std::string*);
void frames_bake(int, int, bool, bool);
void frames_generate_from_grid(glm::ivec2, glm::ivec2, glm::ivec2, int, int, int);

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;
};

View File

@@ -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) \
\