From eb0422cb06fc46d1bbac968e0996f6f9b4614197 Mon Sep 17 00:00:00 2001 From: Danilo Spinella Date: Mon, 15 Apr 2024 15:27:56 +0200 Subject: [PATCH] Rename animation to transition --- daemon/src/config.rs | 10 ++++----- daemon/src/render/renderer.rs | 40 +++++++++++++++++------------------ daemon/src/surface.rs | 15 +++++++------ daemon/src/wallpaper_info.rs | 4 ++-- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/daemon/src/config.rs b/daemon/src/config.rs index d640c48..47a3437 100644 --- a/daemon/src/config.rs +++ b/daemon/src/config.rs @@ -37,7 +37,7 @@ pub struct SerializedWallpaperInfo { pub sorting: Option, pub mode: Option, pub drawn_images_queue_size: Option, - pub animation_time: Option, + pub transition_time: Option, } impl SerializedWallpaperInfo { @@ -125,9 +125,9 @@ impl SerializedWallpaperInfo { (Some(size), _) | (None, Some(size)) => *size, (None, None) => ImagePicker::DEFAULT_DRAWN_IMAGES_QUEUE_SIZE, }; - let animation_time = match (&self.animation_time, &default.animation_time) { - (Some(animation_time), _) | (None, Some(animation_time)) => *animation_time, - (None, None) => Renderer::DEFAULT_ANIMATION_TIME, + let transition_time = match (&self.transition_time, &default.transition_time) { + (Some(transition_time), _) | (None, Some(transition_time)) => *transition_time, + (None, None) => Renderer::DEFAULT_TRANSITION_TIME, }; Ok(WallpaperInfo { @@ -137,7 +137,7 @@ impl SerializedWallpaperInfo { sorting, mode, drawn_images_queue_size, - animation_time, + transition_time, }) } } diff --git a/daemon/src/render/renderer.rs b/daemon/src/render/renderer.rs index 3b86c4b..fe7b85c 100644 --- a/daemon/src/render/renderer.rs +++ b/daemon/src/render/renderer.rs @@ -33,23 +33,23 @@ pub struct Renderer { vao: gl::types::GLuint, vbo: gl::types::GLuint, eab: gl::types::GLuint, - // milliseconds time for the animation - animation_time: u32, + // milliseconds time for the transition + transition_time: u32, pub time_started: u32, display_info: Rc>, old_wallpaper: Wallpaper, current_wallpaper: Wallpaper, transparent_texture: gl::types::GLuint, - animation_fit_changed: bool, + transition_fit_changed: bool, } impl Renderer { - pub const DEFAULT_ANIMATION_TIME: u32 = 300; + pub const DEFAULT_TRANSITION_TIME: u32 = 300; pub unsafe fn new( image: DynamicImage, display_info: Rc>, - animation_time: u32, + transition_time: u32, ) -> Result { let gl = gl::Gl::load_with(|name| { egl.get_proc_address(name).unwrap() as *const std::ffi::c_void @@ -101,12 +101,12 @@ impl Renderer { vbo, eab, time_started: 0, - animation_time, + transition_time, old_wallpaper, current_wallpaper, display_info, transparent_texture, - animation_fit_changed: false, + transition_fit_changed: false, }; renderer.load_wallpaper(image, BackgroundMode::Stretch)?; @@ -127,13 +127,13 @@ impl Renderer { self.check_error("clearing the screen")?; let mut progress = - ((time - self.time_started) as f32 / self.animation_time as f32).min(1.0); - let animation_going = progress != 1.0; + ((time - self.time_started) as f32 / self.transition_time as f32).min(1.0); + let transition_going = progress != 1.0; match mode { BackgroundMode::Stretch | BackgroundMode::Fill | BackgroundMode::Tile => {} BackgroundMode::Fit => { - if !self.animation_fit_changed && progress > 0.5 { + if !self.transition_fit_changed && progress > 0.5 { self.gl.ActiveTexture(gl::TEXTURE0); self.check_error("activating gl::TEXTURE0")?; self.gl @@ -142,11 +142,11 @@ impl Renderer { self.check_error("activating gl::TEXTURE0")?; self.current_wallpaper.bind(&self.gl)?; - self.animation_fit_changed = true; + self.transition_fit_changed = true; // This will recalculate the vertices self.set_mode(mode, true)?; } - if animation_going { + if transition_going { progress = (progress % 0.5) * 2.0; } } @@ -163,7 +163,7 @@ impl Renderer { .DrawElements(gl::TRIANGLES, 6, gl::UNSIGNED_INT, std::ptr::null()); self.check_error("drawing the triangles")?; - Ok(animation_going) + Ok(transition_going) } pub fn load_wallpaper(&mut self, image: DynamicImage, mode: BackgroundMode) -> Result<()> { @@ -182,7 +182,7 @@ impl Renderer { }, BackgroundMode::Fit => unsafe { // We don't change the vertices, we still use the previous ones for the first half - // of the animation + // of the transition self.gl.ActiveTexture(gl::TEXTURE0); self.check_error("activating gl::TEXTURE0")?; self.old_wallpaper.bind(&self.gl)?; @@ -199,7 +199,7 @@ impl Renderer { pub fn set_mode( &mut self, mode: BackgroundMode, - half_animation_for_fit_mode: bool, + half_transition_for_fit_mode: bool, ) -> Result<()> { match mode { BackgroundMode::Stretch | BackgroundMode::Fill | BackgroundMode::Tile => { @@ -223,7 +223,7 @@ impl Renderer { } } BackgroundMode::Fit => { - let vec_coordinates = if half_animation_for_fit_mode { + let vec_coordinates = if half_transition_for_fit_mode { self.current_wallpaper .generate_vertices_coordinates_for_fit_mode() } else { @@ -254,9 +254,9 @@ impl Renderer { } #[inline] - pub fn start_animation(&mut self, time: u32) { + pub fn start_transition(&mut self, time: u32) { self.time_started = time; - self.animation_fit_changed = false; + self.transition_fit_changed = false; } #[inline] @@ -284,8 +284,8 @@ impl Renderer { } #[inline] - pub fn update_animation_time(&mut self, animation_time: u32) { - self.animation_time = animation_time; + pub fn update_transition_time(&mut self, transition_time: u32) { + self.transition_time = transition_time; } } diff --git a/daemon/src/surface.rs b/daemon/src/surface.rs index b499d44..e308831 100644 --- a/daemon/src/surface.rs +++ b/daemon/src/surface.rs @@ -67,7 +67,8 @@ impl Surface { let image = black_image(); let info = Rc::new(RefCell::new(info)); let renderer = unsafe { - Renderer::new(image.into(), info.clone(), wallpaper_info.animation_time).unwrap() + Renderer::new(image.into(), info.clone(), wallpaper_info.transition_time) + .expect("unable to create the renderer") }; let mut surface = Self { @@ -108,11 +109,11 @@ impl Surface { let wallpaper_loaded = self.load_wallpaper(time)?; - let animation_going = unsafe { self.renderer.draw(time, self.wallpaper_info.mode)? }; + let transition_going = unsafe { self.renderer.draw(time, self.wallpaper_info.mode)? }; self.drawn = true; - if animation_going || !wallpaper_loaded { + if transition_going || !wallpaper_loaded { self.queue_draw(qh); } @@ -136,7 +137,7 @@ impl Surface { // Call surface::frame when this return false pub fn load_wallpaper(&mut self, time: u32) -> Result { Ok(loop { - // If we were already trying to load an image + // If we were not already trying to load an image if self.loading_image.is_none() { if let Some(item) = self .image_picker @@ -161,7 +162,7 @@ impl Surface { self.egl_context.make_current()?; self.renderer .load_wallpaper(data.into(), self.wallpaper_info.mode)?; - self.renderer.start_animation(time); + self.renderer.start_transition(time); self.image_picker.update_current_image(image_path, index); // Restart the counter self.loading_image_tries = 0; @@ -347,9 +348,9 @@ impl Surface { self.image_picker .update_queue_size(self.wallpaper_info.drawn_images_queue_size); } - if self.wallpaper_info.animation_time != wallpaper_info.animation_time { + if self.wallpaper_info.transition_time != wallpaper_info.transition_time { self.renderer - .update_animation_time(self.wallpaper_info.animation_time); + .update_transition_time(self.wallpaper_info.transition_time); } } } diff --git a/daemon/src/wallpaper_info.rs b/daemon/src/wallpaper_info.rs index 30141d3..59ffc46 100644 --- a/daemon/src/wallpaper_info.rs +++ b/daemon/src/wallpaper_info.rs @@ -12,7 +12,7 @@ pub struct WallpaperInfo { pub sorting: Sorting, pub mode: BackgroundMode, pub drawn_images_queue_size: usize, - pub animation_time: u32, + pub transition_time: u32, } impl Default for WallpaperInfo { @@ -24,7 +24,7 @@ impl Default for WallpaperInfo { sorting: Sorting::default(), mode: BackgroundMode::default(), drawn_images_queue_size: ImagePicker::DEFAULT_DRAWN_IMAGES_QUEUE_SIZE, - animation_time: Renderer::DEFAULT_ANIMATION_TIME, + transition_time: Renderer::DEFAULT_TRANSITION_TIME, } } }