Timeline: cut, copy and paste one frame property

In the frames context menu, Cut/Copy/Paste each open onto Frame (the whole
frame, as Ctrl+X/C/V) or Property, which lists the properties the frame
type has. Copying a property copies the focused (or first selected) frame;
pasting sets just that property on the selected frames, and is disabled
when a target lacks it or what it refers to (region on the target's
spritesheet, shader, event, sounds). Cutting resets it to the default.
Actions gained submenus; edit::frames_property_set does the work (tested).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-03 21:11:09 -04:00
1 parent 8fb28ef30a
commit 97be81b5c1
11 files changed
+306 -9

No files matched your search

+15 -3
View File
@@ -55,10 +55,10 @@ namespace anm2ed::imgui
{ manager.command_push({manager.selected, [](Manager&, Document& document) { document.redo(); }}); });
}
void actions_menu_draw(Actions& actions, Settings& settings)
void action_items_menu_draw(std::vector<Action>& items, Settings& settings)
{
bool isPreviousSeparator{};
for (auto& action : actions.items)
for (auto& action : items)
{
if (action.isSeparator)
{
@@ -66,6 +66,17 @@ namespace anm2ed::imgui
isPreviousSeparator = true;
continue;
}
isPreviousSeparator = false;
if (!action.children.empty())
{
if (ImGui::BeginMenu(localize.get(action.label), is_action_enabled(action)))
{
action_items_menu_draw(action.children, settings);
ImGui::EndMenu();
}
continue;
}
auto shortcutText = action_shortcut_text_get(action, settings);
auto shortcutLabel = shortcutText.empty() ? nullptr : shortcutText.c_str();
@@ -73,10 +84,11 @@ namespace anm2ed::imgui
action.run();
if (action.tooltip != STRING_UNDEFINED && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
ImGui::SetItemTooltip("%s", localize.get(action.tooltip));
isPreviousSeparator = false;
}
}
void actions_menu_draw(Actions& actions, Settings& settings) { action_items_menu_draw(actions.items, settings); }
bool actions_context_window_draw(const char* label, Actions& actions, Settings& settings, ImGuiPopupFlags flags,
ImGuiHoveredFlags hoveredFlags)
{
+1
View File
@@ -69,6 +69,7 @@ namespace anm2ed::imgui
bool isSeparator{};
std::function<bool()> isEnabled{};
std::function<void()> run{};
std::vector<Action> children{}; // a submenu, in menus
};
struct Actions
+7
View File
@@ -242,6 +242,13 @@ namespace anm2ed::imgui
void copy();
void cut();
void paste();
std::optional<Reference> property_source_get();
std::set<Reference> property_targets_get();
std::optional<model::Frame> property_clipboard_frame_get();
bool is_property_pasteable(edit::FrameProperty);
void property_copy(edit::FrameProperty);
void property_cut(edit::FrameProperty);
void property_paste(edit::FrameProperty);
void context_menu();
void item_base_properties_open(int type, int id);
void group_properties_open(const TimelineRow& row, const model::TrackGroup& group);
+87 -1
View File
@@ -247,7 +247,9 @@ namespace anm2ed::imgui
if (!frame) continue;
clipboardString += model::frame_to_string(*frame, (ItemType)frameReference.itemType);
}
if (!clipboardString.empty()) clipboard.set(clipboardString);
if (clipboardString.empty()) return;
clipboard.set(clipboardString);
frameClipboard = {.text = clipboardString, .itemType = selectedFrames.begin()->itemType};
}
void TimelineContext::copy()
@@ -319,4 +321,88 @@ namespace anm2ed::imgui
animation->startMarker = animation->endMarker = -1;
});
}
// The frame a property is copied from: the focused frame, or else the first selected one.
std::optional<Reference> TimelineContext::property_source_get()
{
if (reference.frameIndex >= 0 && model.frame_get(reference)) return reference;
auto selectedFrames = document.frame_references_get(Document::FrameReferenceFallback::NONE);
if (selectedFrames.empty()) return {};
return *selectedFrames.begin();
}
// The frames a property is cut from or pasted into: the selected ones, or else the focused one.
std::set<Reference> TimelineContext::property_targets_get()
{
auto selectedFrames = document.frame_references_get(Document::FrameReferenceFallback::NONE);
if (selectedFrames.empty())
if (auto source = property_source_get()) selectedFrames.insert(*source);
return selectedFrames;
}
// The frame this timeline put on the clipboard, while it is still there.
std::optional<model::Frame> TimelineContext::property_clipboard_frame_get()
{
if (frameClipboard.text.empty() || clipboard.get() != frameClipboard.text) return {};
auto frames = model::frames_from_string(frameClipboard.text, (ItemType)frameClipboard.itemType);
if (frames.empty()) return {};
return frames.front();
}
// Every target frame has the property, and what it refers to (a region, shader, event, sound) exists for it.
bool TimelineContext::is_property_pasteable(edit::FrameProperty property)
{
if (frameClipboard.property != -1 && frameClipboard.property != (int)property) return false;
if (!edit::is_frame_property_valid(property, (ItemType)frameClipboard.itemType)) return false;
auto source = property_clipboard_frame_get();
auto targets = property_targets_get();
if (!source || targets.empty()) return false;
auto& content = model.content;
for (auto target : targets)
{
if (!edit::is_frame_property_valid(property, (ItemType)target.itemType)) return false;
if (property == edit::FrameProperty::REGION && source->regionId != -1)
{
auto layer = model::item_get(content.layers, target.itemID);
auto spritesheet = layer ? model::item_get(content.spritesheets, layer->spritesheetId) : nullptr;
if (!spritesheet || !model::item_get(spritesheet->regions, source->regionId)) return false;
}
}
if (property == edit::FrameProperty::SHADER && source->shaderId != -1 &&
!model::item_get(content.shaders, source->shaderId))
return false;
if (property == edit::FrameProperty::EVENT && source->eventId != -1 &&
!model::item_get(content.events, source->eventId))
return false;
if (property == edit::FrameProperty::SOUNDS)
for (auto soundId : source->soundIds)
if (soundId != -1 && !model::item_get(content.sounds, soundId)) return false;
return true;
}
void TimelineContext::property_copy(edit::FrameProperty property)
{
auto source = property_source_get();
if (!source) return;
frame_references_copy({*source});
frameClipboard.property = (int)property;
}
// Copies the property, then sets it back to its default on the targets.
void TimelineContext::property_cut(edit::FrameProperty property)
{
auto targets = property_targets_get();
property_copy(property);
edit_push(EDIT_CUT_FRAME_PROPERTY,
[=](model::Model& model) { return edit::frames_property_set(model, targets, property, model::Frame{}); });
}
void TimelineContext::property_paste(edit::FrameProperty property)
{
auto source = property_clipboard_frame_get();
if (!source || !is_property_pasteable(property)) return;
edit_push(EDIT_PASTE_FRAME_PROPERTY, [=, targets = property_targets_get(), source = *source](model::Model& model)
{ return edit::frames_property_set(model, targets, property, source); });
}
}
+46 -3
View File
@@ -2,6 +2,12 @@
namespace anm2ed::imgui
{
constexpr StringType FRAME_PROPERTY_LABELS[] = {
BASIC_POSITION, BASIC_SCALE, BASIC_ROTATION, BASIC_SHEAR, BASIC_PIVOT, BASIC_CROP,
BASIC_SIZE, BASIC_REGION, BASIC_TINT, BASIC_COLOR_OFFSET, BASIC_VISIBLE, BASIC_INTERPOLATED,
BASIC_DURATION, BASIC_SHADER, BASIC_EVENT, LABEL_SOUNDS};
static_assert(std::size(FRAME_PROPERTY_LABELS) == (std::size_t)edit::FrameProperty::COUNT);
void TimelineContext::frame_begin()
{
iconTintDefault = isLightTheme ? ICON_TINT_DEFAULT_LIGHT : ICON_TINT_DEFAULT_DARK;
@@ -150,9 +156,46 @@ namespace anm2ed::imgui
.isEnabled = [=, this]() { return !selectedFrames.empty(); },
.run = [&]() { frames_delete_action(); }});
actions.separator();
actions.add(ACTION_CUT, [=, this]() { return !selectedFrames.empty(); }, [this]() { cut(); });
actions.add(ACTION_COPY, [=, this]() { return !copyFrames.empty(); }, [this]() { copy(); });
actions.add(ACTION_PASTE, [&]() { return !clipboard.is_empty(); }, [this]() { paste(); });
// Cut, copy and paste each open onto the whole frame, or one property of it.
auto source = property_source_get();
auto sourceFrame = source ? model.frame_get(*source) : nullptr;
auto clipboardFrame = property_clipboard_frame_get();
auto clipboard_menu_add = [&](ActionType type, std::function<bool()> isFrameEnabled, std::function<void()> frameRun,
int propertyType, std::function<bool(edit::FrameProperty)> is_property_enabled,
std::function<void(edit::FrameProperty)> property_run)
{
Action properties{.label = LABEL_PROPERTY};
for (int i = 0; i < (int)edit::FrameProperty::COUNT; ++i)
{
auto property = (edit::FrameProperty)i;
if (!edit::is_frame_property_valid(property, (ItemType)propertyType)) continue;
properties.children.push_back({.label = FRAME_PROPERTY_LABELS[i],
.isEnabled = [=]() { return is_property_enabled(property); },
.run = [=]() { property_run(property); }});
}
properties.isEnabled = [children = properties.children]()
{ return std::ranges::any_of(children, is_action_enabled); };
actions.add({.label = ACTION_INFOS[type].label,
.children = {{.label = BASIC_FRAME,
.shortcut = ACTION_INFOS[type].shortcut,
.isEnabled = isFrameEnabled,
.run = frameRun},
properties}});
};
auto sourceType = source ? source->itemType : NONE;
clipboard_menu_add(
ACTION_CUT, [=, this]() { return !selectedFrames.empty(); }, [this]() { cut(); }, sourceType,
[=](edit::FrameProperty) { return sourceFrame != nullptr; },
[this](edit::FrameProperty property) { property_cut(property); });
clipboard_menu_add(
ACTION_COPY, [=, this]() { return !copyFrames.empty(); }, [this]() { copy(); }, sourceType,
[=](edit::FrameProperty) { return sourceFrame != nullptr; },
[this](edit::FrameProperty property) { property_copy(property); });
clipboard_menu_add(
ACTION_PASTE, [&]() { return !clipboard.is_empty(); }, [this]() { paste(); },
clipboardFrame ? frameClipboard.itemType : NONE,
[this](edit::FrameProperty property) { return is_property_pasteable(property); },
[this](edit::FrameProperty property) { property_paste(property); });
// The numbered row has its own (marker) menu.
if (isRulerHovered)
actions_popup_draw("##Context Menu", actions, settings);
+3 -2
View File
@@ -34,8 +34,9 @@ namespace anm2ed::imgui
void Timeline::update(Manager& manager, Settings& settings, Resources& resources, Clipboard& clipboard)
{
if (!manager.get()) return;
auto state = context ? std::move(static_cast<TimelineState&>(*context)) : TimelineState{};
context = std::make_unique<TimelineContext>(std::move(state), manager, settings, resources, clipboard);
context =
std::make_unique<TimelineContext>(context ? std::move(static_cast<TimelineState&>(*context)) : TimelineState{},
manager, settings, resources, clipboard);
context->update();
}
+9
View File
@@ -97,6 +97,14 @@ namespace anm2ed::imgui
bool isActive{};
};
// What the timeline last put on the clipboard: frames of a type, or one property of a frame.
struct FrameClipboard
{
std::string text{};
int itemType{NONE};
int property{-1};
};
struct FrameDurationDrag
{
Reference reference{};
@@ -113,6 +121,7 @@ namespace anm2ed::imgui
{
bool isDragging{};
bool isRulerHovered{};
FrameClipboard frameClipboard{};
int markerTime{};
bool isWindowHovered{};
bool isHorizontalScroll{};