From: Kostya Shishkov Date: Mon, 8 Jun 2026 16:10:33 +0000 (+0200) Subject: videoplayer: implement zoom change command X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=c52fdfb32a1d8b14e57502274479d952cdca1716;p=nihav-player.git videoplayer: implement zoom change command --- diff --git a/videoplayer/src/main.rs b/videoplayer/src/main.rs index ffc54ab..9f2255d 100644 --- a/videoplayer/src/main.rs +++ b/videoplayer/src/main.rs @@ -320,6 +320,8 @@ pub struct DispQueue<'a> { pub len: usize, pub width: usize, pub height: usize, + pub orig_w: usize, + pub orig_h: usize, pub osd_tex: Texture<'a>, pub empty_tex: Texture<'a>, } @@ -336,7 +338,7 @@ impl<'a> DispQueue<'a> { let mut osd_tex = texture_creator.create_texture_streaming(PixelFormatEnum::RGBA8888, width as u32, OSD_HEIGHT as u32).expect("failed to create RGBA texture"); osd_tex.set_blend_mode(BlendMode::Blend); - Self { pool, osd_tex, empty_tex, first_ts: 0, last_ts: 0, ts_valid: false, len, width, height, queue: VecDeque::with_capacity(len) } + Self { pool, osd_tex, empty_tex, first_ts: 0, last_ts: 0, ts_valid: false, len, width, height, orig_w, orig_h, queue: VecDeque::with_capacity(len) } } fn flush(&mut self) { @@ -454,6 +456,8 @@ struct Player { osd: OSD, show_osd: Option, + zoom_mode: bool, + #[cfg(feature="debug")] logfile: File, } @@ -507,6 +511,8 @@ impl Player { osd: OSD::new(), show_osd: None, + zoom_mode: false, + #[cfg(feature="debug")] logfile: File::create("debug.log").expect("'debug.log' should be available for writing"), } @@ -654,6 +660,38 @@ impl Player { if let Event::MouseWheel {direction: MouseWheelDirection::Normal, x: 0, y, ..} = event { self.seek(10, y > 0, dmx, disp_queue)?; } + if self.zoom_mode { + if let Event::KeyDown {keycode: Some(keycode), ..} = event { + let orig_w = disp_queue.orig_w as u32; + let orig_h = disp_queue.orig_h as u32; + let (sc_num, sc_den) = match keycode { + Keycode::Num1 | Keycode::Kp1 => (1, 1), + Keycode::Num2 | Keycode::Kp2 => (2, 1), + Keycode::Num3 | Keycode::Kp3 => (3, 1), + Keycode::Num5 | Keycode::Kp5 => (1, 2), + Keycode::Period | Keycode::KpPeriod => (3, 2), + _ => (0, 0) + }; + if sc_num != 0 { + let win = canvas.window_mut(); + let new_w = orig_w * sc_num / sc_den; + let new_h = orig_h * sc_num / sc_den; + match win.set_size(new_w, new_h) { + Ok(()) => {}, + Err(sdl2::IntegerOrSdlError::IntegerOverflows(errstr, _)) => { + println!("error resizing window: {errstr}"); + }, + Err(sdl2::IntegerOrSdlError::SdlError(errstr)) => { + println!("error resizing window: {errstr}"); + }, + } + } else { + println!(" wrong zoom modifier!"); + } + self.zoom_mode = false; + continue; + } + } if let Event::KeyDown {keycode: Some(keycode), keymod, ..} = event { match keycode { Keycode::Escape => { @@ -728,6 +766,9 @@ impl Player { dmx.set_options(&[NAOption{name: FORCE_SEEK_OPTION, value: NAValue::Bool(!force_seek)}]); } }, + Keycode::Z if keymod.contains(Mod::RSHIFTMOD) || keymod.contains(Mod::LSHIFTMOD) => { + self.zoom_mode = !self.no_sdl_scale; + }, _ => {}, }; if !self.paused && !self.quiet { @@ -1023,6 +1064,7 @@ impl Player { let mut event_pump = self.sdl_context.event_pump().expect("should be able to create event pump"); let mut last_disp = Instant::now(); let mut has_data = true; + self.zoom_mode = false; 'main: loop { self.seeked = false; let ret = self.handle_events(&mut event_pump, &mut canvas, &mut dmx, &mut disp_q);