2019-04-28 18:18:08 +00:00
|
|
|
use super::Graphic;
|
2019-05-07 05:40:03 +00:00
|
|
|
use common::assets::{load, Error};
|
2019-04-28 18:18:08 +00:00
|
|
|
use dot_vox::DotVoxData;
|
|
|
|
use image::DynamicImage;
|
|
|
|
|
2019-05-09 01:38:34 +00:00
|
|
|
pub enum BlankGraphic {}
|
|
|
|
pub enum ImageGraphic {}
|
2019-04-28 18:18:08 +00:00
|
|
|
|
|
|
|
pub trait GraphicCreator<'a> {
|
|
|
|
type Specifier;
|
|
|
|
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error>;
|
|
|
|
}
|
|
|
|
impl<'a> GraphicCreator<'a> for BlankGraphic {
|
|
|
|
type Specifier = ();
|
|
|
|
fn new_graphic(_: ()) -> Result<Graphic, Error> {
|
|
|
|
Ok(Graphic::Blank)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl<'a> GraphicCreator<'a> for ImageGraphic {
|
|
|
|
type Specifier = &'a str;
|
|
|
|
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> {
|
2019-05-07 05:40:03 +00:00
|
|
|
Ok(Graphic::Image(load::<DynamicImage>(specifier)?))
|
2019-04-28 18:18:08 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-09 01:38:34 +00:00
|
|
|
|
|
|
|
pub enum VoxelGraphic {}
|
|
|
|
pub enum VoxelMsGraphic {}
|
|
|
|
pub enum VoxelMs4Graphic {}
|
|
|
|
pub enum VoxelMs9Graphic {}
|
|
|
|
|
2019-04-28 18:18:08 +00:00
|
|
|
impl<'a> GraphicCreator<'a> for VoxelGraphic {
|
|
|
|
type Specifier = &'a str;
|
|
|
|
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> {
|
2019-05-09 01:38:34 +00:00
|
|
|
Ok(Graphic::Voxel(load::<DotVoxData>(specifier)?, None))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl<'a> GraphicCreator<'a> for VoxelMsGraphic {
|
|
|
|
type Specifier = (&'a str, u8);
|
|
|
|
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> {
|
|
|
|
Ok(Graphic::Voxel(
|
|
|
|
load::<DotVoxData>(specifier.0)?,
|
|
|
|
Some(specifier.1),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl<'a> GraphicCreator<'a> for VoxelMs4Graphic {
|
|
|
|
type Specifier = &'a str;
|
|
|
|
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> {
|
|
|
|
Ok(Graphic::Voxel(load::<DotVoxData>(specifier)?, Some(4)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl<'a> GraphicCreator<'a> for VoxelMs9Graphic {
|
|
|
|
type Specifier = &'a str;
|
|
|
|
fn new_graphic(specifier: Self::Specifier) -> Result<Graphic, Error> {
|
|
|
|
Ok(Graphic::Voxel(load::<DotVoxData>(specifier)?, Some(9)))
|
2019-04-28 18:18:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-26 03:30:46 +00:00
|
|
|
/// This macro will automatically load all specified assets, get the corresponding ImgIds and
|
2019-05-17 09:22:32 +00:00
|
|
|
/// create a struct with all of them.
|
2019-04-26 03:30:46 +00:00
|
|
|
///
|
|
|
|
/// Example usage:
|
|
|
|
/// ```
|
|
|
|
/// image_ids! {
|
2019-04-28 16:44:44 +00:00
|
|
|
/// pub struct Imgs {
|
2019-04-28 18:18:08 +00:00
|
|
|
/// <VoxelGraphic>
|
2019-04-26 03:30:46 +00:00
|
|
|
/// button1: "filename1.vox",
|
|
|
|
/// button2: "filename2.vox",
|
2019-04-28 16:44:44 +00:00
|
|
|
///
|
2019-04-28 18:18:08 +00:00
|
|
|
/// <ImageGraphic>
|
2019-04-26 03:30:46 +00:00
|
|
|
/// background: "background.png",
|
2019-05-07 05:40:03 +00:00
|
|
|
///
|
2019-04-28 18:18:08 +00:00
|
|
|
/// <BlankGraphic>
|
|
|
|
/// blank: (),
|
2019-04-26 03:30:46 +00:00
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! image_ids {
|
2019-04-28 16:44:44 +00:00
|
|
|
($($v:vis struct $Ids:ident { $( <$T:ty> $( $name:ident: $specifier:expr ),* $(,)? )* })*) => {
|
2019-04-26 03:30:46 +00:00
|
|
|
$(
|
|
|
|
$v struct $Ids {
|
2019-04-28 16:44:44 +00:00
|
|
|
$($( $v $name: conrod_core::image::Id, )*)*
|
2019-04-26 03:30:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl $Ids {
|
2019-04-28 04:44:13 +00:00
|
|
|
pub fn load(ui: &mut crate::ui::Ui) -> Result<Self, common::assets::Error> {
|
2019-05-09 01:38:34 +00:00
|
|
|
use crate::ui::img_ids::GraphicCreator;
|
2019-04-26 03:30:46 +00:00
|
|
|
Ok(Self {
|
2019-05-11 14:59:48 +00:00
|
|
|
$($( $name: ui.add_graphic(<$T as GraphicCreator>::new_graphic($specifier)?), )*)*
|
2019-04-26 03:30:46 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
};
|
2019-04-30 20:43:55 +00:00
|
|
|
}
|