Frame properties: one field table for change-all, shared widgets
- FRAME_CHANGE_SCALARS generates FrameChange fields, the frames_change apply step and change-all population - Change-all draws component rows from tables instead of five widget lambdas and 46 aliases - Frame properties uses one edit path (edit::COMPLETE), a vec2 field table and an X/Y flip loop - Shared INTERPOLATION_LABELS and Document::layer_regions_get Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
30ea363c39
commit
a4638a422d
9 files changed
+421
-744
No files matched your search
+31
-23
@@ -246,37 +246,45 @@ namespace anm2ed
|
||||
bool isExtendedFormat{};
|
||||
};
|
||||
|
||||
#define FRAME_CHANGE_SCALARS \
|
||||
X(cropX, crop.x, true, false, changeIsCropX, changeCrop.x) \
|
||||
X(cropY, crop.y, true, false, changeIsCropY, changeCrop.y) \
|
||||
X(sizeX, size.x, true, false, changeIsSizeX, changeSize.x) \
|
||||
X(sizeY, size.y, true, false, changeIsSizeY, changeSize.y) \
|
||||
X(pivotX, pivot.x, true, false, changeIsPivotX, changePivot.x) \
|
||||
X(pivotY, pivot.y, true, false, changeIsPivotY, changePivot.y) \
|
||||
X(positionX, position.x, false, false, changeIsPositionX, changePosition.x) \
|
||||
X(positionY, position.y, false, false, changeIsPositionY, changePosition.y) \
|
||||
X(scaleX, scale.x, false, false, changeIsScaleX, changeScale.x) \
|
||||
X(scaleY, scale.y, false, false, changeIsScaleY, changeScale.y) \
|
||||
X(shearX, shear.x, false, false, changeIsShearX, changeShear.x) \
|
||||
X(shearY, shear.y, false, false, changeIsShearY, changeShear.y) \
|
||||
X(rotation, rotation, false, false, changeIsRotation, changeRotation) \
|
||||
X(tintR, tint.r, false, true, changeIsTintR, changeTint.r) \
|
||||
X(tintG, tint.g, false, true, changeIsTintG, changeTint.g) \
|
||||
X(tintB, tint.b, false, true, changeIsTintB, changeTint.b) \
|
||||
X(tintA, tint.a, false, true, changeIsTintA, changeTint.a) \
|
||||
X(colorOffsetR, colorOffset.r, false, true, changeIsColorOffsetR, changeColorOffset.r) \
|
||||
X(colorOffsetG, colorOffset.g, false, true, changeIsColorOffsetG, changeColorOffset.g) \
|
||||
X(colorOffsetB, colorOffset.b, false, true, changeIsColorOffsetB, changeColorOffset.b)
|
||||
|
||||
struct FrameChange
|
||||
{
|
||||
std::optional<int> regionId{};
|
||||
#define X(name, member, isLayerOnly, isColor, isEnabled, value) std::optional<float> name{};
|
||||
FRAME_CHANGE_SCALARS
|
||||
#undef X
|
||||
std::optional<int> duration{};
|
||||
std::optional<int> shaderId{};
|
||||
std::optional<bool> isVisible{};
|
||||
std::optional<Interpolation> interpolation{};
|
||||
std::optional<int> shaderId{};
|
||||
std::optional<float> rotation{};
|
||||
std::optional<int> duration{};
|
||||
std::optional<int> regionId{};
|
||||
std::optional<float> pivotX{};
|
||||
std::optional<float> pivotY{};
|
||||
std::optional<float> cropX{};
|
||||
std::optional<float> cropY{};
|
||||
std::optional<float> positionX{};
|
||||
std::optional<float> positionY{};
|
||||
std::optional<float> sizeX{};
|
||||
std::optional<float> sizeY{};
|
||||
std::optional<float> scaleX{};
|
||||
std::optional<float> scaleY{};
|
||||
std::optional<float> shearX{};
|
||||
std::optional<float> shearY{};
|
||||
std::optional<float> colorOffsetR{};
|
||||
std::optional<float> colorOffsetG{};
|
||||
std::optional<float> colorOffsetB{};
|
||||
std::optional<float> tintR{};
|
||||
std::optional<float> tintG{};
|
||||
std::optional<float> tintB{};
|
||||
std::optional<float> tintA{};
|
||||
std::optional<bool> isFlipX{};
|
||||
std::optional<bool> isFlipY{};
|
||||
};
|
||||
|
||||
inline constexpr StringType INTERPOLATION_LABELS[] = {BASIC_NONE, BASIC_LINEAR, BASIC_EASE_IN, BASIC_EASE_OUT,
|
||||
BASIC_EASE_IN_OUT};
|
||||
|
||||
struct Element
|
||||
{
|
||||
ElementType type{ElementType::UNKNOWN};
|
||||
|
||||
+14
-58
@@ -11,7 +11,6 @@ namespace anm2ed
|
||||
ALL
|
||||
};
|
||||
|
||||
|
||||
void frame_mix(Element& frame, const Element& next, float amount)
|
||||
{
|
||||
frame.rotation = glm::mix(frame.rotation, next.rotation, amount);
|
||||
@@ -254,40 +253,17 @@ namespace anm2ed
|
||||
void frames_change(Element& track, FrameChange change, ItemType itemType, ChangeType changeType,
|
||||
const std::set<int>& selection)
|
||||
{
|
||||
const auto clamp_identity = [](auto value) { return value; };
|
||||
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)
|
||||
auto apply = [&](auto& target, const auto& optionalValue)
|
||||
{
|
||||
if (!optionalValue) return;
|
||||
auto value = *optionalValue;
|
||||
|
||||
switch (changeType)
|
||||
{
|
||||
case ChangeType::ADJUST:
|
||||
target = clampFunc(value);
|
||||
break;
|
||||
case ChangeType::ADD:
|
||||
target = clampFunc(target + value);
|
||||
break;
|
||||
case ChangeType::SUBTRACT:
|
||||
target = clampFunc(target - value);
|
||||
break;
|
||||
case ChangeType::MULTIPLY:
|
||||
target = clampFunc(target * value);
|
||||
break;
|
||||
case ChangeType::DIVIDE:
|
||||
if (value == decltype(value){}) return;
|
||||
target = clampFunc(target / value);
|
||||
break;
|
||||
}
|
||||
if (changeType == ChangeType::ADJUST) target = value;
|
||||
if (changeType == ChangeType::ADD) target += value;
|
||||
if (changeType == ChangeType::SUBTRACT) target -= value;
|
||||
if (changeType == ChangeType::MULTIPLY) target *= value;
|
||||
if (changeType == ChangeType::DIVIDE && value != decltype(value){}) target /= value;
|
||||
};
|
||||
|
||||
auto apply_scalar = [&](auto& target, const auto& optionalValue)
|
||||
{ apply_scalar_with_clamp(target, optionalValue, clamp_identity); };
|
||||
|
||||
for (auto index : selection)
|
||||
{
|
||||
auto frame = track_frame_get(track, index);
|
||||
@@ -298,34 +274,14 @@ namespace anm2ed
|
||||
if (change.isFlipX) frame->scale.x = -frame->scale.x;
|
||||
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);
|
||||
|
||||
if (itemType == ItemType::LAYER)
|
||||
{
|
||||
apply_scalar(frame->crop.x, change.cropX);
|
||||
apply_scalar(frame->crop.y, change.cropY);
|
||||
apply_scalar(frame->pivot.x, change.pivotX);
|
||||
apply_scalar(frame->pivot.y, change.pivotY);
|
||||
apply_scalar(frame->size.x, change.sizeX);
|
||||
apply_scalar(frame->size.y, change.sizeY);
|
||||
if (change.regionId) frame->regionId = *change.regionId;
|
||||
if (change.shaderId) frame->shaderId = *change.shaderId;
|
||||
}
|
||||
|
||||
apply_scalar(frame->position.x, change.positionX);
|
||||
apply_scalar(frame->position.y, change.positionY);
|
||||
apply_scalar(frame->scale.x, change.scaleX);
|
||||
apply_scalar(frame->scale.y, change.scaleY);
|
||||
apply_scalar(frame->shear.x, change.shearX);
|
||||
apply_scalar(frame->shear.y, change.shearY);
|
||||
apply_scalar(frame->colorOffset.x, change.colorOffsetR);
|
||||
apply_scalar(frame->colorOffset.y, change.colorOffsetG);
|
||||
apply_scalar(frame->colorOffset.z, change.colorOffsetB);
|
||||
apply_scalar(frame->tint.x, change.tintR);
|
||||
apply_scalar(frame->tint.y, change.tintG);
|
||||
apply_scalar(frame->tint.z, change.tintB);
|
||||
apply_scalar(frame->tint.w, change.tintA);
|
||||
apply(frame->duration, change.duration);
|
||||
if (change.duration) frame->duration = std::max(FRAME_DURATION_MIN, frame->duration);
|
||||
if (itemType == ItemType::LAYER && change.regionId) frame->regionId = *change.regionId;
|
||||
if (itemType == ItemType::LAYER && change.shaderId) frame->shaderId = *change.shaderId;
|
||||
#define X(name, member, isLayerOnly, isColor, isEnabled, value) \
|
||||
if (!isLayerOnly || itemType == ItemType::LAYER) apply(frame->member, change.name);
|
||||
FRAME_CHANGE_SCALARS
|
||||
#undef X
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user