diff options
author | Kostya Shishkov <kostya.shishkov@gmail.com> | 2023-06-15 18:46:53 +0200 |
---|---|---|
committer | Kostya Shishkov <kostya.shishkov@gmail.com> | 2023-06-15 18:46:53 +0200 |
commit | ff58185ab2070ba00779e48df0fd7e7f6a87ad9e (patch) | |
tree | 5fb1792444942883105c7616738af7e16c0ca34b | |
parent | 8686f9f650974a6065f93df178a76f8d24814ca7 (diff) | |
download | nihav-player-ff58185ab2070ba00779e48df0fd7e7f6a87ad9e.tar.gz |
allow to (un)pause playback by right mouse button click
-rw-r--r-- | videoplayer/src/main.rs | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/videoplayer/src/main.rs b/videoplayer/src/main.rs index 3f15d94..ca11d87 100644 --- a/videoplayer/src/main.rs +++ b/videoplayer/src/main.rs @@ -12,6 +12,7 @@ use std::thread; use sdl2::event::{Event, WindowEvent}; use sdl2::keyboard::Keycode; +use sdl2::mouse::MouseButton; use sdl2::render::{Canvas, Texture, TextureCreator}; use sdl2::pixels::PixelFormatEnum; use sdl2::video::{Window, WindowContext}; @@ -389,6 +390,21 @@ impl Player { } debug_log!(self; {format!(" prefilling done, frames {}-{} audio {}", disp_queue.start, disp_queue.end, self.acontrol.get_fill())}); } + fn toggle_pause(&mut self) { + self.paused = !self.paused; + if self.paused { + self.vsystem.enable_screen_saver(); + self.tkeep.set_ts(); + } else { + self.vsystem.disable_screen_saver(); + self.tkeep.set_time(); + } + if self.paused { + self.acontrol.pause(); + } else { + self.acontrol.resume(); + } + } fn handle_events(&mut self, event_pump: &mut sdl2::EventPump, canvas: &mut Canvas<Window>, dmx: &mut Demuxer, disp_queue: &mut DispQueue) -> bool { for event in event_pump.poll_iter() { if let Event::Quit {..} = event { @@ -401,6 +417,9 @@ impl Player { canvas.copy(disp_queue.get_last_texture(&self.osd), None, None).unwrap(); canvas.present(); } + if let Event::MouseButtonDown {mouse_btn: MouseButton::Right, ..} = event { + self.toggle_pause(); + } if let Event::KeyDown {keycode: Some(keycode), ..} = event { match keycode { Keycode::Escape | Keycode::Q => { @@ -415,21 +434,7 @@ impl Player { Keycode::Down => { self.seek(60, false, dmx, disp_queue); }, Keycode::PageUp => { self.seek(600, true, dmx, disp_queue); }, Keycode::PageDown => { self.seek(600, false, dmx, disp_queue); }, - Keycode::Space => { - self.paused = !self.paused; - if self.paused { - self.vsystem.enable_screen_saver(); - self.tkeep.set_ts(); - } else { - self.vsystem.disable_screen_saver(); - self.tkeep.set_time(); - } - if self.paused { - self.acontrol.pause(); - } else { - self.acontrol.resume(); - } - }, + Keycode::Space => { self.toggle_pause(); }, Keycode::Plus | Keycode::KpPlus => { self.volume = (self.volume + 10).min(MAX_VOLUME); if !self.mute { |