use crate::format_option;
use crate::resources::storage::{BorrowedStringStorage, OwnedStringStorage, StringStorage};
use crate::v2_0::appearance::{ImageType, RGBA, TextureType, WrapMode};
use std::fmt::{Display, Formatter};
pub type OwnedTexture = Texture<OwnedStringStorage>;
pub type BorrowedTexture<'a> = Texture<BorrowedStringStorage<'a>>;
#[derive(Clone, Default, Debug, PartialEq)]
pub struct Texture<SS: StringStorage> {
image_type: ImageType,
image: SS::String,
wrap_mode: Option<WrapMode>,
mapping_type: Option<TextureType>,
border_color: Option<RGBA>,
}
impl<SS: StringStorage> Texture<SS> {
#[inline]
pub fn new(image: SS::String, image_type: ImageType) -> Self {
Self {
image_type,
image,
wrap_mode: None,
mapping_type: None,
border_color: None,
}
}
#[inline]
pub fn image_type(&self) -> &ImageType {
&self.image_type
}
#[inline]
pub fn set_image_type(&mut self, image_type: ImageType) {
self.image_type = image_type;
}
#[inline]
pub fn image(&self) -> &SS::String {
&self.image
}
#[inline]
pub fn set_image(&mut self, image: SS::String) {
self.image = image;
}
#[inline]
pub fn wrap_mode(&self) -> Option<WrapMode> {
self.wrap_mode
}
#[inline]
pub fn set_wrap_mode(&mut self, wrap_mode: Option<WrapMode>) {
self.wrap_mode = wrap_mode;
}
#[inline]
pub fn texture_type(&self) -> Option<TextureType> {
self.mapping_type
}
#[inline]
pub fn set_texture_type(&mut self, texture_type: Option<TextureType>) {
self.mapping_type = texture_type;
}
#[inline]
pub fn border_color(&self) -> Option<RGBA> {
self.border_color
}
#[inline]
pub fn set_border_color(&mut self, border_color: Option<RGBA>) {
self.border_color = border_color;
}
}
impl<SS: StringStorage> Display for Texture<SS> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"image_type: {:?}, image: {:?}, wrap_mode: {}, mapping_type: {}, border_color: {}",
self.image_type,
self.image,
format_option(self.wrap_mode.as_ref()),
format_option(self.mapping_type.as_ref()),
format_option(self.border_color.as_ref())
)
}
}