Timeline start/end markers

Right-clicking the numbered row offers Add Start/End Marker Here and
Remove Markers; Shift+Comma / Shift+Period (configurable) set them at the
playhead. Markers are faded playheads, with the numbers outside their
range darkened, and playback loops within them. They are saved as
StartMarker/EndMarker on the editor's copy (SourceDocument) only, as one
undoable edit each.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-03 21:03:00 -04:00
1 parent 24af98a68e
commit 251d04848a
15 files changed
+147 -13

No files matched your search

+2 -1
View File
@@ -184,7 +184,8 @@ namespace anm2ed::imgui
}
auto fps = std::max(model.info.fps, 1);
playback.tick(fps, animation->frameNum, (animation->isLoop || settings.playbackIsLoop) && !manager.isRecording,
auto range = model::animation_play_range_get(*animation);
playback.tick(fps, range.x, range.y, (animation->isLoop || settings.playbackIsLoop) && !manager.isRecording,
deltaSeconds);
frameTime = playback.time;
+4
View File
@@ -101,6 +101,8 @@ namespace anm2ed::imgui
{0.3765f, 0.6784f, 0.2980f, 1.0f},
{0.6353f, 0.2235f, 0.3647f, 1.0f}};
constexpr auto MARKER_ALPHA = 0.5f;
constexpr auto MARKER_OUTSIDE_COLOR = IM_COL32(0, 0, 0, 96);
constexpr auto FRAME_MULTIPLE = 5;
constexpr auto FRAME_TOOLTIP_HOVER_DELAY = 0.75f;
@@ -234,6 +236,8 @@ namespace anm2ed::imgui
void rows_move_to_row(std::vector<TimelineRow> draggedRows, TimelineRow targetRow, bool isDropAfter,
bool isDropIntoGroup = false);
void fit_animation_length();
void marker_set(bool, int);
void markers_remove();
void frame_references_copy(const std::set<Reference>& selectedFrames);
void copy();
void cut();
+26
View File
@@ -293,4 +293,30 @@ namespace anm2ed::imgui
std::format("{} {}", localize.get(TOAST_DESERIALIZE_FRAMES_FAILED, anm2ed::ENGLISH), *errorString));
});
}
// Sets the animation's start or end marker at a time, moving the other one if it would end up on the wrong side.
void TimelineContext::marker_set(bool isStart, int time)
{
if (!animation) return;
edit_push(isStart ? EDIT_START_MARKER : EDIT_END_MARKER,
[=, animationIndex = reference.animationIndex](model::Model& model)
{
auto animation = model.animation_edit(animationIndex);
if (!animation) return;
auto marker = std::clamp(time, 0, std::max(animation->frameNum - 1, 0));
(isStart ? animation->startMarker : animation->endMarker) = marker;
auto& other = isStart ? animation->endMarker : animation->startMarker;
if (other != -1 && (isStart ? other < marker : other > marker)) other = marker;
});
}
void TimelineContext::markers_remove()
{
edit_push(EDIT_REMOVE_MARKERS,
[animationIndex = reference.animationIndex](model::Model& model)
{
if (auto animation = model.animation_edit(animationIndex))
animation->startMarker = animation->endMarker = -1;
});
}
}
+43
View File
@@ -226,6 +226,49 @@ namespace anm2ed::imgui
if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) isDragging = false;
// Markers show as faded playheads, with the numbers outside the range they set darkened.
if (length > 0 && animation)
{
auto x_get = [&](int time) { return cursorScreenPos.x + frameSize.x * (float)time; };
auto range = model::animation_play_range_get(*animation);
auto bottom = cursorScreenPos.y + frameSize.y;
if (animation->startMarker != -1)
drawList->AddRectFilled(cursorScreenPos, ImVec2(x_get(range.x), bottom), MARKER_OUTSIDE_COLOR);
if (animation->endMarker != -1)
drawList->AddRectFilled(ImVec2(x_get(range.y), cursorScreenPos.y),
ImVec2(cursorScreenPos.x + framesSize.x, bottom), MARKER_OUTSIDE_COLOR);
auto markerTint = playheadIconTint;
markerTint.w *= MARKER_ALPHA;
for (auto marker : {animation->startMarker, animation->endMarker})
if (marker != -1)
drawList->AddImage((ImTextureID)(intptr_t)resources.icon_id_get(icon::PLAYHEAD),
ImVec2(x_get(marker), cursorScreenPos.y), ImVec2(x_get(marker) + frameSize.x, bottom),
ImVec2(0, 0), ImVec2(1, 1), ImGui::GetColorU32(markerTint));
}
isRulerHovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup);
if (isRulerHovered && ImGui::IsMouseReleased(ImGuiMouseButton_Right)) markerTime = hoveredTime;
Actions markerActions{};
auto isAnimation = [&]() { return animation != nullptr; };
markerActions.add({.label = LABEL_ADD_START_MARKER,
.shortcut = SHORTCUT_START_MARKER,
.isEnabled = isAnimation,
.run = [&]() { marker_set(true, markerTime); }});
markerActions.add({.label = LABEL_ADD_END_MARKER,
.shortcut = SHORTCUT_END_MARKER,
.isEnabled = isAnimation,
.run = [&]() { marker_set(false, markerTime); }});
markerActions.separator();
markerActions.add(
{.label = LABEL_REMOVE_MARKERS,
.shortcut = -1,
.isEnabled = [&]() { return animation && (animation->startMarker != -1 || animation->endMarker != -1); },
.run = [&]() { markers_remove(); }});
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, style.WindowPadding);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, style.ItemSpacing);
actions_context_window_draw("##Marker Menu", markerActions, settings);
ImGui::PopStyleVar(2);
if (length > 0)
{
ImGui::SetCursorPos(ImVec2(cursorPos.x + frameSize.x * floorf(playback.time), cursorPos.y));
+6 -2
View File
@@ -153,8 +153,12 @@ namespace anm2ed::imgui
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(); });
actions_context_window_draw("##Context Menu", actions, settings, ImGuiPopupFlags_MouseButtonRight,
ImGuiHoveredFlags_ChildWindows);
// The numbered row has its own (marker) menu.
if (isRulerHovered)
actions_popup_draw("##Context Menu", actions, settings);
else
actions_context_window_draw("##Context Menu", actions, settings, ImGuiPopupFlags_MouseButtonRight,
ImGuiHoveredFlags_ChildWindows);
ImGui::PopStyleVar(2);
}
+2
View File
@@ -185,6 +185,8 @@ namespace anm2ed::imgui
if (!animation) return;
if (shortcut(manager.chords[SHORTCUT_PLAY_PAUSE], shortcut::GLOBAL)) playback.toggle();
if (shortcut(manager.chords[SHORTCUT_START_MARKER], shortcut::GLOBAL)) marker_set(true, (int)playback.time);
if (shortcut(manager.chords[SHORTCUT_END_MARKER], shortcut::GLOBAL)) marker_set(false, (int)playback.time);
if (shortcut(manager.chords[SHORTCUT_MOVE_PLAYHEAD_BACK], shortcut::GLOBAL))
{
+2
View File
@@ -112,6 +112,8 @@ namespace anm2ed::imgui
struct TimelineState
{
bool isDragging{};
bool isRulerHovered{};
int markerTime{};
bool isWindowHovered{};
bool isHorizontalScroll{};
popup::ItemProperties itemProperties{};