From b5280b4a4d844eae5b175d6f4f4f6e5faeee5784 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Tue, 11 Nov 2025 00:25:36 -0500 Subject: [PATCH] Have a simple thing that moves every 3 seconds of a song/audio playing to a new panel. --- storyboard/ui.cpp | 30 +++++++++++++++++++++++++++++- storyboard/ui.hpp | 5 +++++ tools/storyboard.cpp | 1 + 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/storyboard/ui.cpp b/storyboard/ui.cpp index c98392c..a6183cb 100644 --- a/storyboard/ui.cpp +++ b/storyboard/ui.cpp @@ -1,14 +1,17 @@ #include "storyboard/ui.hpp" #include "components.hpp" #include "animation.hpp" +#include "sound.hpp" namespace storyboard { UI::UI() : $view_texture({SCREEN_WIDTH, SCREEN_HEIGHT}), - $view_sprite($view_texture.getTexture()) + $view_sprite($view_texture.getTexture()), + $audio(sound::get_sound_pair("ambient_1").sound) { $view_sprite.setPosition({0, 0}); $camera.style("pan"); + sound::play("ambient_1", true); } void UI::init() { @@ -23,9 +26,14 @@ namespace storyboard { "[a|b|c]" "[*%(200,100)d|_|f]" "[g|h|i]"); + + for(auto& [key, value] : $ui.$parser.cells) { + $cell_names.push_back(key); + } } void UI::render(sf::RenderWindow &window) { + track_audio(); $view_texture.clear(); $camera.render($view_texture); @@ -36,6 +44,26 @@ namespace storyboard { window.draw($view_sprite); } + void UI::track_audio() { + int track_head = int($audio->getPlayingOffset().asSeconds()); + + if(track_head % 3 == 0) { + if($moving) return; + $moving = true; // prevent motion until next tick + + // get the original zoom target as from + auto& cell = $ui.cell_for($zoom_target); + $camera.position(cell.mid_x, cell.mid_y); + + // get the new target from the cell names + $zoom_target = $cell_names.at(track_head % $cell_names.size()); + zoom($zoom_target); + $camera.play(); + } else { + $moving = false; + } + } + bool UI::mouse(float x, float y, guecs::Modifiers mods) { auto& cell = $ui.cell_for($zoom_target); diff --git a/storyboard/ui.hpp b/storyboard/ui.hpp index e819d0a..a0e4875 100644 --- a/storyboard/ui.hpp +++ b/storyboard/ui.hpp @@ -2,6 +2,7 @@ #include "constants.hpp" #include #include "camera.hpp" +#include namespace storyboard { @@ -10,7 +11,10 @@ namespace storyboard { sf::RenderTexture $view_texture; sf::Sprite $view_sprite; cinematic::Camera $camera; + std::shared_ptr $audio; std::string $zoom_target = "a"; + int $moving = false; + std::vector $cell_names; UI(); @@ -19,6 +23,7 @@ namespace storyboard { bool mouse(float x, float y, guecs::Modifiers mods); void zoom(const std::string &cell_name); void reset(); + void track_audio(); }; } diff --git a/tools/storyboard.cpp b/tools/storyboard.cpp index 3379042..1b84355 100644 --- a/tools/storyboard.cpp +++ b/tools/storyboard.cpp @@ -17,6 +17,7 @@ int main(int, char*[]) { guecs::init(&backend); animation::init(); cinematic::init(); + sound::init(); sf::RenderWindow window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Storyboard Editor"); window.setVerticalSyncEnabled(VSYNC);