diff --git a/crates/notedeck/src/imgcache.rs b/crates/notedeck/src/imgcache.rs index 86d789a5..3cb3a8d3 100644 --- a/crates/notedeck/src/imgcache.rs +++ b/crates/notedeck/src/imgcache.rs @@ -7,6 +7,7 @@ use egui::ColorImage; use std::collections::HashMap; use std::fs::{create_dir_all, File}; +use std::sync::mpsc::Receiver; use std::time::{Duration, Instant, SystemTime}; use hex::ToHex; @@ -20,6 +21,37 @@ pub type MediaCacheMap = HashMap; pub enum TexturedImage { Static(TextureHandle), + Animated(Animation), +} + +pub struct Animation { + pub first_frame: TextureFrame, + pub other_frames: Vec, + pub receiver: Option>, +} + +impl Animation { + pub fn get_frame(&self, index: usize) -> Option<&TextureFrame> { + if index == 0 { + Some(&self.first_frame) + } else { + self.other_frames.get(index - 1) + } + } + + pub fn num_frames(&self) -> usize { + self.other_frames.len() + 1 + } +} + +pub struct TextureFrame { + pub delay: Duration, + pub texture: TextureHandle, +} + +pub struct ImageFrame { + pub delay: Duration, + pub image: ColorImage, } pub struct MediaCache { @@ -146,6 +178,7 @@ impl MediaCache { pub fn get_texture(textured_image: &TexturedImage) -> &TextureHandle { match textured_image { TexturedImage::Static(texture_handle) => texture_handle, + TexturedImage::Animated(_animation) => todo!(), // Temporary... } }