From 9a8fd65cb0f110e0e851315d24e7e25d55a6fe85 Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 29 Nov 2019 23:05:54 +0530 Subject: add; configurable animations --- src/animations.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/animations.rs (limited to 'src') diff --git a/src/animations.rs b/src/animations.rs new file mode 100644 index 0000000..634986b --- /dev/null +++ b/src/animations.rs @@ -0,0 +1,48 @@ +use crate::IndicatorConfig; +use std::thread; +use std::time::Duration; + +pub struct Animation { + duration_per_frame: Duration, + frames: Vec, + clear: bool, +} + +impl Animation { + pub fn circles( + config: IndicatorConfig, + function: Box>, + clear: bool, + ) -> Animation { + let no_of_frames = config.framerate; + let duration_per_frame = + Duration::from_millis(config.duration).div_f64(no_of_frames as f64); + let frames = function + .map(|i| { + xcb::Arc::new( + ((config.max_size as f32) / (2. * no_of_frames as f32) * i as f32) as i16, // x + ((config.max_size as f32) / (2. * no_of_frames as f32) * i as f32) as i16, // y + (config.max_size) - (config.max_size / no_of_frames) * i as u16, // width + (config.max_size) - (config.max_size / no_of_frames) * i as u16, // height + 0, // start angle + 360 << 6, // end angle + ) + }) + .collect::>(); + return Animation { + duration_per_frame, + frames, + clear, + }; + } + pub fn play(&self, conn: &xcb::Connection, win: u32, gfx_ctx: u32) { + for frame in &self.frames { + xcb::poly_arc(&conn, win, gfx_ctx, &[*frame]); + conn.flush(); + if self.clear { + xcb::clear_area(&conn, true, win, frame.x(), frame.y(), 2000, 2000); + } + thread::sleep(self.duration_per_frame); + } + } +} -- cgit v1.2.3