2020-07-28 07:37:25 +00:00
|
|
|
use crate::CalculatedSize;
|
|
|
|
use bevy_asset::{Assets, Handle};
|
|
|
|
use bevy_ecs::{Query, Res};
|
|
|
|
use bevy_math::Size;
|
|
|
|
use bevy_render::texture::Texture;
|
|
|
|
use bevy_sprite::ColorMaterial;
|
|
|
|
|
2020-10-08 18:43:01 +00:00
|
|
|
#[derive(Debug, Clone)]
|
2020-07-28 07:37:25 +00:00
|
|
|
pub enum Image {
|
|
|
|
KeepAspect,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Image {
|
|
|
|
fn default() -> Self {
|
|
|
|
Image::KeepAspect
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn image_node_system(
|
|
|
|
materials: Res<Assets<ColorMaterial>>,
|
|
|
|
textures: Res<Assets<Texture>>,
|
|
|
|
mut query: Query<(&Image, &mut CalculatedSize, &Handle<ColorMaterial>)>,
|
|
|
|
) {
|
|
|
|
for (_image, mut calculated_size, material_handle) in &mut query.iter() {
|
2020-08-16 07:30:04 +00:00
|
|
|
if let Some(texture) = materials
|
2020-07-28 07:37:25 +00:00
|
|
|
.get(material_handle)
|
|
|
|
.and_then(|material| material.texture)
|
|
|
|
.and_then(|texture_handle| textures.get(&texture_handle))
|
2020-08-16 07:30:04 +00:00
|
|
|
{
|
|
|
|
calculated_size.size = Size {
|
|
|
|
width: texture.size.x(),
|
|
|
|
height: texture.size.y(),
|
|
|
|
};
|
|
|
|
}
|
2020-07-28 07:37:25 +00:00
|
|
|
}
|
|
|
|
}
|