introduce gif animation
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -7,6 +7,7 @@ use egui::ColorImage;
|
|||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs::{create_dir_all, File};
|
use std::fs::{create_dir_all, File};
|
||||||
|
use std::sync::mpsc::Receiver;
|
||||||
use std::time::{Duration, Instant, SystemTime};
|
use std::time::{Duration, Instant, SystemTime};
|
||||||
|
|
||||||
use hex::ToHex;
|
use hex::ToHex;
|
||||||
@@ -20,6 +21,37 @@ pub type MediaCacheMap = HashMap<String, MediaCacheValue>;
|
|||||||
|
|
||||||
pub enum TexturedImage {
|
pub enum TexturedImage {
|
||||||
Static(TextureHandle),
|
Static(TextureHandle),
|
||||||
|
Animated(Animation),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Animation {
|
||||||
|
pub first_frame: TextureFrame,
|
||||||
|
pub other_frames: Vec<TextureFrame>,
|
||||||
|
pub receiver: Option<Receiver<TextureFrame>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
pub struct MediaCache {
|
||||||
@@ -146,6 +178,7 @@ impl MediaCache {
|
|||||||
pub fn get_texture(textured_image: &TexturedImage) -> &TextureHandle {
|
pub fn get_texture(textured_image: &TexturedImage) -> &TextureHandle {
|
||||||
match textured_image {
|
match textured_image {
|
||||||
TexturedImage::Static(texture_handle) => texture_handle,
|
TexturedImage::Static(texture_handle) => texture_handle,
|
||||||
|
TexturedImage::Animated(_animation) => todo!(), // Temporary...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user