Stage 8c: timeline cleanup

- One TimelineRow type for rows, row selection and drag payloads (replaces
  TimelineItemRow + TimelineRowReference).
- Frame/track selection helpers live on Document (frames_select, frame_select,
  frame_toggle, frames_range_select, frame_focus_select, focus_clear,
  track_select) instead of TimelineContext *_for(Document&) wrappers.
- Drop target and frame-move drag carry References; selection anchors are
  optionals; single-use helpers and write-only fields are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-03 17:55:14 -04:00
1 parent 6f7a457f8f
commit dc32483c45
10 files changed
+243 -391

No files matched your search

+88
View File
@@ -747,6 +747,94 @@ namespace anm2ed
return choices; return choices;
} }
// Selects the frames an edit returned and moves the playhead to the first.
void Document::frames_select(const edit::Uids& uids)
{
auto references = references_get(uids);
if (references.empty()) return;
auto focus = references.front();
editTarget = EditTarget::FRAME;
frame_references_set({references.begin(), references.end()});
reference_set(focus);
if (auto item = model.track_get(focus); item && focus.itemType != TRIGGER)
frameTime = model::frame_time_from_index_get(*item, focus.frameIndex);
}
void Document::frame_select(Reference frameReference)
{
selection.uids[SelectionKind::GROUPS].clear();
editTarget = EditTarget::FRAME;
frame_references_set({frameReference});
reference_set(frameReference);
}
void Document::frame_toggle(Reference frameReference)
{
selection.uids[SelectionKind::GROUPS].clear();
editTarget = EditTarget::FRAME;
auto frames = frame_references_get(FrameReferenceFallback::NONE);
if (!frames.contains(frameReference))
frames.insert(frameReference);
else if (frames.size() > 1)
frames.erase(frameReference);
frame_references_set(frames);
reference_set(frameReference);
}
// Selects frames first..last of one track (added to the selection when additive).
bool Document::frames_range_select(Reference firstReference, Reference lastReference, bool isAdditive)
{
selection.uids[SelectionKind::GROUPS].clear();
editTarget = EditTarget::FRAME;
if (document::item_reference_get(firstReference) != document::item_reference_get(lastReference) ||
firstReference.frameIndex < 0 || lastReference.frameIndex < 0)
return false;
auto item = model.track_get(lastReference);
if (!item || std::max(firstReference.frameIndex, lastReference.frameIndex) >= model::track_frames_count_get(*item))
return false;
auto [firstIndex, lastIndex] = std::minmax(firstReference.frameIndex, lastReference.frameIndex);
auto selectedFrames = isAdditive ? frame_references_get(FrameReferenceFallback::NONE) : std::set<Reference>{};
for (int i = firstIndex; i <= lastIndex; ++i)
{
auto frameReference = lastReference;
frameReference.frameIndex = i;
selectedFrames.insert(frameReference);
}
frame_references_set(selectedFrames);
reference_set(lastReference);
return true;
}
void Document::frame_focus_select()
{
auto targetReference = reference_get();
if (targetReference.frameIndex < 0) return frame_references_clear();
editTarget = EditTarget::FRAME;
frame_references_set({targetReference});
}
void Document::focus_clear()
{
reference_set({reference_get().animationIndex});
frame_references_clear();
selection.uids[SelectionKind::TRACKS].clear();
}
// Selects a track (its layer's spritesheet becomes the focused one).
void Document::track_select(Reference itemReference)
{
itemReference.frameIndex = -1;
if (itemReference.itemType == LAYER)
if (auto layer = model::item_get(model.content.layers, itemReference.itemID))
focused_id_set(SelectionKind::SPRITESHEETS, layer->spritesheetId);
reference_set(itemReference);
frame_references_clear();
selected_set(SelectionKind::TRACKS, {itemReference});
}
std::set<int> Document::animations_selected_get() const std::set<int> Document::animations_selected_get() const
{ {
std::set<int> indices{}; std::set<int> indices{};
+7
View File
@@ -157,6 +157,13 @@ namespace anm2ed
void focused_id_set(SelectionKind, int); void focused_id_set(SelectionKind, int);
void selected_clear(SelectionKind); void selected_clear(SelectionKind);
Choices choices_get(SelectionKind, int = -1) const; Choices choices_get(SelectionKind, int = -1) const;
void frames_select(const edit::Uids&);
void frame_select(Reference);
void frame_toggle(Reference);
bool frames_range_select(Reference, Reference, bool);
void frame_focus_select();
void focus_clear();
void track_select(Reference);
std::set<int> animations_selected_get() const; std::set<int> animations_selected_get() const;
void animations_selected_set(const std::set<int>&); void animations_selected_set(const std::set<int>&);
std::set<Reference> item_frame_references_get(Reference) const; std::set<Reference> item_frame_references_get(Reference) const;
+17 -58
View File
@@ -136,23 +136,8 @@ namespace anm2ed::imgui
resource::icon::EASE_IN, resource::icon::EASE_OUT, resource::icon::EASE_IN, resource::icon::EASE_OUT,
resource::icon::EASE_IN_OUT}; resource::icon::EASE_IN_OUT};
struct TimelineItemRow Reference row_item_reference_get(const TimelineRow&);
{ Reference row_selection_reference_get(const TimelineRow&);
int type{NONE};
int id{-1};
int index{-1};
int groupId{-1};
int rootGroupType{NONE};
int rootGroupId{-1};
int depth{};
bool isGroup{};
};
struct RootFrameSpan
{
int start{};
int end{};
};
struct TimelineContext : TimelineState struct TimelineContext : TimelineState
{ {
@@ -183,12 +168,7 @@ namespace anm2ed::imgui
ImVec4 itemTextColor{}; ImVec4 itemTextColor{};
std::optional<int> frameSplitTimeAtCursor{}; std::optional<int> frameSplitTimeAtCursor{};
int frameMoveDropType{NONE}; std::optional<Reference> frameMoveDropTarget{};
int frameMoveDropItemID{-1};
int frameMoveDropGroupType{NONE};
int frameMoveDropGroupId{-1};
int frameMoveDropIndex{-1};
bool isFrameMoveDropTarget{};
float playheadLineCenterX{}; float playheadLineCenterX{};
float playheadLineTopY{}; float playheadLineTopY{};
bool isPlayheadLineSet{}; bool isPlayheadLineSet{};
@@ -201,8 +181,7 @@ namespace anm2ed::imgui
const model::Track* selected_item_get(); const model::Track* selected_item_get();
const model::TrackGroup* track_group_get(int type, int groupId); const model::TrackGroup* track_group_get(int type, int groupId);
bool is_track_group_visible(int type, int groupId); bool is_track_group_visible(int type, int groupId);
const model::TrackGroup* row_group_get(const TimelineItemRow& row); const model::TrackGroup* row_group_get(const TimelineRow& row);
const model::Track* command_item_reference_get(Document& document, Reference itemReference);
glm::vec4 color_get(TimelineColor, int); glm::vec4 color_get(TimelineColor, int);
std::set<Reference> drag_frame_references_get(const Reference&); std::set<Reference> drag_frame_references_get(const Reference&);
// Queues an edit on the document; its result is selected (frames by default). // Queues an edit on the document; its result is selected (frames by default).
@@ -213,26 +192,17 @@ namespace anm2ed::imgui
[=, this](Manager&, Document& document) mutable [=, this](Manager&, Document& document) mutable
{ {
auto uids = document.edit_apply(label, operation); auto uids = document.edit_apply(label, operation);
select ? select(document, uids) : frames_select_for(document, uids); select ? select(document, uids) : document.frames_select(uids);
}); });
} }
void edit_begin_push(StringType); void edit_begin_push(StringType);
void reference_set(Reference); void reference_set(Reference);
void frames_select_for(Document&, const edit::Uids&);
const model::Frame* command_frame_get(Document& document, const Reference& targetReference);
Reference item_reference_get(int type, int id, int groupType = NONE, int groupId = -1); Reference item_reference_get(int type, int id, int groupType = NONE, int groupId = -1);
Reference item_reference_from_frame_get(Reference frameReference); Reference item_reference_from_frame_get(Reference frameReference);
bool is_same_item(const Reference& left, const Reference& right); bool is_same_item(const Reference& left, const Reference& right);
void group_selection_reset_for(Document& targetDocument); void group_selection_reset_for(Document& targetDocument);
std::set<Reference> item_references_for_current_get(); std::set<Reference> item_references_for_current_get();
void frame_selection_set_for(Document& targetDocument, Reference frameReference);
void frame_selection_toggle_for(Document& targetDocument, Reference frameReference);
bool frame_selection_range_set_for(Document& targetDocument, Reference firstReference, Reference lastReference,
bool isAdditive);
std::set<Reference> copy_frame_references_get(); std::set<Reference> copy_frame_references_get();
void frames_selection_set_reference_for(Document& targetDocument);
void reference_clear_for(Document& targetDocument);
void reference_set_timeline_item_reference_for(Document& targetDocument, Reference itemReference);
void command_push(std::function<void(Manager&, Document&)> run); void command_push(std::function<void(Manager&, Document&)> run);
void overlay_icon(GLuint textureId, ImVec4 tint, bool isForced = false); void overlay_icon(GLuint textureId, ImVec4 tint, bool isForced = false);
void playback_stop(); void playback_stop();
@@ -250,27 +220,19 @@ namespace anm2ed::imgui
bool is_bake_into_other_frames_ready(); bool is_bake_into_other_frames_ready();
void bake_into_other_frames(); void bake_into_other_frames();
void frame_split(); void frame_split();
std::vector<TimelineItemRow> timeline_item_rows_get(); std::vector<TimelineRow> timeline_item_rows_get();
std::vector<Reference> timeline_item_references_get(); bool is_row_selected(const TimelineRow& row);
Reference group_reference_get(const TimelineItemRow& row);
TimelineRowReference row_reference_get(const TimelineItemRow& row);
Reference row_item_reference_get(const TimelineRowReference& row);
std::vector<TimelineRowReference> timeline_row_references_get();
bool is_group_selected(const TimelineItemRow& row);
bool is_row_selected(const TimelineItemRow& row);
void row_selection_clear(); void row_selection_clear();
void row_selection_insert(const TimelineRowReference& row); void row_selection_insert(const TimelineRow& row);
void row_selection_erase(const TimelineRowReference& row); bool is_row_reference_selected(const TimelineRow& row);
bool is_row_reference_selected(const TimelineRowReference& row); void row_selection_set(const TimelineRow& row);
std::size_t row_selection_count_get();
void row_selection_set(const TimelineItemRow& row);
void reference_set_adjacent_item(int direction); void reference_set_adjacent_item(int direction);
std::vector<TimelineRowReference> selected_row_references_get(); std::vector<TimelineRow> selected_row_references_get();
std::vector<TimelineRowReference> row_drag_references_get(const TimelineItemRow& row); std::vector<TimelineRow> row_drag_references_get(const TimelineRow& row);
void item_remove(); void item_remove();
std::vector<Reference> item_references_groupable_get(); std::vector<Reference> item_references_groupable_get();
void item_group(); void item_group();
void rows_move_to_row(std::vector<TimelineRowReference> draggedRows, TimelineItemRow targetRow, bool isDropAfter, void rows_move_to_row(std::vector<TimelineRow> draggedRows, TimelineRow targetRow, bool isDropAfter,
bool isDropIntoGroup = false); bool isDropIntoGroup = false);
void fit_animation_length(); void fit_animation_length();
void frame_references_copy(const std::set<Reference>& selectedFrames); void frame_references_copy(const std::set<Reference>& selectedFrames);
@@ -279,23 +241,20 @@ namespace anm2ed::imgui
void paste(); void paste();
void context_menu(); void context_menu();
void item_base_properties_open(int type, int id); void item_base_properties_open(int type, int id);
void group_properties_close(); void group_properties_open(const TimelineRow& row, const model::TrackGroup& group);
void group_properties_open(const TimelineItemRow& row, const model::TrackGroup& group);
void group_properties_update(); void group_properties_update();
void item_context_menu(); void item_context_menu();
TimelineContext(TimelineState&&, Manager&, Settings&, Resources&, Clipboard&); TimelineContext(TimelineState&&, Manager&, Settings&, Resources&, Clipboard&);
void update(); void update();
void frame_begin(); void frame_begin();
void item_child(const TimelineItemRow&, int); void item_child(const TimelineRow&, int);
void items_child(); void items_child();
void frame_move_drag_clear(); void frames_move_to(Reference);
void frames_move_to(int, int, int, int, int);
ImVec2 frame_box_content_point_get(); ImVec2 frame_box_content_point_get();
ImVec2 frame_box_screen_point_get(ImVec2); ImVec2 frame_box_screen_point_get(ImVec2);
bool is_frame_box_overlapping(ImVec2, ImVec2, ImVec2, ImVec2);
void frame_overlay_draw(ImDrawList*, ImVec2, ImVec2); void frame_overlay_draw(ImDrawList*, ImVec2, ImVec2);
void frame_child(const TimelineItemRow&, int&, float); void frame_child(const TimelineRow&, int&, float);
void frames_child(); void frames_child();
void draw(); void draw();
}; };
+11 -11
View File
@@ -6,7 +6,7 @@ namespace anm2ed::imgui
{ {
auto targetReference = reference; auto targetReference = reference;
auto time = (int)document.frameTime; auto time = (int)document.frameTime;
if (!animation || !command_item_reference_get(document, targetReference)) return; if (!animation || !document.model.track_get(targetReference)) return;
edit_push(EDIT_INSERT_FRAME, [=](model::Model& model) { return edit::frame_insert(model, targetReference, time); }); edit_push(EDIT_INSERT_FRAME, [=](model::Model& model) { return edit::frame_insert(model, targetReference, time); });
} }
@@ -16,7 +16,7 @@ namespace anm2ed::imgui
if (selectedFrames.empty()) return; if (selectedFrames.empty()) return;
edit_push( edit_push(
EDIT_DELETE_FRAMES, [=](model::Model& model) { return edit::frames_delete(model, selectedFrames); }, EDIT_DELETE_FRAMES, [=](model::Model& model) { return edit::frames_delete(model, selectedFrames); },
[this](Document& document, const edit::Uids&) { frames_selection_set_reference_for(document); }); [this](Document& document, const edit::Uids&) { document.frame_focus_select(); });
} }
void TimelineContext::frames_duplicate() void TimelineContext::frames_duplicate()
@@ -133,7 +133,7 @@ namespace anm2ed::imgui
{ return edit::items_remove(model, animationIndex, ids, groupIds); }, { return edit::items_remove(model, animationIndex, ids, groupIds); },
[this](Document& document, const edit::Uids&) [this](Document& document, const edit::Uids&)
{ {
reference_clear_for(document); document.focus_clear();
group_selection_reset_for(document); group_selection_reset_for(document);
}); });
} }
@@ -182,8 +182,8 @@ namespace anm2ed::imgui
}); });
} }
void TimelineContext::rows_move_to_row(std::vector<TimelineRowReference> draggedRows, TimelineItemRow targetRow, void TimelineContext::rows_move_to_row(std::vector<TimelineRow> draggedRows, TimelineRow targetRow, bool isDropAfter,
bool isDropAfter, bool isDropIntoGroup) bool isDropIntoGroup)
{ {
if (draggedRows.empty()) return; if (draggedRows.empty()) return;
auto targetType = draggedRows.front().type; auto targetType = draggedRows.front().type;
@@ -198,13 +198,13 @@ namespace anm2ed::imgui
std::set<int> groupIds{}; std::set<int> groupIds{};
for (const auto& row : draggedRows) for (const auto& row : draggedRows)
(row.isGroup ? groupIds : ids).insert(row.id); (row.isGroup ? groupIds : ids).insert(row.id);
edit::RowTarget target{targetRow.isGroup, targetRow.type, targetRow.id, targetRow.groupId}; edit::RowTarget target{targetRow.isGroup, targetRow.type, targetRow.id,
targetRow.type == ROOT ? -1 : targetRow.groupId};
auto animationIndex = reference.animationIndex; auto animationIndex = reference.animationIndex;
std::set<Reference> tracks{}; std::set<Reference> tracks{};
std::set<Reference> groups{}; std::set<Reference> groups{};
for (const auto& row : draggedRows) for (const auto& row : draggedRows)
(row.isGroup ? groups : tracks) (row.isGroup ? groups : tracks).insert(row_selection_reference_get(row));
.insert(row.isGroup ? Reference{row.animationIndex, row.type, row.id} : row_item_reference_get(row));
Selection moved{}; Selection moved{};
selection_references_set(moved, model, SelectionKind::TRACKS, tracks); selection_references_set(moved, model, SelectionKind::TRACKS, tracks);
selection_references_set(moved, model, SelectionKind::GROUPS, groups); selection_references_set(moved, model, SelectionKind::GROUPS, groups);
@@ -265,14 +265,14 @@ namespace anm2ed::imgui
frame_references_copy(selectedFrames); frame_references_copy(selectedFrames);
edit_push( edit_push(
EDIT_CUT_FRAMES, [=](model::Model& model) { return edit::frames_delete(model, selectedFrames); }, EDIT_CUT_FRAMES, [=](model::Model& model) { return edit::frames_delete(model, selectedFrames); },
[this](Document& document, const edit::Uids&) { frames_selection_set_reference_for(document); }); [this](Document& document, const edit::Uids&) { document.frame_focus_select(); });
} }
void TimelineContext::paste() void TimelineContext::paste()
{ {
auto text = clipboard.get(); auto text = clipboard.get();
if (text.empty()) return; if (text.empty()) return;
if (!command_item_reference_get(document, reference)) if (!document.model.track_get(reference))
{ {
toast_log(Level::WARNING, TOAST_DESERIALIZE_FRAMES_NO_SELECTION); toast_log(Level::WARNING, TOAST_DESERIALIZE_FRAMES_NO_SELECTION);
return; return;
@@ -287,7 +287,7 @@ namespace anm2ed::imgui
{ return edit::frames_paste(model, targetReference, selectedFrames, text, time, errorString.get()); }, { return edit::frames_paste(model, targetReference, selectedFrames, text, time, errorString.get()); },
[=, this](Document& document, const edit::Uids& uids) [=, this](Document& document, const edit::Uids& uids)
{ {
if (errorString->empty()) return frames_select_for(document, uids); if (errorString->empty()) return document.frames_select(uids);
toasts.push(std::format("{} {}", localize.get(TOAST_DESERIALIZE_FRAMES_FAILED), *errorString)); toasts.push(std::format("{} {}", localize.get(TOAST_DESERIALIZE_FRAMES_FAILED), *errorString));
logger.error( logger.error(
std::format("{} {}", localize.get(TOAST_DESERIALIZE_FRAMES_FAILED, anm2ed::ENGLISH), *errorString)); std::format("{} {}", localize.get(TOAST_DESERIALIZE_FRAMES_FAILED, anm2ed::ENGLISH), *errorString));
+31 -78
View File
@@ -2,43 +2,25 @@
namespace anm2ed::imgui namespace anm2ed::imgui
{ {
void TimelineContext::frame_move_drag_clear() // Moves the dragged frames to `target`'s track, before its frame index.
{ void TimelineContext::frames_move_to(Reference target)
frameMoveDrag = {};
frameMoveDropType = NONE;
frameMoveDropItemID = -1;
frameMoveDropGroupType = NONE;
frameMoveDropGroupId = -1;
frameMoveDropIndex = -1;
isFrameMoveDropTarget = false;
}
void TimelineContext::frames_move_to(int targetType, int targetID, int targetGroupType, int targetGroupId,
int insertIndex)
{ {
if (!frameMoveDrag.isActive || !animation || frameMoveDrag.animationIndex != reference.animationIndex) return; if (!frameMoveDrag.isActive || !animation || frameMoveDrag.animationIndex != reference.animationIndex) return;
if (targetType == TRIGGER) return; if (target.itemType == TRIGGER) return;
auto drag = frameMoveDrag; auto frames = std::set<Reference>(frameMoveDrag.references.begin(), frameMoveDrag.references.end());
std::erase_if(drag.references, [](const Reference& frameReference) std::erase_if(frames, [](const Reference& frame) { return frame.itemType == TRIGGER || frame.frameIndex < 0; });
{ return frameReference.itemType == TRIGGER || frameReference.frameIndex < 0; }); if (frames.empty()) return;
if (drag.references.empty() && drag.frameIndex >= 0)
drag.references.push_back(
{drag.animationIndex, drag.type, drag.itemID, drag.frameIndex, drag.groupType, drag.groupId});
std::erase_if(drag.references, [](const Reference& frameReference)
{ return frameReference.itemType == TRIGGER || frameReference.frameIndex < 0; });
if (drag.references.empty()) return;
Reference target{drag.animationIndex, targetType, targetID, -1, targetGroupType, targetGroupId}; auto insertIndex = std::exchange(target.frameIndex, -1);
edit_push( edit_push(
EDIT_MOVE_FRAMES, EDIT_MOVE_FRAMES, [frames, target, insertIndex](model::Model& model)
[frames = std::set<Reference>(drag.references.begin(), drag.references.end()), target, { return edit::frames_move(model, frames, target, insertIndex); },
insertIndex](model::Model& model) { return edit::frames_move(model, frames, target, insertIndex); },
[=, this](Document& document, const edit::Uids& uids) [=, this](Document& document, const edit::Uids& uids)
{ {
frames_select_for(document, uids); document.frames_select(uids);
if (targetType == LAYER) if (target.itemType == LAYER)
if (auto layer = model::item_get(document.model.content.layers, targetID)) if (auto layer = model::item_get(document.model.content.layers, target.itemID))
document.focused_id_set(SelectionKind::SPRITESHEETS, layer->spritesheetId); document.focused_id_set(SelectionKind::SPRITESHEETS, layer->spritesheetId);
}); });
} }
@@ -54,11 +36,6 @@ namespace anm2ed::imgui
return ImVec2(point.x - scroll.x + frameBoxClipMin.x, point.y - scroll.y + frameBoxClipMin.y); return ImVec2(point.x - scroll.x + frameBoxClipMin.x, point.y - scroll.y + frameBoxClipMin.y);
} }
bool TimelineContext::is_frame_box_overlapping(ImVec2 leftMin, ImVec2 leftMax, ImVec2 rightMin, ImVec2 rightMax)
{
return leftMin.x <= rightMax.x && leftMax.x >= rightMin.x && leftMin.y <= rightMax.y && leftMax.y >= rightMin.y;
}
void TimelineContext::frame_overlay_draw(ImDrawList* drawList, ImVec2 clipMin, ImVec2 clipMax) void TimelineContext::frame_overlay_draw(ImDrawList* drawList, ImVec2 clipMin, ImVec2 clipMax)
{ {
if (isFrameBoxSelecting && isFrameBoxClipSet) if (isFrameBoxSelecting && isFrameBoxClipSet)
@@ -90,12 +67,12 @@ namespace anm2ed::imgui
} }
} }
void TimelineContext::frame_child(const TimelineItemRow& row, int& index, float width) void TimelineContext::frame_child(const TimelineRow& row, int& index, float width)
{ {
auto type = row.type; auto type = row.type;
auto id = row.id; auto id = row.id;
auto row_reference_make = [&](int frameIndex = -1) auto row_reference_make = [&](int frameIndex = -1)
{ return Reference{reference.animationIndex, type, id, frameIndex, row.rootGroupType, row.rootGroupId}; }; { return Reference{reference.animationIndex, type, id, frameIndex, row.groupType, row.groupId}; };
auto childSize = ImVec2(width, rowFrameChildHeight); auto childSize = ImVec2(width, rowFrameChildHeight);
if (row.isGroup) if (row.isGroup)
{ {
@@ -111,12 +88,12 @@ namespace anm2ed::imgui
return; return;
} }
auto item = item_get(type, id, row.rootGroupType, row.rootGroupId); auto item = item_get(type, id, row.groupType, row.groupId);
if (type != NONE && !item) return; if (type != NONE && !item) return;
auto isVisible = item ? item->isVisible && is_track_group_visible(type, row.groupId) : false; auto isVisible = item ? item->isVisible && is_track_group_visible(type, row.groupId) : false;
if (item && type == ROOT && row.rootGroupId != -1) if (item && type == ROOT && row.groupId != -1)
isVisible = item->isVisible && is_track_group_visible(row.rootGroupType, row.rootGroupId); isVisible = item->isVisible && is_track_group_visible(row.groupType, row.groupId);
auto& isOnlyShowLayers = settings.timelineIsOnlyShowLayers; auto& isOnlyShowLayers = settings.timelineIsOnlyShowLayers;
if (isOnlyShowLayers && type != LAYER) isVisible = false; if (isOnlyShowLayers && type != LAYER) isVisible = false;
@@ -174,7 +151,8 @@ namespace anm2ed::imgui
auto frameEnd = type == TRIGGER ? frameStart + 1.0f : frameStart + frame.duration; auto frameEnd = type == TRIGGER ? frameStart + 1.0f : frameStart + frame.duration;
auto frameContentMin = ImVec2(frameStart * frameSize.x, rowMinY); auto frameContentMin = ImVec2(frameStart * frameSize.x, rowMinY);
auto frameContentMax = ImVec2(frameEnd * frameSize.x, rowMaxY); auto frameContentMax = ImVec2(frameEnd * frameSize.x, rowMaxY);
if (is_frame_box_overlapping(frameContentMin, frameContentMax, boxMin, boxMax)) if (frameContentMin.x <= boxMax.x && frameContentMax.x >= boxMin.x && frameContentMin.y <= boxMax.y &&
frameContentMax.y >= boxMin.y)
frameBoxSelection.insert(frameReference); frameBoxSelection.insert(frameReference);
if (type != TRIGGER) selectionFrameTime += frame.duration; if (type != TRIGGER) selectionFrameTime += frame.duration;
++frameIndex; ++frameIndex;
@@ -193,7 +171,7 @@ namespace anm2ed::imgui
} }
else if (reference.itemType != NONE || reference.itemID != -1) else if (reference.itemType != NONE || reference.itemID != -1)
group_selection_reset_for(document); group_selection_reset_for(document);
reference_clear_for(document); document.focus_clear();
} }
if (type == NONE) if (type == NONE)
@@ -350,12 +328,7 @@ namespace anm2ed::imgui
++frameIndex; ++frameIndex;
} }
frameMoveDropType = type; frameMoveDropTarget = Reference{reference.animationIndex, type, id, dropIndex, row.groupType, row.groupId};
frameMoveDropItemID = id;
frameMoveDropGroupType = row.rootGroupType;
frameMoveDropGroupId = row.rootGroupId;
frameMoveDropIndex = dropIndex;
isFrameMoveDropTarget = true;
auto dropX = cursorScreenPos.x + dropFrameTime * frameSize.x; auto dropX = cursorScreenPos.x + dropFrameTime * frameSize.x;
auto previewWidth = glm::max(frameSize.x, (float)frameMoveDrag.duration * frameSize.x); auto previewWidth = glm::max(frameSize.x, (float)frameMoveDrag.duration * frameSize.x);
@@ -433,25 +406,15 @@ namespace anm2ed::imgui
auto isShiftDown = ImGui::IsKeyDown(ImGuiMod_Shift); auto isShiftDown = ImGui::IsKeyDown(ImGuiMod_Shift);
if (isShiftDown) if (isShiftDown)
{ {
auto isHadAnchor = isFrameSelectionAnchorSet; auto isRangeSelected = document.frames_range_select(frameSelectionAnchor.value_or(frameReference),
auto anchorReference = isHadAnchor ? frameSelectionAnchor : frameReference; frameReference, isCtrlDown);
auto isRangeSelected = if (!isRangeSelected) document.frame_select(frameReference);
frame_selection_range_set_for(document, anchorReference, frameReference, isCtrlDown); if (!frameSelectionAnchor || !isRangeSelected) frameSelectionAnchor = frameReference;
if (!isRangeSelected) frame_selection_set_for(document, frameReference);
if (!isHadAnchor || !isRangeSelected) frameSelectionAnchor = frameReference;
isFrameSelectionAnchorSet = true;
}
else if (isCtrlDown)
{
frame_selection_toggle_for(document, frameReference);
frameSelectionAnchor = frameReference;
isFrameSelectionAnchorSet = true;
} }
else else
{ {
frame_selection_set_for(document, frameReference); isCtrlDown ? document.frame_toggle(frameReference) : document.frame_select(frameReference);
frameSelectionAnchor = frameReference; frameSelectionAnchor = frameReference;
isFrameSelectionAnchorSet = true;
} }
reference_set(frameReference); reference_set(frameReference);
isReferenced = true; isReferenced = true;
@@ -470,13 +433,12 @@ namespace anm2ed::imgui
isDraggedFrameActive = true; isDraggedFrameActive = true;
draggedFrameReference = frameReference; draggedFrameReference = frameReference;
draggedFrameType = type; draggedFrameType = type;
draggedFrameIndex = frameIndex;
draggedFrameStart = hoveredTime; draggedFrameStart = hoveredTime;
if (type != TRIGGER) draggedFrameStartDuration = frame.duration; if (type != TRIGGER) draggedFrameStartDuration = frame.duration;
draggedFrameStartDurations.clear(); draggedFrameStartDurations.clear();
if (type != TRIGGER) if (type != TRIGGER)
for (auto selectedReference : drag_frame_references_get(frameReference)) for (auto selectedReference : drag_frame_references_get(frameReference))
if (auto selectedFrame = command_frame_get(document, selectedReference)) if (auto selectedFrame = document.model.frame_get(selectedReference))
draggedFrameStartDurations.push_back({selectedReference, selectedFrame->duration}); draggedFrameStartDurations.push_back({selectedReference, selectedFrame->duration});
draggedFrameStartMouseX = ImGui::GetIO().MousePos.x; draggedFrameStartMouseX = ImGui::GetIO().MousePos.x;
draggedFrameWidth = frameSize.x; draggedFrameWidth = frameSize.x;
@@ -492,22 +454,14 @@ namespace anm2ed::imgui
auto selectedReferences = drag_frame_references_get(frameReference); auto selectedReferences = drag_frame_references_get(frameReference);
int dragDuration = 0; int dragDuration = 0;
for (auto selectedReference : selectedReferences) for (auto selectedReference : selectedReferences)
if (auto selectedFrame = command_frame_get(document, selectedReference)) if (auto selectedFrame = document.model.frame_get(selectedReference))
dragDuration += selectedFrame->duration; dragDuration += selectedFrame->duration;
dragDuration = glm::max(1, dragDuration); dragDuration = glm::max(1, dragDuration);
frameMoveDrag = { frameMoveDrag = {.animationIndex = reference.animationIndex,
.type = type,
.itemID = id,
.animationIndex = reference.animationIndex,
.groupType = row.rootGroupType,
.groupId = row.rootGroupId,
.frameIndex = frameIndex,
.duration = dragDuration, .duration = dragDuration,
.indices = {},
.references = {selectedReferences.begin(), selectedReferences.end()}, .references = {selectedReferences.begin(), selectedReferences.end()},
.isActive = true, .isActive = true};
};
} }
} }
@@ -599,7 +553,6 @@ namespace anm2ed::imgui
isDraggedFrameActive = false; isDraggedFrameActive = false;
draggedFrameReference = {}; draggedFrameReference = {};
draggedFrameType = NONE; draggedFrameType = NONE;
draggedFrameIndex = -1;
draggedFrameStart = -1; draggedFrameStart = -1;
draggedFrameStartDuration = -1; draggedFrameStartDuration = -1;
draggedFrameStartDurations.clear(); draggedFrameStartDurations.clear();
@@ -722,7 +675,7 @@ namespace anm2ed::imgui
ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableSetupColumn("##Frames"); ImGui::TableSetupColumn("##Frames");
auto frames_child_row = [&](const TimelineItemRow& row) auto frames_child_row = [&](const TimelineRow& row)
{ {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0); ImGui::TableSetColumnIndex(0);
+7 -16
View File
@@ -64,7 +64,7 @@ namespace anm2ed::imgui
command_push( command_push(
[=, this](Manager& manager, Document& document) [=, this](Manager& manager, Document& document)
{ {
auto frame = command_frame_get(document, targetReference); auto frame = document.model.frame_get(targetReference);
if (!frame || frame->regionId != -1) return; if (!frame || frame->regionId != -1) return;
auto layer = model::item_get(document.model.content.layers, targetReference.itemID); auto layer = model::item_get(document.model.content.layers, targetReference.itemID);
if (!layer) return; if (!layer) return;
@@ -91,7 +91,7 @@ namespace anm2ed::imgui
auto is_region_makeable = [&](const Reference& frameReference) auto is_region_makeable = [&](const Reference& frameReference)
{ {
if (frameReference.itemType != LAYER || frameReference.frameIndex < 0) return false; if (frameReference.itemType != LAYER || frameReference.frameIndex < 0) return false;
auto frame = command_frame_get(document, frameReference); auto frame = document.model.frame_get(frameReference);
auto layer = model::item_get(model.content.layers, frameReference.itemID); auto layer = model::item_get(model.content.layers, frameReference.itemID);
return frame && frame->regionId == -1 && layer && return frame && frame->regionId == -1 && layer &&
model::item_get(model.content.spritesheets, layer->spritesheetId); model::item_get(model.content.spritesheets, layer->spritesheetId);
@@ -163,16 +163,7 @@ namespace anm2ed::imgui
manager.item_properties_open(type == LAYER ? ElementType::LAYER_ELEMENT : ElementType::NULL_ELEMENT, id); manager.item_properties_open(type == LAYER ? ElementType::LAYER_ELEMENT : ElementType::NULL_ELEMENT, id);
} }
void TimelineContext::group_properties_close() void TimelineContext::group_properties_open(const TimelineRow& row, const model::TrackGroup& group)
{
groupName.clear();
groupAnimationIndex = -1;
groupType = NONE;
groupId = -1;
groupPropertiesPopup.close();
}
void TimelineContext::group_properties_open(const TimelineItemRow& row, const model::TrackGroup& group)
{ {
groupName = group.name.empty() ? std::string(localize.get(TEXT_NEW_GROUP)) : group.name; groupName = group.name.empty() ? std::string(localize.get(TEXT_NEW_GROUP)) : group.name;
groupAnimationIndex = reference.animationIndex; groupAnimationIndex = reference.animationIndex;
@@ -210,7 +201,7 @@ namespace anm2ed::imgui
group->name = targetName; group->name = targetName;
}); });
} }
if (result != PopupButton::NONE) group_properties_close(); if (result != PopupButton::NONE) groupPropertiesPopup.close();
ImGui::EndPopup(); ImGui::EndPopup();
} }
@@ -229,15 +220,15 @@ namespace anm2ed::imgui
auto selectedRows = selected_row_references_get(); auto selectedRows = selected_row_references_get();
auto selectedGroupableItems = item_references_groupable_get(); auto selectedGroupableItems = item_references_groupable_get();
auto copyFrames = copy_frame_references_get(); auto copyFrames = copy_frame_references_get();
TimelineItemRow selectedGroupRow{}; TimelineRow selectedGroupRow{};
const model::TrackGroup* selectedGroup{}; const model::TrackGroup* selectedGroup{};
if (selectedRows.size() == 1 && selectedRows.front().isGroup) if (selectedRows.size() == 1 && selectedRows.front().isGroup)
{ {
auto row = selectedRows.front(); auto row = selectedRows.front();
selectedGroupRow = {.type = row.type, .id = row.id, .index = row.index, .isGroup = true}; selectedGroupRow = row;
selectedGroup = row_group_get(selectedGroupRow); selectedGroup = row_group_get(selectedGroupRow);
} }
auto isRemoveAvailable = std::ranges::any_of(selectedRows, [](const TimelineRowReference& row) auto isRemoveAvailable = std::ranges::any_of(selectedRows, [](const TimelineRow& row)
{ return row.type == LAYER || row.type == NULL_; }); { return row.type == LAYER || row.type == NULL_; });
auto item_cut = [&]() auto item_cut = [&]()
{ {
+3 -5
View File
@@ -12,10 +12,8 @@ namespace anm2ed::imgui
frames_child(); frames_child();
if (frameMoveDrag.isActive && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) if (frameMoveDrag.isActive && ImGui::IsMouseReleased(ImGuiMouseButton_Left))
{ {
if (isFrameMoveDropTarget) if (frameMoveDropTarget) frames_move_to(*frameMoveDropTarget);
frames_move_to(frameMoveDropType, frameMoveDropItemID, frameMoveDropGroupType, frameMoveDropGroupId, frameMoveDrag = {};
frameMoveDropIndex);
frame_move_drag_clear();
} }
items_child(); items_child();
} }
@@ -202,7 +200,7 @@ namespace anm2ed::imgui
frameReference.frameIndex = glm::clamp(reference.frameIndex + (int)isNextFrame - (int)isPreviousFrame, 0, frameReference.frameIndex = glm::clamp(reference.frameIndex + (int)isNextFrame - (int)isPreviousFrame, 0,
(int)item->frames.size() - 1); (int)item->frames.size() - 1);
reference_set(frameReference); reference_set(frameReference);
frames_selection_set_reference_for(document); document.frame_focus_select();
document.frameTime = model::frame_time_from_index_get(*item, reference.frameIndex); document.frameTime = model::frame_time_from_index_get(*item, reference.frameIndex);
} }
+51 -189
View File
@@ -19,24 +19,14 @@ namespace anm2ed::imgui
return !group || group->isVisible; return !group || group->isVisible;
} }
const model::TrackGroup* TimelineContext::row_group_get(const TimelineItemRow& row) const model::TrackGroup* TimelineContext::row_group_get(const TimelineRow& row)
{ {
return row.isGroup ? track_group_get(row.type, row.id) : nullptr; return row.isGroup ? track_group_get(row.type, row.id) : nullptr;
} }
const model::Track* TimelineContext::command_item_reference_get(Document& document, Reference itemReference) const model::Frame* TimelineContext::frame_get() { return document.model.frame_get(reference); }
{
return document.model.track_get(itemReference);
}
const model::Frame* TimelineContext::command_frame_get(Document& document, const Reference& targetReference) const model::Track* TimelineContext::selected_item_get() { return document.model.track_get(reference); }
{
return document.model.frame_get(targetReference);
}
const model::Frame* TimelineContext::frame_get() { return command_frame_get(document, reference); }
const model::Track* TimelineContext::selected_item_get() { return command_item_reference_get(document, reference); }
glm::vec4 TimelineContext::color_get(TimelineColor color, int type) glm::vec4 TimelineContext::color_get(TimelineColor color, int type)
{ {
@@ -63,18 +53,6 @@ namespace anm2ed::imgui
document.reference_set(value); document.reference_set(value);
} }
void TimelineContext::frames_select_for(Document& targetDocument, const edit::Uids& uids)
{
auto references = targetDocument.references_get(uids);
if (references.empty()) return;
auto focus = references.front();
targetDocument.editTarget = Document::EditTarget::FRAME;
targetDocument.frame_references_set({references.begin(), references.end()});
targetDocument.reference_set(focus);
if (auto item = command_item_reference_get(targetDocument, focus); item && focus.itemType != TRIGGER)
targetDocument.frameTime = model::frame_time_from_index_get(*item, focus.frameIndex);
}
Reference TimelineContext::item_reference_get(int type, int id, int groupType, int groupId) Reference TimelineContext::item_reference_get(int type, int id, int groupType, int groupId)
{ {
return Reference{reference.animationIndex, type, id, -1, groupType, groupId}; return Reference{reference.animationIndex, type, id, -1, groupType, groupId};
@@ -95,7 +73,7 @@ namespace anm2ed::imgui
void TimelineContext::group_selection_reset_for(Document& targetDocument) void TimelineContext::group_selection_reset_for(Document& targetDocument)
{ {
targetDocument.selection.uids[SelectionKind::GROUPS].clear(); targetDocument.selection.uids[SelectionKind::GROUPS].clear();
isRowSelectionAnchorSet = false; rowSelectionAnchor.reset();
} }
std::set<Reference> TimelineContext::item_references_for_current_get() std::set<Reference> TimelineContext::item_references_for_current_get()
@@ -105,54 +83,6 @@ namespace anm2ed::imgui
return result; return result;
} }
void TimelineContext::frame_selection_set_for(Document& targetDocument, Reference frameReference)
{
group_selection_reset_for(targetDocument);
targetDocument.editTarget = Document::EditTarget::FRAME;
targetDocument.frame_references_set({frameReference});
targetDocument.reference_set(frameReference);
}
void TimelineContext::frame_selection_toggle_for(Document& targetDocument, Reference frameReference)
{
group_selection_reset_for(targetDocument);
targetDocument.editTarget = Document::EditTarget::FRAME;
auto selection = targetDocument.frame_references_get(Document::FrameReferenceFallback::NONE);
if (!selection.contains(frameReference))
selection.insert(frameReference);
else if (selection.size() > 1)
selection.erase(frameReference);
targetDocument.frame_references_set(selection);
targetDocument.reference_set(frameReference);
}
bool TimelineContext::frame_selection_range_set_for(Document& targetDocument, Reference firstReference,
Reference lastReference, bool isAdditive)
{
group_selection_reset_for(targetDocument);
targetDocument.editTarget = Document::EditTarget::FRAME;
if (!is_same_item(firstReference, lastReference) || firstReference.frameIndex < 0 || lastReference.frameIndex < 0)
return false;
auto item = command_item_reference_get(targetDocument, lastReference);
if (!item || std::max(firstReference.frameIndex, lastReference.frameIndex) >= model::track_frames_count_get(*item))
return false;
auto [firstIndex, lastIndex] = std::minmax(firstReference.frameIndex, lastReference.frameIndex);
auto selectedFrames = isAdditive ? targetDocument.frame_references_get(Document::FrameReferenceFallback::NONE)
: std::set<Reference>{};
for (int i = firstIndex; i <= lastIndex; ++i)
{
auto frameReference = lastReference;
frameReference.frameIndex = i;
selectedFrames.insert(frameReference);
}
targetDocument.frame_references_set(selectedFrames);
targetDocument.reference_set(lastReference);
return true;
}
std::set<Reference> TimelineContext::copy_frame_references_get() std::set<Reference> TimelineContext::copy_frame_references_get()
{ {
auto selectedFrames = document.frame_references_get(Document::FrameReferenceFallback::NONE); auto selectedFrames = document.frame_references_get(Document::FrameReferenceFallback::NONE);
@@ -173,41 +103,15 @@ namespace anm2ed::imgui
return result; return result;
} }
void TimelineContext::frames_selection_set_reference_for(Document& targetDocument)
{
auto targetReference = targetDocument.reference_get();
if (targetReference.frameIndex < 0) return targetDocument.frame_references_clear();
targetDocument.editTarget = Document::EditTarget::FRAME;
targetDocument.frame_references_set({targetReference});
}
void TimelineContext::reference_clear_for(Document& targetDocument)
{
targetDocument.reference_set({targetDocument.reference_get().animationIndex});
targetDocument.frame_references_clear();
targetDocument.selection.uids[SelectionKind::TRACKS].clear();
}
void TimelineContext::reference_set_timeline_item_reference_for(Document& targetDocument, Reference itemReference)
{
itemReference.frameIndex = -1;
if (itemReference.itemType == LAYER)
if (auto layer = model::item_get(targetDocument.model.content.layers, itemReference.itemID))
targetDocument.focused_id_set(SelectionKind::SPRITESHEETS, layer->spritesheetId);
targetDocument.reference_set(itemReference);
targetDocument.frame_references_clear();
targetDocument.selected_set(SelectionKind::TRACKS, {itemReference});
}
void TimelineContext::command_push(std::function<void(Manager&, Document&)> run) void TimelineContext::command_push(std::function<void(Manager&, Document&)> run)
{ {
manager.command_push( manager.command_push(
{manager.selected, [run](Manager& manager, Document& document) mutable { run(manager, document); }}); {manager.selected, [run](Manager& manager, Document& document) mutable { run(manager, document); }});
} }
std::vector<TimelineItemRow> TimelineContext::timeline_item_rows_get() std::vector<TimelineRow> TimelineContext::timeline_item_rows_get()
{ {
std::vector<TimelineItemRow> rows{}; std::vector<TimelineRow> rows{};
if (!animation) return rows; if (!animation) return rows;
auto is_track_shown = [&](const model::Track& track) auto is_track_shown = [&](const model::Track& track)
@@ -236,85 +140,50 @@ namespace anm2ed::imgui
auto& group = std::get<model::TrackGroup>(entries[index]); auto& group = std::get<model::TrackGroup>(entries[index]);
rows.push_back({.type = type, .id = group.id, .index = index, .isGroup = true}); rows.push_back({.type = type, .id = group.id, .index = index, .isGroup = true});
if (!group.isExpanded) continue; if (!group.isExpanded) continue;
rows.push_back({.type = ROOT, .id = -1, .rootGroupType = type, .rootGroupId = group.id, .depth = 1}); rows.push_back({.type = ROOT, .groupType = type, .groupId = group.id, .depth = 1});
for (auto trackIndex : order_get((int)group.tracks.size(), isReversed)) for (auto trackIndex : order_get((int)group.tracks.size(), isReversed))
if (auto& track = group.tracks[trackIndex]; is_track_shown(track)) if (auto& track = group.tracks[trackIndex]; is_track_shown(track))
rows.push_back({.type = type, rows.push_back({.type = type,
.id = track.id, .id = track.id,
.index = trackIndex, .index = trackIndex,
.groupType = type,
.groupId = group.id, .groupId = group.id,
.rootGroupType = type,
.rootGroupId = group.id,
.depth = 1}); .depth = 1});
} }
} }
rows.push_back({.type = TRIGGER}); rows.push_back({.type = TRIGGER});
for (auto& row : rows)
{
row.documentIndex = manager.selected;
row.animationIndex = reference.animationIndex;
}
return rows; return rows;
} }
std::vector<Reference> TimelineContext::timeline_item_references_get() bool TimelineContext::is_row_selected(const TimelineRow& row)
{ {
std::vector<Reference> itemReferences; if (row.isGroup) return is_row_reference_selected(row);
for (const auto& row : timeline_item_rows_get()) auto itemReference = item_reference_get(row.type, row.id, row.groupType, row.groupId);
{
if (row.isGroup) continue;
itemReferences.push_back({reference.animationIndex, row.type, row.id, -1, row.rootGroupType, row.rootGroupId});
}
return itemReferences;
}
Reference TimelineContext::group_reference_get(const TimelineItemRow& row)
{
return Reference{reference.animationIndex, row.type, row.id};
}
TimelineRowReference TimelineContext::row_reference_get(const TimelineItemRow& row)
{
return TimelineRowReference{manager.selected, reference.animationIndex, row.type, row.id,
row.index, row.rootGroupType, row.rootGroupId, row.isGroup};
}
Reference TimelineContext::row_item_reference_get(const TimelineRowReference& row)
{
return Reference{row.animationIndex, row.type, row.id, -1, row.groupType, row.groupId};
}
std::vector<TimelineRowReference> TimelineContext::timeline_row_references_get()
{
std::vector<TimelineRowReference> rowReferences;
for (const auto& row : timeline_item_rows_get())
{
if (row.type == NONE) continue;
rowReferences.push_back(row_reference_get(row));
}
return rowReferences;
}
bool TimelineContext::is_group_selected(const TimelineItemRow& row)
{
return document.selected_get(SelectionKind::GROUPS).contains(group_reference_get(row));
}
bool TimelineContext::is_row_selected(const TimelineItemRow& row)
{
if (row.isGroup) return is_group_selected(row);
auto itemReference = item_reference_get(row.type, row.id, row.rootGroupType, row.rootGroupId);
auto tracks = document.selected_get(SelectionKind::TRACKS); auto tracks = document.selected_get(SelectionKind::TRACKS);
return tracks.contains(itemReference) || return tracks.contains(itemReference) ||
(tracks.empty() && document.selection.uids[SelectionKind::GROUPS].empty() && (tracks.empty() && document.selection.uids[SelectionKind::GROUPS].empty() &&
is_same_item(reference, itemReference)); is_same_item(reference, itemReference));
} }
SelectionKind row_kind_get(const TimelineRowReference& row) Reference row_item_reference_get(const TimelineRow& row)
{ {
return row.isGroup ? SelectionKind::GROUPS : SelectionKind::TRACKS; return Reference{row.animationIndex, row.type, row.id, -1, row.groupType, row.groupId};
} }
Reference row_selection_reference_get(const TimelineRowReference& row) Reference row_selection_reference_get(const TimelineRow& row)
{ {
return row.isGroup ? Reference{row.animationIndex, row.type, row.id} return row.isGroup ? Reference{row.animationIndex, row.type, row.id} : row_item_reference_get(row);
: Reference{row.animationIndex, row.type, row.id, -1, row.groupType, row.groupId}; }
SelectionKind row_kind_get(const TimelineRow& row)
{
return row.isGroup ? SelectionKind::GROUPS : SelectionKind::TRACKS;
} }
void TimelineContext::row_selection_clear() void TimelineContext::row_selection_clear()
@@ -323,34 +192,21 @@ namespace anm2ed::imgui
document.selection.uids[SelectionKind::GROUPS].clear(); document.selection.uids[SelectionKind::GROUPS].clear();
} }
void TimelineContext::row_selection_insert(const TimelineRowReference& row) void TimelineContext::row_selection_insert(const TimelineRow& row)
{ {
auto references = document.selected_get(row_kind_get(row)); auto references = document.selected_get(row_kind_get(row));
references.insert(row_selection_reference_get(row)); references.insert(row_selection_reference_get(row));
document.selected_set(row_kind_get(row), references); document.selected_set(row_kind_get(row), references);
} }
void TimelineContext::row_selection_erase(const TimelineRowReference& row) bool TimelineContext::is_row_reference_selected(const TimelineRow& row)
{
auto references = document.selected_get(row_kind_get(row));
references.erase(row_selection_reference_get(row));
document.selected_set(row_kind_get(row), references);
}
bool TimelineContext::is_row_reference_selected(const TimelineRowReference& row)
{ {
return document.selected_get(row_kind_get(row)).contains(row_selection_reference_get(row)); return document.selected_get(row_kind_get(row)).contains(row_selection_reference_get(row));
} }
std::size_t TimelineContext::row_selection_count_get() void TimelineContext::row_selection_set(const TimelineRow& row)
{ {
return document.selection.uids[SelectionKind::TRACKS].size() + auto rowReference = row;
document.selection.uids[SelectionKind::GROUPS].size();
}
void TimelineContext::row_selection_set(const TimelineItemRow& row)
{
auto rowReference = row_reference_get(row);
auto isCtrlDown = ImGui::IsKeyDown(ImGuiMod_Ctrl); auto isCtrlDown = ImGui::IsKeyDown(ImGuiMod_Ctrl);
auto isShiftDown = ImGui::IsKeyDown(ImGuiMod_Shift); auto isShiftDown = ImGui::IsKeyDown(ImGuiMod_Shift);
@@ -367,8 +223,8 @@ namespace anm2ed::imgui
if (isShiftDown) if (isShiftDown)
{ {
auto rowSelection = timeline_row_references_get(); auto rowSelection = timeline_item_rows_get();
auto anchor = isRowSelectionAnchorSet ? rowSelectionAnchor : rowReference; auto anchor = rowSelectionAnchor.value_or(rowReference);
auto first = std::find(rowSelection.begin(), rowSelection.end(), anchor); auto first = std::find(rowSelection.begin(), rowSelection.end(), anchor);
auto last = std::find(rowSelection.begin(), rowSelection.end(), rowReference); auto last = std::find(rowSelection.begin(), rowSelection.end(), rowReference);
if (first == rowSelection.end() || last == rowSelection.end()) if (first == rowSelection.end() || last == rowSelection.end())
@@ -385,13 +241,19 @@ namespace anm2ed::imgui
if (!isCtrlDown) row_selection_clear(); if (!isCtrlDown) row_selection_clear();
for (int i = firstIndex; i <= lastIndex; ++i) for (int i = firstIndex; i <= lastIndex; ++i)
row_selection_insert(rowSelection[i]); row_selection_insert(rowSelection[i]);
if (!isRowSelectionAnchorSet) rowSelectionAnchor = rowReference; if (!rowSelectionAnchor) rowSelectionAnchor = rowReference;
} }
} }
else if (isCtrlDown) else if (isCtrlDown)
{ {
if (is_row_reference_selected(rowReference) && row_selection_count_get() > 1) if (is_row_reference_selected(rowReference) && document.selection.uids[SelectionKind::TRACKS].size() +
row_selection_erase(rowReference); document.selection.uids[SelectionKind::GROUPS].size() >
1)
{
auto references = document.selected_get(row_kind_get(rowReference));
references.erase(row_selection_reference_get(rowReference));
document.selected_set(row_kind_get(rowReference), references);
}
else else
row_selection_insert(rowReference); row_selection_insert(rowReference);
rowSelectionAnchor = rowReference; rowSelectionAnchor = rowReference;
@@ -402,13 +264,13 @@ namespace anm2ed::imgui
row_selection_insert(rowReference); row_selection_insert(rowReference);
rowSelectionAnchor = rowReference; rowSelectionAnchor = rowReference;
} }
isRowSelectionAnchorSet = true;
} }
void TimelineContext::reference_set_adjacent_item(int direction) void TimelineContext::reference_set_adjacent_item(int direction)
{ {
auto itemReferences = timeline_item_references_get(); std::vector<Reference> itemReferences{};
for (const auto& row : timeline_item_rows_get())
if (!row.isGroup) itemReferences.push_back(row_item_reference_get(row));
if (itemReferences.empty()) return; if (itemReferences.empty()) return;
auto it = std::find_if(itemReferences.begin(), itemReferences.end(), auto it = std::find_if(itemReferences.begin(), itemReferences.end(),
@@ -420,27 +282,27 @@ namespace anm2ed::imgui
auto& itemReference = itemReferences[index]; auto& itemReference = itemReferences[index];
group_selection_reset_for(document); group_selection_reset_for(document);
reference_set_timeline_item_reference_for(document, itemReference); document.track_select(itemReference);
} }
std::vector<TimelineRowReference> TimelineContext::selected_row_references_get() std::vector<TimelineRow> TimelineContext::selected_row_references_get()
{ {
std::vector<TimelineRowReference> result{}; std::vector<TimelineRow> result{};
for (const auto& row : timeline_item_rows_get()) for (const auto& row : timeline_item_rows_get())
if (is_row_selected(row)) result.push_back(row_reference_get(row)); if (is_row_selected(row)) result.push_back(row);
return result; return result;
} }
std::vector<TimelineRowReference> TimelineContext::row_drag_references_get(const TimelineItemRow& row) std::vector<TimelineRow> TimelineContext::row_drag_references_get(const TimelineRow& row)
{ {
auto clicked = row_reference_get(row); auto clicked = row;
if (clicked.type != LAYER && clicked.type != NULL_) return std::vector<TimelineRowReference>{clicked}; if (clicked.type != LAYER && clicked.type != NULL_) return std::vector<TimelineRow>{clicked};
auto rows = selected_row_references_get(); auto rows = selected_row_references_get();
if (!is_row_reference_selected(clicked)) rows = {clicked}; if (!is_row_reference_selected(clicked)) rows = {clicked};
if (rows.empty()) rows = {clicked}; if (rows.empty()) rows = {clicked};
std::erase_if(rows, [&](const TimelineRowReference& rowReference) { return rowReference.type != clicked.type; }); std::erase_if(rows, [&](const TimelineRow& rowReference) { return rowReference.type != clicked.type; });
if (rows.empty()) rows = {clicked}; if (rows.empty()) rows = {clicked};
return rows; return rows;
} }
+9 -14
View File
@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <memory> #include <memory>
#include <optional>
#include <set> #include <set>
#include <string> #include <string>
#include <vector> #include <vector>
@@ -17,7 +18,9 @@ namespace anm2ed::imgui
{ {
struct TimelineContext; struct TimelineContext;
struct TimelineRowReference // A timeline row: a track (in a group or not), a group, or a group's root. groupType/groupId name the group a
// track or group root belongs to.
struct TimelineRow
{ {
int documentIndex{-1}; int documentIndex{-1};
int animationIndex{-1}; int animationIndex{-1};
@@ -26,21 +29,16 @@ namespace anm2ed::imgui
int index{-1}; int index{-1};
int groupType{NONE}; int groupType{NONE};
int groupId{-1}; int groupId{-1};
int depth{};
bool isGroup{}; bool isGroup{};
auto operator<=>(const TimelineRowReference&) const = default; auto operator<=>(const TimelineRow&) const = default;
}; };
struct FrameMoveDrag struct FrameMoveDrag
{ {
int type{NONE};
int itemID{-1};
int animationIndex{-1}; int animationIndex{-1};
int groupType{NONE};
int groupId{-1};
int frameIndex{-1};
int duration{1}; int duration{1};
std::vector<int> indices{};
std::vector<Reference> references{}; std::vector<Reference> references{};
bool isActive{}; bool isActive{};
}; };
@@ -78,8 +76,7 @@ namespace anm2ed::imgui
ImVec2 frameBoxStart{}; ImVec2 frameBoxStart{};
ImVec2 frameBoxEnd{}; ImVec2 frameBoxEnd{};
std::set<Reference> frameBoxSelection{}; std::set<Reference> frameBoxSelection{};
TimelineRowReference rowSelectionAnchor{}; std::optional<TimelineRow> rowSelectionAnchor{};
bool isRowSelectionAnchorSet{};
PopupHelper groupPropertiesPopup{PopupHelper(LABEL_GROUP_PROPERTIES, POPUP_SMALL_NO_HEIGHT)}; PopupHelper groupPropertiesPopup{PopupHelper(LABEL_GROUP_PROPERTIES, POPUP_SMALL_NO_HEIGHT)};
std::string groupName{}; std::string groupName{};
int groupAnimationIndex{-1}; int groupAnimationIndex{-1};
@@ -88,7 +85,6 @@ namespace anm2ed::imgui
Reference draggedFrameReference{}; Reference draggedFrameReference{};
bool isDraggedFrameActive{}; bool isDraggedFrameActive{};
int draggedFrameType{}; int draggedFrameType{};
int draggedFrameIndex{-1};
int draggedFrameStart{-1}; int draggedFrameStart{-1};
int draggedFrameStartDuration{-1}; int draggedFrameStartDuration{-1};
std::vector<FrameDurationDrag> draggedFrameStartDurations{}; std::vector<FrameDurationDrag> draggedFrameStartDurations{};
@@ -96,10 +92,9 @@ namespace anm2ed::imgui
float draggedFrameWidth{}; float draggedFrameWidth{};
bool isDraggedFrameSnapshot{}; bool isDraggedFrameSnapshot{};
FrameMoveDrag frameMoveDrag{}; FrameMoveDrag frameMoveDrag{};
Reference frameSelectionAnchor{}; std::optional<Reference> frameSelectionAnchor{};
bool isFrameSelectionAnchorSet{};
int animationLengthEditIndex{-1}; int animationLengthEditIndex{-1};
std::vector<TimelineRowReference> rowDragReferences{}; std::vector<TimelineRow> rowDragReferences{};
glm::vec2 scroll{}; glm::vec2 scroll{};
ImGuiStyle style{}; ImGuiStyle style{};
}; };
+19 -20
View File
@@ -2,14 +2,14 @@
namespace anm2ed::imgui namespace anm2ed::imgui
{ {
void TimelineContext::item_child(const TimelineItemRow& row, int index) void TimelineContext::item_child(const TimelineRow& row, int index)
{ {
ImGui::PushID(index); ImGui::PushID(index);
auto type = row.type; auto type = row.type;
auto id = row.id; auto id = row.id;
auto row_reference_make = [&]() auto row_reference_make = [&]()
{ return Reference{reference.animationIndex, type, id, -1, row.rootGroupType, row.rootGroupId}; }; { return Reference{reference.animationIndex, type, id, -1, row.groupType, row.groupId}; };
if (row.isGroup) if (row.isGroup)
{ {
auto group = row_group_get(row); auto group = row_group_get(row);
@@ -23,7 +23,7 @@ namespace anm2ed::imgui
auto itemSize = ImVec2(ImGui::GetContentRegionAvail().x, rowFrameChildHeight); auto itemSize = ImVec2(ImGui::GetContentRegionAvail().x, rowFrameChildHeight);
auto isGroupVisible = group->isVisible; auto isGroupVisible = group->isVisible;
auto colorVec = color_get(COLOR_ITEM_BASE, type); auto colorVec = color_get(COLOR_ITEM_BASE, type);
if (is_group_selected(row)) colorVec = color_get(COLOR_ITEM_SELECTED, type); if (is_row_reference_selected(row)) colorVec = color_get(COLOR_ITEM_SELECTED, type);
auto color = to_imvec4(isGroupVisible ? colorVec : colorVec * COLOR_HIDDEN_MULTIPLIER); auto color = to_imvec4(isGroupVisible ? colorVec : colorVec * COLOR_HIDDEN_MULTIPLIER);
ImGui::PushStyleColor(ImGuiCol_ChildBg, color); ImGui::PushStyleColor(ImGuiCol_ChildBg, color);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, style.ItemSpacing); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, style.ItemSpacing);
@@ -74,7 +74,7 @@ namespace anm2ed::imgui
{ {
rowDragReferences = row_drag_references_get(row); rowDragReferences = row_drag_references_get(row);
ImGui::SetDragDropPayload("Timeline Row Drag Drop", rowDragReferences.data(), ImGui::SetDragDropPayload("Timeline Row Drag Drop", rowDragReferences.data(),
(int)rowDragReferences.size() * (int)sizeof(TimelineRowReference)); (int)rowDragReferences.size() * (int)sizeof(TimelineRow));
ImGui::EndDragDropSource(); ImGui::EndDragDropSource();
} }
@@ -91,9 +91,9 @@ namespace anm2ed::imgui
else if (mousePos.y >= groupButtonMin.y + groupDropThird) else if (mousePos.y >= groupButtonMin.y + groupDropThird)
dropZone = DropZone::INSIDE; dropZone = DropZone::INSIDE;
auto isDropAfter = dropZone != DropZone::BEFORE; auto isDropAfter = dropZone != DropZone::BEFORE;
auto payloadRows = (TimelineRowReference*)payload->Data; auto payloadRows = (TimelineRow*)payload->Data;
auto payloadCount = payload->DataSize / sizeof(TimelineRowReference); auto payloadCount = payload->DataSize / sizeof(TimelineRow);
std::vector<TimelineRowReference> draggedRows(payloadRows, payloadRows + payloadCount); std::vector<TimelineRow> draggedRows(payloadRows, payloadRows + payloadCount);
auto isDropIntoGroup = dropZone == DropZone::INSIDE && (row.type == LAYER || row.type == NULL_); auto isDropIntoGroup = dropZone == DropZone::INSIDE && (row.type == LAYER || row.type == NULL_);
for (auto draggedRow : draggedRows) for (auto draggedRow : draggedRows)
if (draggedRow.isGroup || draggedRow.type != row.type) isDropIntoGroup = false; if (draggedRow.isGroup || draggedRow.type != row.type) isDropIntoGroup = false;
@@ -182,7 +182,7 @@ namespace anm2ed::imgui
return; return;
} }
auto item = item_get(type, id, row.rootGroupType, row.rootGroupId); auto item = item_get(type, id, row.groupType, row.groupId);
if (type != NONE && !item) if (type != NONE && !item)
{ {
ImGui::PopID(); ImGui::PopID();
@@ -190,8 +190,8 @@ namespace anm2ed::imgui
} }
auto isItemVisible = item ? item->isVisible : false; auto isItemVisible = item ? item->isVisible : false;
auto isVisible = item ? item->isVisible && is_track_group_visible(type, row.groupId) : false; auto isVisible = item ? item->isVisible && is_track_group_visible(type, row.groupId) : false;
if (item && type == ROOT && row.rootGroupId != -1) if (item && type == ROOT && row.groupId != -1)
isVisible = item->isVisible && is_track_group_visible(row.rootGroupType, row.rootGroupId); isVisible = item->isVisible && is_track_group_visible(row.groupType, row.groupId);
auto& isOnlyShowLayers = settings.timelineIsOnlyShowLayers; auto& isOnlyShowLayers = settings.timelineIsOnlyShowLayers;
if (isOnlyShowLayers && type != LAYER) isVisible = false; if (isOnlyShowLayers && type != LAYER) isVisible = false;
auto isReferenced = is_same_item(reference, row_reference_make()); auto isReferenced = is_same_item(reference, row_reference_make());
@@ -247,7 +247,7 @@ namespace anm2ed::imgui
{ {
rowDragReferences = row_drag_references_get(row); rowDragReferences = row_drag_references_get(row);
ImGui::SetDragDropPayload("Timeline Row Drag Drop", rowDragReferences.data(), ImGui::SetDragDropPayload("Timeline Row Drag Drop", rowDragReferences.data(),
(int)rowDragReferences.size() * (int)sizeof(TimelineRowReference)); (int)rowDragReferences.size() * (int)sizeof(TimelineRow));
ImGui::EndDragDropSource(); ImGui::EndDragDropSource();
} }
@@ -260,9 +260,9 @@ namespace anm2ed::imgui
auto isDropAfter = is_drop_after(itemButtonMin, itemButtonMax); auto isDropAfter = is_drop_after(itemButtonMin, itemButtonMax);
drop_line_draw(ImGui::GetWindowDrawList(), itemChildMin, itemChildMax, isDropAfter); drop_line_draw(ImGui::GetWindowDrawList(), itemChildMin, itemChildMax, isDropAfter);
auto payloadRows = (TimelineRowReference*)payload->Data; auto payloadRows = (TimelineRow*)payload->Data;
auto payloadCount = payload->DataSize / sizeof(TimelineRowReference); auto payloadCount = payload->DataSize / sizeof(TimelineRow);
std::vector<TimelineRowReference> draggedRows(payloadRows, payloadRows + payloadCount); std::vector<TimelineRow> draggedRows(payloadRows, payloadRows + payloadCount);
if (payload->IsDelivery()) rows_move_to_row(draggedRows, row, isDropAfter, false); if (payload->IsDelivery()) rows_move_to_row(draggedRows, row, isDropAfter, false);
} }
ImGui::EndDragDropTarget(); ImGui::EndDragDropTarget();
@@ -393,8 +393,8 @@ namespace anm2ed::imgui
auto animationIndex = reference.animationIndex; auto animationIndex = reference.animationIndex;
auto targetType = type; auto targetType = type;
auto targetID = id; auto targetID = id;
auto targetGroupType = row.rootGroupType; auto targetGroupType = row.groupType;
auto targetGroupId = row.rootGroupId; auto targetGroupId = row.groupId;
edit_push(EDIT_TOGGLE_ITEM_VISIBILITY, edit_push(EDIT_TOGGLE_ITEM_VISIBILITY,
[=](model::Model& model) [=](model::Model& model)
{ {
@@ -510,14 +510,13 @@ namespace anm2ed::imgui
{ {
if (animation && ImGui::Shortcut(ImGuiMod_Ctrl | ImGuiKey_A, ImGuiInputFlags_RouteFocused)) if (animation && ImGui::Shortcut(ImGuiMod_Ctrl | ImGuiKey_A, ImGuiInputFlags_RouteFocused))
{ {
auto rowReferences = timeline_row_references_get(); auto rowReferences = timeline_item_rows_get();
row_selection_clear(); row_selection_clear();
for (auto rowReference : rowReferences) for (auto rowReference : rowReferences)
row_selection_insert(rowReference); row_selection_insert(rowReference);
if (!rowReferences.empty()) if (!rowReferences.empty())
{ {
rowSelectionAnchor = rowReferences.front(); rowSelectionAnchor = rowReferences.front();
isRowSelectionAnchorSet = true;
} }
document.frame_references_clear(); document.frame_references_clear();
} }
@@ -536,7 +535,7 @@ namespace anm2ed::imgui
ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableSetupColumn("##Items"); ImGui::TableSetupColumn("##Items");
auto item_child_row = [&](const TimelineItemRow& row, int index) auto item_child_row = [&](const TimelineRow& row, int index)
{ {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0); ImGui::TableSetColumnIndex(0);
@@ -578,7 +577,7 @@ namespace anm2ed::imgui
ImGui::SameLine(); ImGui::SameLine();
auto selectedRows = selected_row_references_get(); auto selectedRows = selected_row_references_get();
auto isRemoveAvailable = std::ranges::any_of(selectedRows, [](const TimelineRowReference& row) auto isRemoveAvailable = std::ranges::any_of(selectedRows, [](const TimelineRow& row)
{ return row.type == LAYER || row.type == NULL_; }); { return row.type == LAYER || row.type == NULL_; });
ImGui::BeginDisabled(!isRemoveAvailable); ImGui::BeginDisabled(!isRemoveAvailable);
shortcut(manager.chords[SHORTCUT_REMOVE]); shortcut(manager.chords[SHORTCUT_REMOVE]);