Split anm2 and timeline into modules; merge groups by name

Baseline before de-bloat refactor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-03 12:41:23 -04:00
1 parent 9e9dd8bd8a
commit 41ed347925
20 files changed
+7849 -7415

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@
#include "window/onionskin.hpp"
#include "window/shaders.hpp"
#include "window/spritesheet_editor.hpp"
#include "window/timeline.hpp"
#include "window/timeline/timeline.hpp"
#include "window/tools.hpp"
#include "window/welcome.hpp"
#include "window/window.hpp"
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+355
View File
@@ -0,0 +1,355 @@
#pragma once
#include "timeline.hpp"
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <format>
#include <functional>
#include <map>
#include <optional>
#include <set>
#include <imgui_internal.h>
#include "actions.hpp"
#include "log.hpp"
#include "math.hpp"
#include "toast.hpp"
#include "util/imgui/draw.hpp"
#include "util/imgui/input.hpp"
#include "util/imgui/layout.hpp"
#include "util/imgui/shortcut.hpp"
#include "util/imgui/tooltip.hpp"
#include "vector.hpp"
using namespace anm2ed::resource;
using namespace anm2ed::types;
using namespace anm2ed::util;
using namespace glm;
namespace anm2ed::imgui
{
constexpr auto WIDTH_MULTIPLIER = 1.25f;
constexpr auto COLOR_HIDDEN_MULTIPLIER = vec4(0.5f, 0.5f, 0.5f, 1.000f);
constexpr auto FRAME_BORDER_COLOR_DARK = ImVec4(1.0f, 1.0f, 1.0f, 0.15f);
constexpr auto FRAME_BORDER_COLOR_LIGHT = ImVec4(0.0f, 0.0f, 0.0f, 0.25f);
constexpr auto FRAME_BORDER_COLOR_REFERENCED_DARK = ImVec4(1.0f, 1.0f, 1.0f, 0.50f);
constexpr auto FRAME_BORDER_COLOR_REFERENCED_LIGHT = ImVec4(0.0f, 0.0f, 0.0f, 0.60f);
constexpr auto FRAME_BORDER_THICKNESS = 1.0f;
constexpr auto FRAME_BORDER_THICKNESS_REFERENCED = 2.0f;
constexpr auto FRAME_MULTIPLE_OVERLAY_COLOR_DARK = ImVec4(1.0f, 1.0f, 1.0f, 0.05f);
constexpr auto FRAME_MULTIPLE_OVERLAY_COLOR_LIGHT = ImVec4(0.0f, 0.0f, 0.0f, 0.1f);
constexpr auto FRAME_ROUNDING = 3.0f;
constexpr auto ICON_TINT_DEFAULT_DARK = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
constexpr auto ICON_TINT_DEFAULT_LIGHT = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
constexpr auto ITEM_TEXT_COLOR_DARK = to_imvec4(color::WHITE);
constexpr auto ITEM_TEXT_COLOR_LIGHT = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
constexpr auto PLAYHEAD_ICON_TINT_LIGHT = ImVec4(0.3922f, 0.7843f, 0.5882f, 1.0f);
constexpr auto PLAYHEAD_LINE_COLOR_DARK = to_imvec4(color::WHITE);
constexpr auto PLAYHEAD_LINE_COLOR_LIGHT = ImVec4(0.1961f, 0.5882f, 0.3922f, 1.0f);
constexpr auto PLAYHEAD_LINE_THICKNESS = 4.0f;
constexpr auto TEXT_MULTIPLE_COLOR_DARK = to_imvec4(color::WHITE);
constexpr auto TEXT_MULTIPLE_COLOR_LIGHT = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
constexpr auto TIMELINE_BACKGROUND_COLOR_LIGHT = ImVec4(0.5490f, 0.5490f, 0.5882f, 1.0f);
constexpr auto TIMELINE_PLAYHEAD_RECT_COLOR_DARK = ImVec4(0.60f, 0.45f, 0.30f, 1.0f);
constexpr auto TIMELINE_PLAYHEAD_RECT_COLOR_LIGHT = ImVec4(0.8353f, 0.8353f, 0.7294f, 1.0f);
constexpr auto TIMELINE_TICK_COLOR_LIGHT = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
constexpr auto TIMELINE_CHILD_BG_COLOR_LIGHT = ImVec4(0.5490f, 0.5490f, 0.5882f, 1.0f);
constexpr auto TIMELINE_TEXT_COLOR_LIGHT = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
enum class DropZone
{
BEFORE,
INSIDE,
AFTER
};
constexpr glm::vec4 FRAME_COLOR_LIGHT_BASE[] = {{0.80f, 0.80f, 0.80f, 1.0f},
{0.5216f, 0.7333f, 1.0f, 1.0f},
{1.0f, 0.9961f, 0.5882f, 1.0f},
{0.6157f, 1.0f, 0.5882f, 1.0f},
{1.0f, 0.5882f, 0.8314f, 1.0f}};
constexpr glm::vec4 FRAME_COLOR_LIGHT_ACTIVE[] = {{0.74f, 0.74f, 0.74f, 1.0f},
{0.0980f, 0.3765f, 0.6431f, 1.0f},
{1.0f, 0.5255f, 0.3333f, 1.0f},
{0.3686f, 0.5765f, 0.2353f, 1.0f},
{0.6118f, 0.2039f, 0.2745f, 1.0f}};
constexpr glm::vec4 FRAME_COLOR_LIGHT_HOVERED[] = {{0.84f, 0.84f, 0.84f, 1.0f},
{0.0752f, 0.2887f, 0.4931f, 1.0f},
{0.85f, 0.4467f, 0.2833f, 1.0f},
{0.2727f, 0.4265f, 0.1741f, 1.0f},
{0.4618f, 0.1539f, 0.2072f, 1.0f}};
constexpr glm::vec4 ITEM_COLOR_LIGHT_BASE[] = {{0.3059f, 0.3255f, 0.5412f, 1.0f},
{0.3333f, 0.5725f, 0.8392f, 1.0f},
{1.0f, 0.5412f, 0.3412f, 1.0f},
{0.5255f, 0.8471f, 0.4588f, 1.0f},
{0.7961f, 0.3882f, 0.5412f, 1.0f}};
constexpr glm::vec4 ITEM_COLOR_LIGHT_ACTIVE[] = {{0.3459f, 0.3655f, 0.5812f, 1.0f},
{0.3733f, 0.6125f, 0.8792f, 1.0f},
{0.9106f, 0.4949f, 0.2753f, 1.0f},
{0.5655f, 0.8871f, 0.4988f, 1.0f},
{0.8361f, 0.4282f, 0.5812f, 1.0f}};
constexpr glm::vec4 ITEM_COLOR_LIGHT_SELECTED[] = {{0.74f, 0.74f, 0.74f, 1.0f},
{0.2039f, 0.4549f, 0.7176f, 1.0f},
{0.8745f, 0.4392f, 0.2275f, 1.0f},
{0.3765f, 0.6784f, 0.2980f, 1.0f},
{0.6353f, 0.2235f, 0.3647f, 1.0f}};
constexpr auto FRAME_MULTIPLE = 5;
constexpr auto FRAME_TOOLTIP_HOVER_DELAY = 0.75f;
constexpr auto DRAG_DROP_SOURCE_FLAGS =
ImGuiDragDropFlags_SourceNoPreviewTooltip | ImGuiDragDropFlags_SourceNoHoldToOpenOthers;
#define ITEM_CHILD_WIDTH ImGui::GetTextLineHeightWithSpacing() * 12.5
struct TimelineItemRow
{
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
{
Timeline& timeline;
bool& isDragging;
bool& isWindowHovered;
bool& isHorizontalScroll;
popup::ItemProperties& itemProperties;
PopupHelper& bakePopup;
PopupHelper& bakeIntoOtherFramesPopup;
PopupHelper& makeManyRegionsPopup;
BakeIntoOtherFramesTarget& bakeIntoOtherFramesTarget;
bool& isBakeIntoOtherFramesLayers;
bool& isBakeIntoOtherFramesNulls;
bool& isMakeManyRegionsMapFrames;
std::set<Reference>& makeManyRegionReferences;
int& hoveredTime;
bool& isFrameBoxPending;
bool& isFrameBoxSelecting;
bool& isFrameBoxAdditive;
ImVec2& frameBoxStart;
ImVec2& frameBoxEnd;
std::set<Reference>& frameBoxSelection;
TimelineRowReference& rowSelectionAnchor;
bool& isRowSelectionAnchorSet;
PopupHelper& groupPropertiesPopup;
std::string& groupName;
int& groupAnimationIndex;
int& groupType;
int& groupId;
Reference& draggedFrameReference;
bool& isDraggedFrameActive;
int& draggedFrameType;
int& draggedFrameIndex;
int& draggedFrameStart;
int& draggedFrameStartDuration;
std::vector<FrameDurationDrag>& draggedFrameStartDurations;
float& draggedFrameStartMouseX;
float& draggedFrameWidth;
bool& isDraggedFrameSnapshot;
bool& frameFocusRequested;
int& frameFocusIndex;
FrameMoveDrag& frameMoveDrag;
std::vector<int>& frameSelectionSnapshot;
std::vector<int>& frameSelectionLocked;
bool& isFrameSelectionLocked;
Reference& frameSelectionSnapshotReference;
Reference& frameSelectionAnchor;
bool& isFrameSelectionAnchorSet;
int& animationLengthEditIndex;
std::vector<TimelineRowReference>& rowDragReferences;
glm::vec2& scroll;
ImGuiStyle& style;
Manager& manager;
Settings& settings;
Resources& resources;
Clipboard& clipboard;
Document& document;
Anm2& anm2;
Playback& playback;
Reference& reference;
Storage& frames;
Storage& region;
Element* animation{};
float rowFrameChildHeight{};
bool isLightTheme{};
bool isTextPushed{};
ImVec4 iconTintDefault{};
ImVec4 itemIconTint{};
ImVec4 frameBorderColor{};
ImVec4 frameBorderColorReferenced{};
ImVec4 frameMultipleOverlayColor{};
ImVec4 textMultipleColor{};
ImVec4 playheadLineColor{};
ImVec4 playheadIconTint{};
ImVec4 timelineBackgroundColor{};
ImVec4 timelinePlayheadRectColor{};
ImVec4 timelineTickColor{};
ImVec4 itemTextColor{};
std::optional<int> frameSplitTimeAtCursor{};
int frameMoveDropType{NONE};
int frameMoveDropItemID{-1};
int frameMoveDropGroupType{NONE};
int frameMoveDropGroupId{-1};
int frameMoveDropIndex{-1};
bool isFrameMoveDropTarget{};
float playheadLineCenterX{};
float playheadLineTopY{};
bool isPlayheadLineSet{};
ImVec2 frameBoxClipMin{};
ImVec2 frameBoxClipMax{};
bool isFrameBoxClipSet{};
std::function<int(int)> type_index{};
std::function<ItemType(int)> item_type_get{};
std::function<Element*(int, int, int, int)> item_get{};
std::function<Element*()> frame_get{};
std::function<Element*()> selected_item_get{};
std::function<ElementType(const Element&)> item_frame_type_get{};
std::function<int(const Element*)> item_frames_count{};
std::function<int(const Element&, int)> item_frame_child_index_get{};
std::function<int(const Element&, int)> item_frame_insert_index_get{};
std::function<Element*(int)> layer_get{};
std::function<Element*(int)> null_get{};
std::function<Element*(int)> spritesheet_get{};
std::function<Element*()> info_get{};
std::function<ElementType(int)> container_type_get{};
std::function<ElementType(int)> track_type_get{};
std::function<int(const Element&, int)> track_id_get{};
std::function<Element*(int)> track_container_get{};
std::function<Element*(int, int)> track_group_get{};
std::function<bool(int, int)> is_track_group_visible{};
std::function<Element*(const TimelineItemRow&)> row_group_get{};
std::function<int(int, int)> group_items_count_get{};
std::function<Element*(Document&, int)> command_animation_get{};
std::function<Element*(Document&, int, int, int, int, int)> command_item_get{};
std::function<Element*(Document&, Reference)> command_item_reference_get{};
std::function<Element*(Document&, const Reference&)> command_frame_get{};
std::function<Element*(Document&, int)> command_layer_get{};
std::function<Element*(Document&, int)> command_spritesheet_get{};
std::function<Element*(Document&)> command_info_get{};
std::function<Reference(int, int, int, int)> item_reference_get{};
std::function<Reference(Reference)> item_reference_from_frame_get{};
std::function<bool(const Reference&, const Reference&)> is_same_item{};
std::function<bool(Document&, const Reference&)> is_frame_reference_valid_for{};
std::function<void(Document&)> group_selection_reset_for{};
std::function<std::set<Reference>()> frame_references_for_current_get{};
std::function<std::set<Reference>()> item_references_for_current_get{};
std::function<void(Document&)> frames_selection_sync_for{};
std::function<void(Document&, Reference)> item_selection_set_for{};
std::function<void(Document&, Reference)> frame_selection_set_for{};
std::function<void(Document&, Reference)> frame_selection_toggle_for{};
std::function<bool(Document&, Reference, Reference, bool)> frame_selection_range_set_for{};
std::function<std::set<Reference>()> all_frame_references_for_items_get{};
std::function<bool(const Reference&)> is_frame_copy_item{};
std::function<std::set<Reference>()> copy_frame_references_get{};
std::function<void(Document&)> frames_selection_reset_for{};
std::function<void(Document&)> frames_selection_set_reference_for{};
std::function<void(Document&)> frames_reference_normalize_for{};
std::function<void(Document&)> reference_clear_for{};
std::function<void(Document&, Reference)> reference_set_item_reference_for{};
std::function<void(Document&, Reference)> reference_set_timeline_item_reference_for{};
std::function<void(std::function<void(Manager&, Document&)>)> command_push{};
std::function<std::set<Reference>(std::set<Reference>)> track_references_from_frame_references_get{};
std::function<void(StringType, const std::set<Reference>&)> tracks_snapshot_command_push{};
std::function<void(StringType, const std::set<Reference>&)> frames_snapshot_command_push{};
std::function<void(StringType, Document::ChangeType, const std::set<Reference>&,
std::function<void(Manager&, Document&)>)>
frames_edit_command_push{};
std::function<void(StringType, Document::ChangeType, const std::set<Reference>&,
std::function<void(Manager&, Document&)>)>
tracks_edit_command_push{};
std::function<void(StringType, Document::ChangeType, std::function<void(Manager&, Document&)>)> edit_command_push{};
std::function<glm::vec4(int)> type_color_base_vec{};
std::function<glm::vec4(int)> type_color_active_vec{};
std::function<glm::vec4(int)> type_color_hovered_vec{};
std::function<glm::vec4(int)> item_color_vec{};
std::function<glm::vec4(int)> item_color_active_vec{};
std::function<void(GLuint, ImVec4, bool)> overlay_icon{};
std::function<void()> frames_selection_set_reference{};
std::function<void()> playback_stop{};
std::function<void()> frame_insert{};
std::function<void(Document&, std::set<Reference>)> frames_delete_for{};
std::function<void()> frames_delete_action{};
std::function<void()> frames_duplicate{};
std::function<bool(std::set<Reference>)> is_frames_reverse_available{};
std::function<void()> frames_reverse{};
std::function<void()> frames_bake{};
std::function<std::set<Reference>()> selected_root_frame_references_get{};
std::function<std::set<Reference>(const Document&, const Element&, BakeIntoOtherFramesTarget, bool, bool)>
item_references_for_bake_into_other_frames_get{};
std::function<bool()> is_bake_into_other_frames_ready{};
std::function<void(Element&, const Element&, bool, bool, bool)> frame_root_transform_apply{};
std::function<void()> bake_into_other_frames{};
std::function<void()> frame_split{};
std::function<void()> reference_clear{};
std::function<void(Reference)> reference_set_timeline_item_reference{};
std::function<std::vector<TimelineItemRow>()> timeline_item_rows_get{};
std::function<std::vector<Reference>()> timeline_item_references_get{};
std::function<Reference(const TimelineItemRow&)> group_reference_get{};
std::function<TimelineRowReference(const TimelineItemRow&)> row_reference_get{};
std::function<Reference(const TimelineRowReference&)> row_item_reference_get{};
std::function<std::vector<TimelineRowReference>()> timeline_row_references_get{};
std::function<bool(const TimelineItemRow&)> is_group_selected{};
std::function<bool(const TimelineItemRow&)> is_row_selected{};
std::function<void()> row_selection_clear{};
std::function<void(const TimelineRowReference&)> row_selection_insert{};
std::function<void(const TimelineRowReference&)> row_selection_erase{};
std::function<bool(const TimelineRowReference&)> is_row_reference_selected{};
std::function<std::size_t()> row_selection_count_get{};
std::function<void(const TimelineItemRow&)> row_selection_set{};
std::function<void(int)> reference_set_adjacent_item{};
std::function<std::vector<TimelineRowReference>()> selected_row_references_get{};
std::function<std::vector<TimelineRowReference>(const TimelineItemRow&)> row_drag_references_get{};
std::function<void()> item_remove{};
std::function<std::vector<Reference>()> item_references_groupable_get{};
std::function<void()> item_group{};
std::function<void(std::vector<TimelineRowReference>, TimelineItemRow, bool, bool)> rows_move_to_row{};
std::function<void()> fit_animation_length{};
std::function<void(const std::set<Reference>&)> frame_references_copy{};
std::function<void()> copy{};
std::function<void()> cut{};
std::function<void()> paste{};
std::function<void()> context_menu{};
std::function<void(int, int)> item_base_properties_open{};
std::function<void()> group_properties_close{};
std::function<void(const TimelineItemRow&, const Element&)> group_properties_open{};
std::function<void()> group_properties_update{};
std::function<void()> item_context_menu{};
TimelineContext(Timeline&, Manager&, Settings&, Resources&, Clipboard&);
void update();
void commands_bind();
void item_child(const TimelineItemRow&, int);
void items_child();
void frame_move_drag_clear();
void frames_move_to(int, int, int, int, int);
ImVec2 frame_box_content_point_get();
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_child(const TimelineItemRow&, int&, float);
void frames_child();
void draw();
};
}
File diff suppressed because it is too large. Load diff
+248
View File
@@ -0,0 +1,248 @@
#include "context.hpp"
namespace anm2ed::imgui
{
void TimelineContext::draw()
{
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2());
if (ImGui::Begin(localize.get(LABEL_TIMELINE_WINDOW), &settings.windowIsTimeline))
{
isWindowHovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows |
ImGuiHoveredFlags_AllowWhenBlockedByActiveItem);
frames_child();
if (frameMoveDrag.isActive && ImGui::IsMouseReleased(ImGuiMouseButton_Left))
{
if (isFrameMoveDropTarget)
frames_move_to(frameMoveDropType, frameMoveDropItemID, frameMoveDropGroupType, frameMoveDropGroupId,
frameMoveDropIndex);
frame_move_drag_clear();
}
items_child();
}
ImGui::PopStyleVar();
ImGui::End();
if (itemProperties.update(manager, settings, document, reference)) group_selection_reset_for(document);
group_properties_update();
makeManyRegionsPopup.trigger();
if (ImGui::BeginPopupModal(makeManyRegionsPopup.label(), &makeManyRegionsPopup.isOpen, ImGuiWindowFlags_NoResize))
{
input_text_string(localize.get(LABEL_FORMAT), &settings.generateRegionNameFormat);
ImGui::Checkbox(localize.get(LABEL_MAP_FRAMES_TO_REGIONS), &isMakeManyRegionsMapFrames);
auto widgetSize = widget_size_with_row_get(2);
if (ImGui::Button(localize.get(LABEL_MAKE_MANY_REGIONS), widgetSize))
{
auto targetFrames = makeManyRegionReferences;
auto format = settings.generateRegionNameFormat;
auto mapping = isMakeManyRegionsMapFrames ? Document::RegionFrameMapping::SET
: Document::RegionFrameMapping::PRESERVE;
edit_command_push(EDIT_GENERATE_REGIONS_FROM_ANIMATIONS, Document::ALL,
[=, this](Manager&, Document& document) mutable
{ document.regions_generate_from_frames(targetFrames, format, mapping); });
makeManyRegionsPopup.close();
}
ImGui::SameLine();
if (ImGui::Button(localize.get(BASIC_CANCEL), widgetSize)) makeManyRegionsPopup.close();
ImGui::EndPopup();
}
makeManyRegionsPopup.end();
bakePopup.trigger();
if (ImGui::BeginPopupModal(bakePopup.label(), &bakePopup.isOpen, ImGuiWindowFlags_NoResize))
{
auto& interval = settings.bakeInterval;
auto& isRoundRotation = settings.bakeIsRoundRotation;
auto& isRoundScale = settings.bakeIsRoundScale;
auto frame = frame_get();
input_int_range(localize.get(LABEL_INTERVAL), interval, FRAME_DURATION_MIN,
frame ? frame->duration : FRAME_DURATION_MIN);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_INTERVAL));
ImGui::Checkbox(localize.get(LABEL_ROUND_ROTATION), &isRoundRotation);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ROUND_ROTATION));
ImGui::Checkbox(localize.get(LABEL_ROUND_SCALE), &isRoundScale);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ROUND_SCALE));
auto widgetSize = widget_size_with_row_get(2);
shortcut(manager.chords[SHORTCUT_CONFIRM]);
if (ImGui::Button(localize.get(LABEL_BAKE), widgetSize))
{
frames_bake();
bakePopup.close();
}
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_BAKE_FRAMES_OPTIONS));
ImGui::SameLine();
shortcut(manager.chords[SHORTCUT_CANCEL]);
if (ImGui::Button(localize.get(BASIC_CANCEL), widgetSize)) bakePopup.close();
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_CANCEL_BAKE_FRAMES));
ImGui::EndPopup();
}
bakeIntoOtherFramesPopup.trigger();
if (ImGui::BeginPopupModal(bakeIntoOtherFramesPopup.label(), &bakeIntoOtherFramesPopup.isOpen,
ImGuiWindowFlags_NoResize))
{
auto& isRoundRotation = settings.bakeIsRoundRotation;
auto& isRoundScale = settings.bakeIsRoundScale;
auto& isMatchRootInterpolation = settings.bakeIsMatchRootInterpolation;
auto& isUseRootPivot = settings.bakeIsUseRootPivot;
int target = (int)bakeIntoOtherFramesTarget;
ImGui::RadioButton(localize.get(LABEL_CURRENT_SELECTION), &target,
(int)BakeIntoOtherFramesTarget::CURRENT_SELECTION);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_BAKE_INTO_OTHER_FRAMES_CURRENT_SELECTION));
ImGui::SameLine();
ImGui::RadioButton(localize.get(LABEL_ALL), &target, (int)BakeIntoOtherFramesTarget::ALL);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_BAKE_INTO_OTHER_FRAMES_ALL));
bakeIntoOtherFramesTarget = (BakeIntoOtherFramesTarget)target;
auto isCurrentSelection = bakeIntoOtherFramesTarget == BakeIntoOtherFramesTarget::CURRENT_SELECTION;
ImGui::BeginDisabled(isCurrentSelection);
ImGui::Checkbox(localize.get(LABEL_LAYERS), &isBakeIntoOtherFramesLayers);
ImGui::SameLine();
ImGui::Checkbox(localize.get(LABEL_NULLS), &isBakeIntoOtherFramesNulls);
ImGui::EndDisabled();
ImGui::Checkbox(localize.get(LABEL_ROUND_ROTATION), &isRoundRotation);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ROUND_ROTATION));
ImGui::Checkbox(localize.get(LABEL_ROUND_SCALE), &isRoundScale);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ROUND_SCALE));
ImGui::Checkbox(localize.get(LABEL_BAKE_MATCH_ROOT_INTERPOLATION), &isMatchRootInterpolation);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_BAKE_MATCH_ROOT_INTERPOLATION));
ImGui::Checkbox(localize.get(LABEL_BAKE_USE_ROOT_PIVOT), &isUseRootPivot);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_BAKE_USE_ROOT_PIVOT));
auto widgetSize = widget_size_with_row_get(2);
shortcut(manager.chords[SHORTCUT_CONFIRM]);
ImGui::BeginDisabled(!is_bake_into_other_frames_ready());
if (ImGui::Button(localize.get(LABEL_BAKE), widgetSize))
{
bake_into_other_frames();
bakeIntoOtherFramesPopup.close();
}
ImGui::EndDisabled();
ImGui::SameLine();
shortcut(manager.chords[SHORTCUT_CANCEL]);
if (ImGui::Button(localize.get(BASIC_CANCEL), widgetSize)) bakeIntoOtherFramesPopup.close();
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_CANCEL_BAKE_FRAMES));
ImGui::EndPopup();
}
if (animation)
{
if (shortcut(manager.chords[SHORTCUT_PLAY_PAUSE], shortcut::GLOBAL)) playback.toggle();
if (shortcut(manager.chords[SHORTCUT_MOVE_PLAYHEAD_BACK], shortcut::GLOBAL))
{
playback_stop();
playback.decrement(settings.playbackIsClamp ? animation->frameNum : FRAME_NUM_MAX);
document.frameTime = playback.time;
}
if (shortcut(manager.chords[SHORTCUT_MOVE_PLAYHEAD_FORWARD], shortcut::GLOBAL))
{
playback_stop();
playback.increment(settings.playbackIsClamp ? animation->frameNum : FRAME_NUM_MAX);
document.frameTime = playback.time;
}
static bool isShortenChordHeld = false;
auto isShortenFrame = shortcut(manager.chords[SHORTCUT_SHORTEN_FRAME], shortcut::GLOBAL);
if (isShortenFrame)
{
auto selectedFrames = frame_references_for_current_get();
std::erase_if(selectedFrames,
[](const Reference& frameReference) { return frameReference.itemType == TRIGGER; });
if (!selectedFrames.empty())
{
if (!isShortenChordHeld) frames_snapshot_command_push(EDIT_SHORTEN_FRAME, selectedFrames);
command_push([=, this](Manager&, Document& document)
{
for (auto frameReference : selectedFrames)
{
auto frame = command_frame_get(document, frameReference);
if (!frame) continue;
frame->duration = std::max(FRAME_DURATION_MIN, frame->duration - 1);
}
document.anm2_change(Document::FRAMES);
});
}
}
isShortenChordHeld = isShortenFrame;
static bool isExtendChordHeld = false;
auto isExtendFrame = shortcut(manager.chords[SHORTCUT_EXTEND_FRAME], shortcut::GLOBAL);
if (isExtendFrame)
{
auto selectedFrames = frame_references_for_current_get();
std::erase_if(selectedFrames,
[](const Reference& frameReference) { return frameReference.itemType == TRIGGER; });
if (!selectedFrames.empty())
{
if (!isExtendChordHeld) frames_snapshot_command_push(EDIT_EXTEND_FRAME, selectedFrames);
command_push([=, this](Manager&, Document& document)
{
for (auto frameReference : selectedFrames)
{
auto frame = command_frame_get(document, frameReference);
if (!frame) continue;
frame->duration = std::min(FRAME_DURATION_MAX, frame->duration + 1);
}
document.anm2_change(Document::FRAMES);
});
}
}
isExtendChordHeld = isExtendFrame;
auto isPreviousFrame = shortcut(manager.chords[SHORTCUT_PREVIOUS_FRAME], shortcut::GLOBAL);
auto isNextFrame = shortcut(manager.chords[SHORTCUT_NEXT_FRAME], shortcut::GLOBAL);
auto isPreviousItem = shortcut(manager.chords[SHORTCUT_PREVIOUS_ITEM], shortcut::GLOBAL);
auto isNextItem = shortcut(manager.chords[SHORTCUT_NEXT_ITEM], shortcut::GLOBAL);
if (isPreviousFrame)
if (auto item = selected_item_get(); item && !item->children.empty())
reference.frameIndex = glm::clamp(--reference.frameIndex, 0, (int)item->children.size() - 1);
if (isNextFrame)
if (auto item = selected_item_get(); item && !item->children.empty())
reference.frameIndex = glm::clamp(++reference.frameIndex, 0, (int)item->children.size() - 1);
if (isPreviousFrame || isNextFrame)
{
if (auto item = selected_item_get(); item && !item->children.empty())
{
frames_selection_set_reference();
document.frameTime = frame_time_from_index_get(*item, reference.frameIndex);
}
}
if (isPreviousItem) reference_set_adjacent_item(-1);
if (isNextItem) reference_set_adjacent_item(1);
}
if (isTextPushed) ImGui::PopStyleColor();
}
}
+67
View File
@@ -0,0 +1,67 @@
#include "context.hpp"
namespace anm2ed::imgui
{
Timeline::Timeline() = default;
Timeline::~Timeline() = default;
TimelineContext::TimelineContext(Timeline& timeline, Manager& manager, Settings& settings, Resources& resources,
Clipboard& clipboard)
: timeline(timeline), isDragging(timeline.isDragging), isWindowHovered(timeline.isWindowHovered),
isHorizontalScroll(timeline.isHorizontalScroll), itemProperties(timeline.itemProperties),
bakePopup(timeline.bakePopup), bakeIntoOtherFramesPopup(timeline.bakeIntoOtherFramesPopup),
makeManyRegionsPopup(timeline.makeManyRegionsPopup),
bakeIntoOtherFramesTarget(timeline.bakeIntoOtherFramesTarget),
isBakeIntoOtherFramesLayers(timeline.isBakeIntoOtherFramesLayers),
isBakeIntoOtherFramesNulls(timeline.isBakeIntoOtherFramesNulls),
isMakeManyRegionsMapFrames(timeline.isMakeManyRegionsMapFrames),
makeManyRegionReferences(timeline.makeManyRegionReferences), hoveredTime(timeline.hoveredTime),
isFrameBoxPending(timeline.isFrameBoxPending), isFrameBoxSelecting(timeline.isFrameBoxSelecting),
isFrameBoxAdditive(timeline.isFrameBoxAdditive), frameBoxStart(timeline.frameBoxStart),
frameBoxEnd(timeline.frameBoxEnd), frameBoxSelection(timeline.frameBoxSelection),
rowSelectionAnchor(timeline.rowSelectionAnchor), isRowSelectionAnchorSet(timeline.isRowSelectionAnchorSet),
groupPropertiesPopup(timeline.groupPropertiesPopup), groupName(timeline.groupName),
groupAnimationIndex(timeline.groupAnimationIndex), groupType(timeline.groupType), groupId(timeline.groupId),
draggedFrameReference(timeline.draggedFrameReference), isDraggedFrameActive(timeline.isDraggedFrameActive),
draggedFrameType(timeline.draggedFrameType), draggedFrameIndex(timeline.draggedFrameIndex),
draggedFrameStart(timeline.draggedFrameStart), draggedFrameStartDuration(timeline.draggedFrameStartDuration),
draggedFrameStartDurations(timeline.draggedFrameStartDurations),
draggedFrameStartMouseX(timeline.draggedFrameStartMouseX), draggedFrameWidth(timeline.draggedFrameWidth),
isDraggedFrameSnapshot(timeline.isDraggedFrameSnapshot), frameFocusRequested(timeline.frameFocusRequested),
frameFocusIndex(timeline.frameFocusIndex), frameMoveDrag(timeline.frameMoveDrag),
frameSelectionSnapshot(timeline.frameSelectionSnapshot), frameSelectionLocked(timeline.frameSelectionLocked),
isFrameSelectionLocked(timeline.isFrameSelectionLocked),
frameSelectionSnapshotReference(timeline.frameSelectionSnapshotReference),
frameSelectionAnchor(timeline.frameSelectionAnchor), isFrameSelectionAnchorSet(timeline.isFrameSelectionAnchorSet),
animationLengthEditIndex(timeline.animationLengthEditIndex), rowDragReferences(timeline.rowDragReferences),
scroll(timeline.scroll), style(timeline.style), manager(manager), settings(settings), resources(resources),
clipboard(clipboard), document(*manager.get()), anm2(document.anm2), playback(document.playback),
reference(document.reference), frames(document.frames), region(document.region)
{
}
void TimelineContext::update()
{
animation = anm2.element_get(ElementType::ANIMATION, reference.animationIndex);
rowFrameChildHeight = ImGui::GetTextLineHeightWithSpacing() + ImGui::GetStyle().WindowPadding.y * 1.5f;
style = ImGui::GetStyle();
isLightTheme = settings.theme == theme::LIGHT;
isTextPushed = false;
if (isLightTheme)
{
ImGui::PushStyleColor(ImGuiCol_Text, TIMELINE_TEXT_COLOR_LIGHT);
isTextPushed = true;
}
commands_bind();
draw();
}
void Timeline::update(Manager& manager, Settings& settings, Resources& resources, Clipboard& clipboard)
{
if (!manager.get()) return;
context = std::make_unique<TimelineContext>(*this, manager, settings, resources, clipboard);
context->update();
}
}
@@ -1,5 +1,6 @@
#pragma once
#include <memory>
#include <set>
#include <string>
#include <vector>
@@ -14,6 +15,8 @@
namespace anm2ed::imgui
{
struct TimelineContext;
struct TimelineRowReference
{
int documentIndex{-1};
@@ -56,6 +59,8 @@ namespace anm2ed::imgui
class Timeline
{
friend struct TimelineContext;
bool isDragging{};
bool isWindowHovered{};
bool isHorizontalScroll{};
@@ -105,8 +110,11 @@ namespace anm2ed::imgui
std::vector<TimelineRowReference> rowDragReferences{};
glm::vec2 scroll{};
ImGuiStyle style{};
std::unique_ptr<TimelineContext> context{};
public:
Timeline();
~Timeline();
void update(Manager&, Settings&, Resources&, Clipboard&);
};
}
+629
View File
@@ -0,0 +1,629 @@
#include "context.hpp"
namespace anm2ed::imgui
{
void TimelineContext::item_child(const TimelineItemRow& row, int index)
{
ImGui::PushID(index);
auto type = row.type;
auto id = row.id;
auto row_reference_make = [&]()
{ return Reference{reference.animationIndex, type, id, -1, row.rootGroupType, row.rootGroupId}; };
if (row.isGroup)
{
auto group = row_group_get(row);
if (!group)
{
ImGui::PopID();
return;
}
auto label = group->name.empty() ? std::string(localize.get(TEXT_NEW_GROUP)) : group->name;
auto itemSize = ImVec2(ImGui::GetContentRegionAvail().x, rowFrameChildHeight);
auto isGroupVisible = group->isVisible;
auto colorVec = item_color_vec(type);
if (is_group_selected(row))
{
if (isLightTheme)
colorVec = ITEM_COLOR_LIGHT_SELECTED[type_index(type)];
else
colorVec = item_color_active_vec(type);
}
auto color = to_imvec4(isGroupVisible ? colorVec : colorVec * COLOR_HIDDEN_MULTIPLIER);
ImGui::PushStyleColor(ImGuiCol_ChildBg, color);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, style.ItemSpacing);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, style.WindowPadding);
if (ImGui::BeginChild("##Group Child", itemSize, ImGuiChildFlags_Borders, ImGuiWindowFlags_NoScrollWithMouse))
{
auto cursorPos = ImGui::GetCursorPos();
auto groupChildMin = ImGui::GetWindowPos();
auto groupChildMax = ImVec2(groupChildMin.x + ImGui::GetWindowSize().x,
groupChildMin.y + ImGui::GetWindowSize().y);
auto toggle_group = [&]()
{
auto targetRow = row;
auto targetAnimationIndex = reference.animationIndex;
edit_command_push(EDIT_TOGGLE_GROUP_EXPANDED, Document::ITEMS,
[=, this](Manager&, Document& document) mutable
{
auto animation = command_animation_get(document, targetAnimationIndex);
auto container =
animation ? element_child_first_get(*animation, container_type_get(targetRow.type))
: nullptr;
auto group = container ? element_child_id_get(*container, ElementType::GROUP,
targetRow.id)
: nullptr;
if (!group) return;
group->isExpanded = !group->isExpanded;
});
};
ImGui::SetCursorPos(to_imvec2(to_vec2(cursorPos) - to_vec2(style.ItemSpacing)));
ImGui::SetNextItemAllowOverlap();
ImGui::InvisibleButton("##Group Button", itemSize);
auto groupButtonMin = ImGui::GetItemRectMin();
auto groupButtonMax = ImGui::GetItemRectMax();
auto mousePos = ImGui::GetIO().MousePos;
auto is_mouse_in_rect = [](ImVec2 mouse, ImVec2 min, ImVec2 max)
{ return mouse.x >= min.x && mouse.x < max.x && mouse.y >= min.y && mouse.y < max.y; };
auto isGroupHovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem) &&
is_mouse_in_rect(mousePos, groupButtonMin, groupButtonMax);
bool isGroupTooltipDelayed{};
if (isGroupHovered)
{
auto& imguiStyle = ImGui::GetStyle();
auto previousTooltipDelay = imguiStyle.HoverDelayNormal;
imguiStyle.HoverDelayNormal = FRAME_TOOLTIP_HOVER_DELAY;
isGroupTooltipDelayed =
ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary | ImGuiHoveredFlags_DelayNormal |
ImGuiHoveredFlags_AllowWhenDisabled | ImGuiHoveredFlags_NoSharedDelay);
imguiStyle.HoverDelayNormal = previousTooltipDelay;
}
if (ImGui::BeginDragDropSource(DRAG_DROP_SOURCE_FLAGS))
{
rowDragReferences = row_drag_references_get(row);
ImGui::SetDragDropPayload("Timeline Row Drag Drop", rowDragReferences.data(),
(int)rowDragReferences.size() * (int)sizeof(TimelineRowReference));
ImGui::EndDragDropSource();
}
if (ImGui::BeginDragDropTarget())
{
if (auto payload = ImGui::AcceptDragDropPayload(
"Timeline Row Drag Drop",
ImGuiDragDropFlags_AcceptBeforeDelivery | ImGuiDragDropFlags_AcceptNoDrawDefaultRect))
{
auto groupDropThird = (groupButtonMax.y - groupButtonMin.y) / 3.0f;
auto dropZone = DropZone::BEFORE;
if (mousePos.y >= groupButtonMax.y - groupDropThird)
dropZone = DropZone::AFTER;
else if (mousePos.y >= groupButtonMin.y + groupDropThird)
dropZone = DropZone::INSIDE;
auto isDropAfter = dropZone != DropZone::BEFORE;
auto payloadRows = (TimelineRowReference*)payload->Data;
auto payloadCount = payload->DataSize / sizeof(TimelineRowReference);
std::vector<TimelineRowReference> draggedRows(payloadRows, payloadRows + payloadCount);
auto isDropIntoGroup = dropZone == DropZone::INSIDE && (row.type == LAYER || row.type == NULL_);
for (auto draggedRow : draggedRows)
if (draggedRow.isGroup || draggedRow.type != row.type) isDropIntoGroup = false;
if (isDropIntoGroup)
drop_box_draw(ImGui::GetWindowDrawList(), groupChildMin, groupChildMax);
else
drop_line_draw(ImGui::GetWindowDrawList(), groupChildMin, groupChildMax, isDropAfter);
if (payload->IsDelivery()) rows_move_to_row(draggedRows, row, isDropAfter, isDropIntoGroup);
}
ImGui::EndDragDropTarget();
}
ImGui::SetCursorPos(cursorPos);
auto folderIcon = group->isExpanded ? icon::FOLDER_OPEN : icon::FOLDER;
ImGui::Image(resources.icons[folderIcon].id, icon_size_get());
auto iconMin = ImGui::GetItemRectMin();
auto iconMax = ImGui::GetItemRectMax();
overlay_icon(resources.icons[folderIcon].id, itemIconTint, false);
ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_Text, itemTextColor);
ImGui::TextUnformatted(label.c_str());
ImGui::PopStyleColor();
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4());
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4());
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4());
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2());
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
ImGui::SetCursorPos(
ImVec2(itemSize.x - ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().ItemSpacing.x,
(itemSize.y - ImGui::GetTextLineHeightWithSpacing()) / 2));
int visibleIcon = isGroupVisible ? icon::VISIBLE : icon::INVISIBLE;
if (ImGui::ImageButton("##Group Visible Toggle", resources.icons[visibleIcon].id, icon_size_get()))
{
auto targetAnimationIndex = reference.animationIndex;
auto targetType = type;
auto targetGroupId = group->id;
auto targetVisible = !isGroupVisible;
edit_command_push(EDIT_TOGGLE_ITEM_VISIBILITY, Document::FRAMES,
[=, this](Manager&, Document& document)
{
auto animation = command_animation_get(document, targetAnimationIndex);
auto container =
animation ? element_child_first_get(*animation, container_type_get(targetType))
: nullptr;
if (!container) return;
auto group = element_child_id_get(*container, ElementType::GROUP, targetGroupId);
if (!group) return;
group->isVisible = targetVisible;
});
}
auto visibleButtonMin = ImGui::GetItemRectMin();
auto visibleButtonMax = ImGui::GetItemRectMax();
overlay_icon(resources.icons[visibleIcon].id, itemIconTint, false);
ImGui::SetItemTooltip("%s", isGroupVisible ? localize.get(TOOLTIP_ITEM_VISIBILITY_SHOWN)
: localize.get(TOOLTIP_ITEM_VISIBILITY_HIDDEN));
ImGui::PopStyleVar(2);
ImGui::PopStyleColor(3);
auto isIconHovered = isGroupHovered && is_mouse_in_rect(mousePos, iconMin, iconMax);
auto isVisibleButtonHovered = isGroupHovered && is_mouse_in_rect(mousePos, visibleButtonMin, visibleButtonMax);
if (isGroupTooltipDelayed && !isVisibleButtonHovered)
{
ImGui::BeginTooltip();
ImGui::PushFont(resources.fonts[font::BOLD].get(), font::SIZE);
ImGui::TextUnformatted(label.c_str());
ImGui::PopFont();
ImGui::TextUnformatted(std::vformat(localize.get(FORMAT_ID), std::make_format_args(group->id)).c_str());
auto groupItemsCount = group_items_count_get(type, group->id);
ImGui::TextUnformatted(
std::vformat(localize.get(FORMAT_ITEMS_COUNT), std::make_format_args(groupItemsCount)).c_str());
ImGui::EndTooltip();
}
if (isIconHovered && ImGui::IsMouseReleased(ImGuiMouseButton_Left) &&
!ImGui::IsMouseDragPastThreshold(ImGuiMouseButton_Left))
toggle_group();
else if (isGroupHovered && !isIconHovered && !isVisibleButtonHovered &&
ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
group_properties_open(row, *group);
else if (isGroupHovered && !isIconHovered && !isVisibleButtonHovered &&
ImGui::IsMouseReleased(ImGuiMouseButton_Left) && !ImGui::IsMouseDragPastThreshold(ImGuiMouseButton_Left))
row_selection_set(row);
}
ImGui::EndChild();
ImGui::PopStyleVar(2);
ImGui::PopStyleColor();
ImGui::PopID();
return;
}
auto item = item_get(type, id, row.rootGroupType, row.rootGroupId);
if (type != NONE && !item)
{
ImGui::PopID();
return;
}
auto isItemVisible = item ? item->isVisible : false;
auto isVisible = item ? item->isVisible && is_track_group_visible(type, row.groupId) : false;
if (item && type == ROOT && row.rootGroupId != -1)
isVisible = item->isVisible && is_track_group_visible(row.rootGroupType, row.rootGroupId);
auto& isOnlyShowLayers = settings.timelineIsOnlyShowLayers;
if (isOnlyShowLayers && type != LAYER) isVisible = false;
auto isReferenced = is_same_item(reference, row_reference_make());
auto isItemSelected = is_row_selected(row);
auto label = [&]() -> std::string
{
if (type == LAYER)
{
auto layer = layer_get(id);
if (!layer) return localize.get(TYPE_STRINGS[type]);
return std::vformat(localize.get(FORMAT_LAYER), std::make_format_args(id, layer->name, layer->spritesheetId));
}
if (type == NULL_)
{
auto null = null_get(id);
if (!null) return localize.get(TYPE_STRINGS[type]);
return std::vformat(localize.get(FORMAT_NULL), std::make_format_args(id, null->name));
}
return localize.get(TYPE_STRINGS[type]);
}();
auto icon = TYPE_ICONS[type];
auto iconTintCurrent = isLightTheme && type == NONE ? ImVec4(1.0f, 1.0f, 1.0f, 1.0f) : itemIconTint;
auto baseColorVec = item_color_vec(type);
auto activeColorVec = item_color_active_vec(type);
auto colorVec = baseColorVec;
if (isItemSelected && type != NONE)
{
if (isLightTheme)
colorVec = ITEM_COLOR_LIGHT_SELECTED[type_index(type)];
else
colorVec = activeColorVec;
}
auto color = to_imvec4(colorVec);
color = !isVisible ? to_imvec4(colorVec * COLOR_HIDDEN_MULTIPLIER) : color;
ImGui::PushStyleColor(ImGuiCol_ChildBg, color);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, style.ItemSpacing);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, style.WindowPadding);
auto itemSize = ImVec2(ImGui::GetContentRegionAvail().x, rowFrameChildHeight);
if (ImGui::BeginChild(label.c_str(), itemSize, ImGuiChildFlags_Borders, ImGuiWindowFlags_NoScrollWithMouse))
{
auto cursorPos = ImGui::GetCursorPos();
auto itemChildMin = ImGui::GetWindowPos();
auto itemChildMax = ImVec2(itemChildMin.x + ImGui::GetWindowSize().x, itemChildMin.y + ImGui::GetWindowSize().y);
if (type != NONE)
{
ImGui::SetCursorPos(to_imvec2(to_vec2(cursorPos) - to_vec2(style.ItemSpacing)));
ImGui::SetNextItemAllowOverlap();
ImGui::SetNextItemStorageID(id);
ImGui::InvisibleButton("##Item Button", itemSize);
auto itemButtonMin = ImGui::GetItemRectMin();
auto itemButtonMax = ImGui::GetItemRectMax();
auto isItemButtonHovered = ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem);
if (type == LAYER || type == NULL_)
{
if (ImGui::BeginDragDropSource(DRAG_DROP_SOURCE_FLAGS))
{
rowDragReferences = row_drag_references_get(row);
ImGui::SetDragDropPayload("Timeline Row Drag Drop", rowDragReferences.data(),
(int)rowDragReferences.size() * (int)sizeof(TimelineRowReference));
ImGui::EndDragDropSource();
}
if (ImGui::BeginDragDropTarget())
{
if (auto payload = ImGui::AcceptDragDropPayload(
"Timeline Row Drag Drop",
ImGuiDragDropFlags_AcceptBeforeDelivery | ImGuiDragDropFlags_AcceptNoDrawDefaultRect))
{
auto isDropAfter = is_drop_after(itemButtonMin, itemButtonMax);
drop_line_draw(ImGui::GetWindowDrawList(), itemChildMin, itemChildMax, isDropAfter);
auto payloadRows = (TimelineRowReference*)payload->Data;
auto payloadCount = payload->DataSize / sizeof(TimelineRowReference);
std::vector<TimelineRowReference> draggedRows(payloadRows, payloadRows + payloadCount);
if (payload->IsDelivery()) rows_move_to_row(draggedRows, row, isDropAfter, false);
}
ImGui::EndDragDropTarget();
}
}
if (isItemButtonHovered)
{
if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) item_base_properties_open(type, id);
else if (ImGui::IsMouseReleased(ImGuiMouseButton_Left) &&
!ImGui::IsMouseDragPastThreshold(ImGuiMouseButton_Left))
row_selection_set(row);
auto& imguiStyle = ImGui::GetStyle();
auto previousTooltipFlags = imguiStyle.HoverFlagsForTooltipMouse;
auto previousTooltipDelay = imguiStyle.HoverDelayNormal;
imguiStyle.HoverFlagsForTooltipMouse = ImGuiHoveredFlags_Stationary | ImGuiHoveredFlags_DelayNormal |
ImGuiHoveredFlags_AllowWhenDisabled |
ImGuiHoveredFlags_NoSharedDelay;
imguiStyle.HoverDelayNormal = FRAME_TOOLTIP_HOVER_DELAY;
bool showItemTooltip = ImGui::BeginItemTooltip();
imguiStyle.HoverFlagsForTooltipMouse = previousTooltipFlags;
imguiStyle.HoverDelayNormal = previousTooltipDelay;
if (showItemTooltip)
{
auto yesNoLabel = [&](bool value) { return value ? localize.get(BASIC_YES) : localize.get(BASIC_NO); };
auto visibleLabel = yesNoLabel(isVisible);
auto framesCount = item_frames_count(item);
switch (type)
{
case ROOT:
{
ImGui::PushFont(resources.fonts[font::BOLD].get(), font::SIZE);
ImGui::TextUnformatted(localize.get(BASIC_ROOT));
ImGui::PopFont();
ImGui::TextUnformatted(
std::vformat(localize.get(FORMAT_VISIBLE), std::make_format_args(visibleLabel)).c_str());
auto transformLabel = yesNoLabel(settings.previewIsRootTransform);
ImGui::TextUnformatted(
std::vformat(localize.get(FORMAT_TRANSFORM), std::make_format_args(transformLabel)).c_str());
ImGui::TextUnformatted(
std::vformat(localize.get(FORMAT_FRAMES_COUNT), std::make_format_args(framesCount)).c_str());
break;
}
case LAYER:
{
auto layer = layer_get(id);
if (!layer) break;
ImGui::PushFont(resources.fonts[font::BOLD].get(), font::SIZE);
ImGui::TextUnformatted(layer->name.c_str());
ImGui::PopFont();
ImGui::TextUnformatted(std::vformat(localize.get(FORMAT_ID), std::make_format_args(id)).c_str());
ImGui::TextUnformatted(
std::vformat(localize.get(FORMAT_SPRITESHEET_ID), std::make_format_args(layer->spritesheetId))
.c_str());
ImGui::TextUnformatted(
std::vformat(localize.get(FORMAT_VISIBLE), std::make_format_args(visibleLabel)).c_str());
ImGui::TextUnformatted(
std::vformat(localize.get(FORMAT_FRAMES_COUNT), std::make_format_args(framesCount)).c_str());
break;
}
case NULL_:
{
auto nullInfo = null_get(id);
if (!nullInfo) break;
ImGui::PushFont(resources.fonts[font::BOLD].get(), font::SIZE);
ImGui::TextUnformatted(nullInfo->name.c_str());
ImGui::PopFont();
auto rectLabel = yesNoLabel(nullInfo->isShowRect);
ImGui::TextUnformatted(std::vformat(localize.get(FORMAT_ID), std::make_format_args(id)).c_str());
ImGui::TextUnformatted(
std::vformat(localize.get(FORMAT_RECT), std::make_format_args(rectLabel)).c_str());
ImGui::TextUnformatted(
std::vformat(localize.get(FORMAT_VISIBLE), std::make_format_args(visibleLabel)).c_str());
ImGui::TextUnformatted(
std::vformat(localize.get(FORMAT_FRAMES_COUNT), std::make_format_args(framesCount)).c_str());
break;
}
case TRIGGER:
{
ImGui::PushFont(resources.fonts[font::BOLD].get(), font::SIZE);
ImGui::TextUnformatted(localize.get(BASIC_TRIGGERS));
ImGui::PopFont();
ImGui::TextUnformatted(
std::vformat(localize.get(FORMAT_VISIBLE), std::make_format_args(visibleLabel)).c_str());
ImGui::TextUnformatted(
std::vformat(localize.get(FORMAT_TRIGGERS_COUNT), std::make_format_args(framesCount)).c_str());
break;
}
default:
break;
}
ImGui::EndTooltip();
}
}
auto contentCursorPos = cursorPos;
contentCursorPos.x += (float)row.depth * ImGui::GetTextLineHeightWithSpacing();
ImGui::SetCursorPos(contentCursorPos);
ImGui::Image(resources.icons[icon].id, icon_size_get());
overlay_icon(resources.icons[icon].id, iconTintCurrent, false);
ImGui::SameLine();
if (isReferenced) ImGui::PushFont(resources.fonts[font::ITALICS].get(), font::SIZE);
ImGui::PushStyleColor(ImGuiCol_Text, itemTextColor);
ImGui::TextUnformatted(label.c_str());
ImGui::PopStyleColor();
if (isReferenced) ImGui::PopFont();
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4());
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4());
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4());
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2());
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
ImGui::SetCursorPos(
ImVec2(itemSize.x - ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().ItemSpacing.x,
(itemSize.y - ImGui::GetTextLineHeightWithSpacing()) / 2));
int visibleIcon = isItemVisible ? icon::VISIBLE : icon::INVISIBLE;
if (ImGui::ImageButton("##Visible Toggle", resources.icons[visibleIcon].id, icon_size_get()))
{
auto animationIndex = reference.animationIndex;
auto targetType = type;
auto targetID = id;
auto targetGroupType = row.rootGroupType;
auto targetGroupId = row.rootGroupId;
edit_command_push(EDIT_TOGGLE_ITEM_VISIBILITY, Document::FRAMES,
[=, this](Manager&, Document& document)
{
auto item = command_item_get(document, animationIndex, targetType, targetID,
targetGroupType, targetGroupId);
if (!item) return;
item->isVisible = !item->isVisible;
});
}
overlay_icon(resources.icons[visibleIcon].id, iconTintCurrent, false);
ImGui::SetItemTooltip("%s", isItemVisible ? localize.get(TOOLTIP_ITEM_VISIBILITY_SHOWN)
: localize.get(TOOLTIP_ITEM_VISIBILITY_HIDDEN));
if (type == NULL_)
{
if (auto null = null_get(id))
{
auto& isShowRect = null->isShowRect;
auto rectIcon = isShowRect ? icon::SHOW_RECT : icon::HIDE_RECT;
ImGui::SetCursorPos(
ImVec2(itemSize.x - (ImGui::GetTextLineHeightWithSpacing() * 2) - ImGui::GetStyle().ItemSpacing.x,
(itemSize.y - ImGui::GetTextLineHeightWithSpacing()) / 2));
if (ImGui::ImageButton("##Rect Toggle", resources.icons[rectIcon].id, icon_size_get()))
{
auto nullID = id;
edit_command_push(EDIT_TOGGLE_NULL_RECT, Document::FRAMES,
[=, this](Manager&, Document& document)
{
auto nulls = document.anm2.element_get(ElementType::NULLS);
auto null = nulls ? element_child_id_get(*nulls, ElementType::NULL_ELEMENT, nullID)
: nullptr;
if (!null) return;
null->isShowRect = !null->isShowRect;
});
}
overlay_icon(resources.icons[rectIcon].id, iconTintCurrent, false);
ImGui::SetItemTooltip("%s", isShowRect ? localize.get(TOOLTIP_NULL_RECT_SHOWN)
: localize.get(TOOLTIP_NULL_RECT_HIDDEN));
}
}
ImGui::PopStyleVar(2);
ImGui::PopStyleColor(3);
}
else
{
auto cursorPos = ImGui::GetCursorPos();
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4());
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4());
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4());
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2());
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
ImGui::SetCursorPos(
ImVec2(itemSize.x - ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().ItemSpacing.x,
(itemSize.y - ImGui::GetTextLineHeightWithSpacing()) / 2));
auto& isShowUnused = settings.timelineIsShowUnused;
auto unusedIcon = isShowUnused ? icon::SHOW_UNUSED : icon::HIDE_UNUSED;
if (ImGui::ImageButton("##Unused Toggle", resources.icons[unusedIcon].id, icon_size_get()))
isShowUnused = !isShowUnused;
overlay_icon(resources.icons[unusedIcon].id, iconTintCurrent, false);
ImGui::SetItemTooltip("%s", isShowUnused ? localize.get(TOOLTIP_UNUSED_ITEMS_SHOWN)
: localize.get(TOOLTIP_UNUSED_ITEMS_HIDDEN));
auto& showLayersOnly = settings.timelineIsOnlyShowLayers;
auto layersIcon = showLayersOnly ? icon::SHOW_LAYERS : icon::HIDE_LAYERS;
ImGui::SetCursorPos(
ImVec2(itemSize.x - (ImGui::GetTextLineHeightWithSpacing() * 2) - ImGui::GetStyle().ItemSpacing.x,
(itemSize.y - ImGui::GetTextLineHeightWithSpacing()) / 2));
if (ImGui::ImageButton("##Layers Toggle", resources.icons[layersIcon].id, icon_size_get()))
showLayersOnly = !showLayersOnly;
overlay_icon(resources.icons[layersIcon].id, iconTintCurrent, false);
ImGui::SetItemTooltip("%s", showLayersOnly ? localize.get(TOOLTIP_ONLY_LAYERS_VISIBLE)
: localize.get(TOOLTIP_ALL_ITEMS_VISIBLE));
ImGui::PopStyleVar(2);
ImGui::PopStyleColor(3);
ImGui::SetCursorPos(cursorPos);
ImGui::BeginDisabled();
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
ImGui::Text("(?)");
ImGui::PopStyleColor();
auto tooltipShortcuts = std::vformat(
localize.get(TOOLTIP_TIMELINE_SHORTCUTS),
std::make_format_args(settings.shortcutMovePlayheadBack, settings.shortcutMovePlayheadForward,
settings.shortcutShortenFrame, settings.shortcutExtendFrame,
settings.shortcutPreviousFrame, settings.shortcutNextFrame,
settings.shortcutPreviousItem, settings.shortcutNextItem));
ImGui::SetItemTooltip("%s", tooltipShortcuts.c_str());
ImGui::EndDisabled();
}
}
ImGui::EndChild();
ImGui::PopStyleColor();
ImGui::PopStyleVar(2);
ImGui::PopID();
}
void TimelineContext::items_child()
{
auto itemsChildSize = ImVec2(ITEM_CHILD_WIDTH, ImGui::GetContentRegionAvail().y);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2());
bool isItemsChildOpen = ImGui::BeginChild("##Items Child", itemsChildSize, ImGuiChildFlags_Borders);
ImGui::PopStyleVar();
if (isItemsChildOpen)
{
auto itemsListChildSize = ImVec2(ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y -
ImGui::GetTextLineHeightWithSpacing() -
ImGui::GetStyle().ItemSpacing.y * 2);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2());
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2());
if (ImGui::BeginChild("##Items List Child", itemsListChildSize, ImGuiChildFlags_Borders,
ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoScrollbar))
{
if (animation && ImGui::Shortcut(ImGuiMod_Ctrl | ImGuiKey_A, ImGuiInputFlags_RouteFocused))
{
auto rowReferences = timeline_row_references_get();
row_selection_clear();
for (auto rowReference : rowReferences)
row_selection_insert(rowReference);
if (!rowReferences.empty())
{
rowSelectionAnchor = rowReferences.front();
isRowSelectionAnchorSet = true;
}
frames_selection_reset_for(document);
}
if (animation && shortcut(manager.chords[SHORTCUT_GROUP], shortcut::FOCUSED) &&
!item_references_groupable_get().empty())
item_group();
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2());
ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarSize, 0.0f);
if (ImGui::BeginTable("##Item Table", 1, ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollY))
{
ImGui::GetCurrentWindow()->Flags |= ImGuiWindowFlags_NoScrollWithMouse;
ImGui::SetScrollY(scroll.y);
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableSetupColumn("##Items");
auto item_child_row = [&](const TimelineItemRow& row, int index)
{
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
item_child(row, index);
};
int index{};
item_child_row({.type = NONE}, index++);
if (animation)
for (const auto& row : timeline_item_rows_get())
item_child_row(row, index++);
if (isHorizontalScroll && ImGui::GetCurrentWindow()->ScrollbarY)
{
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::Dummy(ImVec2(0, style.ScrollbarSize));
}
ImGui::EndTable();
}
ImGui::PopStyleVar(2);
item_context_menu();
}
ImGui::PopStyleVar(2);
ImGui::EndChild();
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, style.WindowPadding);
ImGui::SetCursorPos(ImVec2(ImGui::GetCursorPosX() + style.WindowPadding.x, ImGui::GetCursorPosY()));
auto widgetSize = widget_size_with_row_get(2, ImGui::GetContentRegionAvail().x - style.WindowPadding.x);
ImGui::BeginDisabled(!animation);
{
shortcut(manager.chords[SHORTCUT_ADD]);
if (ImGui::Button(localize.get(BASIC_ADD), widgetSize)) itemProperties.open();
set_item_tooltip_shortcut(localize.get(TOOLTIP_ADD_ITEM), settings.shortcutAdd);
ImGui::SameLine();
auto selectedRows = selected_row_references_get();
auto isRemoveAvailable = std::ranges::any_of(selectedRows, [](const TimelineRowReference& row)
{ return row.type == LAYER || row.type == NULL_; });
ImGui::BeginDisabled(!isRemoveAvailable);
shortcut(manager.chords[SHORTCUT_REMOVE]);
if (ImGui::Button(localize.get(BASIC_REMOVE), widgetSize)) item_remove();
set_item_tooltip_shortcut(localize.get(TOOLTIP_REMOVE_ITEMS), settings.shortcutRemove);
ImGui::EndDisabled();
}
ImGui::EndDisabled();
ImGui::PopStyleVar();
}
ImGui::EndChild();
}
}