timeline refactor, bit broken rn

This commit is contained in:
2025-11-09 10:35:21 -05:00
parent 1e35910b0a
commit e2799b1e58
41 changed files with 2034 additions and 1374 deletions

View File

@@ -42,51 +42,22 @@ namespace anm2ed::imgui
auto& isSound = settings.timelineIsSound;
auto& isOnlyShowLayers = settings.timelineIsOnlyShowLayers;
if (isSound && !anm2.content.sounds.empty())
if (auto animation = document.animation_get(); animation)
if (animation->triggers.isVisible && !isOnlyShowLayers)
if (auto trigger = animation->triggers.frame_generate(playback.time, anm2::TRIGGER);
trigger.is_visible(anm2::TRIGGER))
if (anm2.content.sounds.contains(trigger.soundID)) anm2.content.sounds[trigger.soundID].audio.play();
if (!anm2.content.sounds.empty() && isSound)
{
if (auto animation = document.animation_get();
animation && animation->triggers.isVisible && (!isOnlyShowLayers || manager.isRecording))
{
if (auto trigger = animation->triggers.frame_generate(playback.time, anm2::TRIGGER);
trigger.is_visible(anm2::TRIGGER))
if (anm2.content.sounds.contains(trigger.soundID)) anm2.content.sounds[trigger.soundID].audio.play(mixer);
}
}
document.reference.frameTime = playback.time;
}
if (manager.isRecording)
{
if (manager.isRecordingStart)
{
if (settings.renderIsRawAnimation)
{
savedSettings = settings;
settings.previewBackgroundColor = vec4();
settings.previewIsGrid = false;
settings.previewIsAxes = false;
settings.timelineIsOnlyShowLayers = true;
savedZoom = zoom;
savedPan = pan;
if (auto animation = document.animation_get())
{
auto rect = animation->rect(isRootTransform);
size = vec2(rect.z, rect.w) * scale;
set_to_rect(zoom, pan, rect);
}
isSizeTrySet = false;
bind();
viewport_set();
clear(settings.previewBackgroundColor);
unbind();
}
manager.isRecordingStart = false;
return; // Need to wait an additional frame. Kind of hacky, but oh well.
}
auto pixels = pixels_get();
renderFrames.push_back(Texture(pixels.data(), size));
@@ -120,7 +91,7 @@ namespace anm2ed::imgui
}
else
{
if (animation_render(ffmpegPath, path, renderFrames, (render::Type)type, size, anm2.info.fps))
if (animation_render(ffmpegPath, path, renderFrames, audioStream, (render::Type)type, size, anm2.info.fps))
toasts.info(std::format("Exported rendered animation to: {}", path));
else
toasts.warning(std::format("Could not output rendered animation: {}", path));
@@ -133,12 +104,49 @@ namespace anm2ed::imgui
settings = savedSettings;
isSizeTrySet = true;
if (settings.timelineIsSound) audioStream.capture_end(mixer);
playback.isPlaying = false;
playback.isFinished = false;
manager.isRecording = false;
manager.progressPopup.close();
}
}
if (manager.isRecordingStart)
{
savedSettings = settings;
if (settings.timelineIsSound) audioStream.capture_begin(mixer);
if (settings.renderIsRawAnimation)
{
settings.previewBackgroundColor = vec4();
settings.previewIsGrid = false;
settings.previewIsAxes = false;
settings.timelineIsOnlyShowLayers = true;
savedZoom = zoom;
savedPan = pan;
if (auto animation = document.animation_get())
{
if (auto rect = animation->rect(isRootTransform); rect != vec4(-1.0f))
{
size_set(vec2(rect.w, rect.z) * scale);
set_to_rect(zoom, pan, rect);
}
}
isSizeTrySet = false;
bind();
clear(settings.previewBackgroundColor);
unbind();
}
manager.isRecordingStart = false;
manager.isRecording = true;
}
}
void AnimationPreview::update(Manager& manager, Settings& settings, Resources& resources)
@@ -270,8 +278,8 @@ namespace anm2ed::imgui
auto cursorScreenPos = ImGui::GetCursorScreenPos();
if (isSizeTrySet) size_set(to_vec2(ImGui::GetContentRegionAvail()));
bind();
viewport_set();
bind();
clear(backgroundColor);
if (isAxes) axes_render(shaderAxes, zoom, pan, axesColor);
if (isGrid) grid_render(shaderGrid, zoom, pan, gridSize, gridOffset, gridColor);
@@ -412,7 +420,7 @@ namespace anm2ed::imgui
isPreviewHovered = ImGui::IsItemHovered();
if (animation && animation->triggers.isVisible && !isOnlyShowLayers)
if (animation && animation->triggers.isVisible && !isOnlyShowLayers && !manager.isRecording)
{
if (auto trigger = animation->triggers.frame_generate(frameTime, anm2::TRIGGER);
trigger.isVisible && trigger.eventID > -1)

View File

@@ -1,5 +1,6 @@
#pragma once
#include "audio_stream.h"
#include "canvas.h"
#include "manager.h"
#include "resources.h"
@@ -9,6 +10,8 @@ namespace anm2ed::imgui
{
class AnimationPreview : public Canvas
{
MIX_Mixer* mixer = MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, nullptr);
AudioStream audioStream = AudioStream(mixer);
bool isPreviewHovered{};
bool isSizeTrySet{true};
Settings savedSettings{};

View File

@@ -85,7 +85,7 @@ namespace anm2ed::imgui
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2());
selection.start(anm2.content.spritesheets.size());
selection.start(anm2.content.spritesheets.size(), ImGuiMultiSelectFlags_ClearOnEscape);
for (auto& [id, spritesheet] : anm2.content.spritesheets)
{
@@ -168,16 +168,16 @@ namespace anm2ed::imgui
context_menu();
}
ImGui::EndChild();
ImGui::PopID();
}
selection.finish();
ImGui::PopStyleVar(2);
context_menu();
selection.finish();
}
ImGui::EndChild();

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,6 @@
#pragma once
#include "clipboard.h"
#include "document.h"
#include "manager.h"
#include "resources.h"
#include "settings.h"
@@ -25,14 +24,6 @@ namespace anm2ed::imgui
ImDrawList* pickerLineDrawList{};
ImGuiStyle style{};
void context_menu(Document&, Settings&, Clipboard&);
void item_child(Manager&, Document&, anm2::Animation*, Settings&, Resources&, Clipboard&, anm2::Type, int, int&);
void items_child(Manager&, Document&, anm2::Animation*, Settings&, Resources&, Clipboard&);
void frame_child(Document&, anm2::Animation*, Settings&, Resources&, Clipboard&, anm2::Type, int, int&, float);
void frames_child(Document&, anm2::Animation*, Settings&, Resources&, Clipboard&);
void popups(Document&, anm2::Animation*, Settings&);
public:
void update(Manager&, Settings&, Resources&, Clipboard&);
};