Skip to content

Commit

Permalink
Rename animation to transition
Browse files Browse the repository at this point in the history
  • Loading branch information
danyspin97 committed Apr 15, 2024
1 parent 8f1555c commit eb0422c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 34 deletions.
10 changes: 5 additions & 5 deletions daemon/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct SerializedWallpaperInfo {
pub sorting: Option<Sorting>,
pub mode: Option<BackgroundMode>,
pub drawn_images_queue_size: Option<usize>,
pub animation_time: Option<u32>,
pub transition_time: Option<u32>,
}

impl SerializedWallpaperInfo {
Expand Down Expand Up @@ -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 {
Expand All @@ -137,7 +137,7 @@ impl SerializedWallpaperInfo {
sorting,
mode,
drawn_images_queue_size,
animation_time,
transition_time,
})
}
}
Expand Down
40 changes: 20 additions & 20 deletions daemon/src/render/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RefCell<DisplayInfo>>,
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<RefCell<DisplayInfo>>,
animation_time: u32,
transition_time: u32,
) -> Result<Self> {
let gl = gl::Gl::load_with(|name| {
egl.get_proc_address(name).unwrap() as *const std::ffi::c_void
Expand Down Expand Up @@ -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)?;
Expand All @@ -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
Expand All @@ -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;
}
}
Expand All @@ -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<()> {
Expand All @@ -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)?;
Expand All @@ -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 => {
Expand All @@ -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 {
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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;
}
}

Expand Down
15 changes: 8 additions & 7 deletions daemon/src/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}

Expand All @@ -136,7 +137,7 @@ impl Surface {
// Call surface::frame when this return false
pub fn load_wallpaper(&mut self, time: u32) -> Result<bool> {
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
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions daemon/src/wallpaper_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
}
}
Expand Down

0 comments on commit eb0422c

Please sign in to comment.