From 15e94192bd41fe6a03648a82cf57f0d5a2848831 Mon Sep 17 00:00:00 2001 From: shweet Date: Sun, 22 Nov 2026 18:42:11 -0500 Subject: [PATCH] Describe frame properties in one table FRAME_PROPERTIES gives each property's tracks and what copying it takes, for the enum, the check and the copy. --- src/edit/edit.h | 51 +++++++++++++++---------- src/edit/frames.cpp | 92 ++++++++++----------------------------------- 2 files changed, 51 insertions(+), 92 deletions(-) diff --git a/src/edit/edit.h b/src/edit/edit.h index c5c871c..f1ba92f 100644 --- a/src/edit/edit.h +++ b/src/edit/edit.h @@ -63,30 +63,41 @@ struct AnimationTarget }; // Frame properties that can be copied on their own. +// Each frame property: the tracks that have it (all but triggers, layers only, or triggers only) and what copying it +// takes from a source frame. +#define FRAME_PROPERTIES(X) \ + X(POSITION, FRAMES, target.position = source.position) \ + X(SCALE, FRAMES, target.scale = source.scale) \ + X(ROTATION, FRAMES, target.rotation = source.rotation) \ + X(SKEW, FRAMES, target.skew = source.skew) \ + X(PIVOT, LAYERS, target.pivot = source.pivot) \ + X(CROP, LAYERS, target.crop = source.crop) \ + X(SIZE, LAYERS, target.size = source.size) \ + X(REGION, LAYERS, target.regionId = source.regionId; target.crop = source.crop; target.size = source.size; \ + target.pivot = source.pivot) \ + X(TINT, FRAMES, target.tint = source.tint) \ + X(COLOR_OFFSET, FRAMES, target.colorOffset = source.colorOffset) \ + X(VISIBLE, FRAMES, target.isVisible = source.isVisible) \ + X(INTERPOLATION, FRAMES, target.interpolation = source.interpolation) \ + X(DURATION, FRAMES, target.duration = source.duration) \ + X(SHADER, LAYERS, target.shaderId = source.shaderId) \ + X(DEPTH, LAYERS, target.depth = source.depth) \ + X(BLUR, LAYERS, target.blur = source.blur) \ + X(CHILD, LAYERS, target.childAnimation = source.childAnimation; target.childMode = source.childMode; \ + target.childStart = source.childStart; target.isChildStartRandom = source.isChildStartRandom; \ + target.isChildRestart = source.isChildRestart) \ + X(EVENT, TRIGGERS, target.eventIds = source.eventIds) \ + X(SOUNDS, TRIGGERS, target.soundIds = source.soundIds) + enum class FrameProperty { - POSITION, - SCALE, - ROTATION, - SKEW, - PIVOT, - CROP, - SIZE, - REGION, - TINT, - COLOR_OFFSET, - VISIBLE, - INTERPOLATION, - DURATION, - SHADER, - DEPTH, - BLUR, - CHILD, - EVENT, - SOUNDS, - COUNT +#define X(property, tracks, ...) property, + FRAME_PROPERTIES(X) +#undef X + COUNT }; + bool is_frame_property_valid(FrameProperty, ItemType); void frame_property_copy(Frame&, const Frame&, FrameProperty); Uids frames_property_set(Model&, const std::set&, FrameProperty, const Frame&); diff --git a/src/edit/frames.cpp b/src/edit/frames.cpp index cdaa2eb..82ce7a0 100644 --- a/src/edit/frames.cpp +++ b/src/edit/frames.cpp @@ -218,85 +218,33 @@ Uids frames_move(Model& model, const std::set& frames, Reference targ // Triggers have an event and sounds. Layer frames add a pivot, crop, size, region and shader to the others' transform. bool is_frame_property_valid(FrameProperty property, ItemType type) { + enum Tracks + { + FRAMES, + LAYERS, + TRIGGERS + }; + constexpr Tracks TRACKS[] = { +#define X(property, tracks, ...) tracks, + FRAME_PROPERTIES(X) +#undef X + }; + auto tracks = TRACKS[(int)property]; if (type == ItemType::TRIGGER) - return property == FrameProperty::EVENT || property == FrameProperty::SOUNDS; - if (property == FrameProperty::EVENT || property == FrameProperty::SOUNDS) - return false; - auto isLayerOnly = property == FrameProperty::PIVOT || property == FrameProperty::CROP || - property == FrameProperty::SIZE || property == FrameProperty::REGION || - property == FrameProperty::SHADER || property == FrameProperty::DEPTH || - property == FrameProperty::BLUR || property == FrameProperty::CHILD; - return type == ItemType::LAYER || !isLayerOnly; + return tracks == TRIGGERS; + return tracks == FRAMES || (tracks == LAYERS && type == ItemType::LAYER); } void frame_property_copy(Frame& target, const Frame& source, FrameProperty property) { switch (property) { - case FrameProperty::POSITION: - target.position = source.position; - break; - case FrameProperty::SCALE: - target.scale = source.scale; - break; - case FrameProperty::ROTATION: - target.rotation = source.rotation; - break; - case FrameProperty::SKEW: - target.skew = source.skew; - break; - case FrameProperty::PIVOT: - target.pivot = source.pivot; - break; - case FrameProperty::CROP: - target.crop = source.crop; - break; - case FrameProperty::SIZE: - target.size = source.size; - break; - case FrameProperty::REGION: - target.regionId = source.regionId; - target.crop = source.crop; - target.size = source.size; - target.pivot = source.pivot; - break; - case FrameProperty::TINT: - target.tint = source.tint; - break; - case FrameProperty::COLOR_OFFSET: - target.colorOffset = source.colorOffset; - break; - case FrameProperty::VISIBLE: - target.isVisible = source.isVisible; - break; - case FrameProperty::INTERPOLATION: - target.interpolation = source.interpolation; - break; - case FrameProperty::DURATION: - target.duration = source.duration; - break; - case FrameProperty::SHADER: - target.shaderId = source.shaderId; - break; - case FrameProperty::DEPTH: - target.depth = source.depth; - break; - case FrameProperty::BLUR: - target.blur = source.blur; - break; - case FrameProperty::CHILD: - target.childAnimation = source.childAnimation; - target.childMode = source.childMode; - target.childStart = source.childStart; - target.isChildStartRandom = source.isChildStartRandom; - target.isChildRestart = source.isChildRestart; - break; - case FrameProperty::EVENT: - target.eventIds = source.eventIds; - break; - case FrameProperty::SOUNDS: - target.soundIds = source.soundIds; - break; +#define X(property, tracks, ...) \ + case FrameProperty::property: \ + __VA_ARGS__; \ + break; + FRAME_PROPERTIES(X) +#undef X default: break; }