diff options
Diffstat (limited to 'src/tangara/ui')
| -rw-r--r-- | src/tangara/ui/ui_events.hpp | 4 | ||||
| -rw-r--r-- | src/tangara/ui/ui_fsm.cpp | 25 | ||||
| -rw-r--r-- | src/tangara/ui/ui_fsm.hpp | 2 |
3 files changed, 31 insertions, 0 deletions
diff --git a/src/tangara/ui/ui_events.hpp b/src/tangara/ui/ui_events.hpp index 0f371769..ce9320fc 100644 --- a/src/tangara/ui/ui_events.hpp +++ b/src/tangara/ui/ui_events.hpp @@ -34,6 +34,10 @@ struct Screenshot : tinyfsm::Event { std::string filename; }; +struct SeekBack : tinyfsm::Event { + uint32_t seconds; +}; + namespace internal { struct InitDisplay : tinyfsm::Event { diff --git a/src/tangara/ui/ui_fsm.cpp b/src/tangara/ui/ui_fsm.cpp index aaf35d13..1b8c0984 100644 --- a/src/tangara/ui/ui_fsm.cpp +++ b/src/tangara/ui/ui_fsm.cpp @@ -403,6 +403,31 @@ void UiState::react(const Screenshot& ev) { SaveScreenshot(sCurrentScreen->root(), ev.filename); } +void UiState::react(const SeekBack& ev) { + const auto playback_position = sPlaybackPosition.get(); + if (!std::holds_alternative<int>(playback_position)) { + // I don't think this ever happens, but check anyway. + return; + } + + const auto track = sPlaybackTrack.get(); + if (!std::holds_alternative<audio::TrackInfo>(track)) { + // Nothing is playing + return; + } + + const auto current_position = std::get<int>(playback_position); + int32_t seek_position = current_position - ev.seconds; + if (seek_position < 1) { + seek_position = 0; + } + + events::Audio().Dispatch(audio::SetTrack{ + .new_track = std::get<audio::TrackInfo>(track).uri, + .seek_to_second = seek_position, + }); +} + void UiState::react(const system_fsm::KeyLockChanged& ev) { sDisplay->SetDisplayOn(!ev.locking); sInput->lock(ev.locking); diff --git a/src/tangara/ui/ui_fsm.hpp b/src/tangara/ui/ui_fsm.hpp index d4354bec..01f0beb1 100644 --- a/src/tangara/ui/ui_fsm.hpp +++ b/src/tangara/ui/ui_fsm.hpp @@ -56,6 +56,8 @@ class UiState : public tinyfsm::Fsm<UiState> { void react(const tinyfsm::Event& ev) {} void react(const Screenshot&); + void react(const SeekBack&); + virtual void react(const OnLuaError&) {} virtual void react(const DumpLuaStack&) {} virtual void react(const internal::BackPressed&) {} |
