2020-07-28 07:37:25 +00:00
|
|
|
use bevy_asset::{Assets, Handle};
|
2020-11-13 02:22:46 +00:00
|
|
|
use bevy_ecs::{Query, Res, With};
|
2020-07-28 07:37:25 +00:00
|
|
|
use bevy_math::Size;
|
|
|
|
use bevy_render::texture::Texture;
|
|
|
|
use bevy_sprite::ColorMaterial;
|
2020-12-27 19:19:03 +00:00
|
|
|
use bevy_text::CalculatedSize;
|
2020-07-28 07:37:25 +00:00
|
|
|
|
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>>,
|
2020-11-13 02:22:46 +00:00
|
|
|
mut query: Query<(&mut CalculatedSize, &Handle<ColorMaterial>), With<Image>>,
|
2020-07-28 07:37:25 +00:00
|
|
|
) {
|
2020-11-13 02:22:46 +00:00
|
|
|
for (mut calculated_size, material_handle) in query.iter_mut() {
|
2020-08-16 07:30:04 +00:00
|
|
|
if let Some(texture) = materials
|
2020-07-28 07:37:25 +00:00
|
|
|
.get(material_handle)
|
2020-10-18 20:48:15 +00:00
|
|
|
.and_then(|material| material.texture.as_ref())
|
|
|
|
.and_then(|texture_handle| textures.get(texture_handle))
|
2020-08-16 07:30:04 +00:00
|
|
|
{
|
|
|
|
calculated_size.size = Size {
|
2020-11-22 20:04:47 +00:00
|
|
|
width: texture.size.width as f32,
|
|
|
|
height: texture.size.height as f32,
|
2020-08-16 07:30:04 +00:00
|
|
|
};
|
|
|
|
}
|
2020-07-28 07:37:25 +00:00
|
|
|
}
|
|
|
|
}
|