2121use bevy:: {
2222 app:: { App , Plugin } ,
2323 asset:: Assets ,
24+ camera:: { Projection , RenderTarget } ,
2425 ecs:: query:: QueryEntityError ,
2526 math:: { IRect , IVec2 } ,
2627 prelude:: { Commands , Component , Entity , In , Query , ResMut , Window , With , default} ,
2728 render:: render_resource:: { Extent3d , TextureFormat } ,
2829 window:: {
2930 CompositeAlphaMode , Monitor , RawHandleWrapper , WindowLevel , WindowMode , WindowPosition ,
30- WindowResolution , WindowWrapper ,
31+ WindowRef , WindowResolution , WindowWrapper ,
3132 } ,
3233} ;
3334use raw_window_handle:: {
@@ -39,7 +40,7 @@ use processing_core::error::{self, ProcessingError, Result};
3940#[ cfg( not( target_os = "windows" ) ) ]
4041use std:: ptr:: NonNull ;
4142
42- use crate :: image:: Image ;
43+ use crate :: { graphics :: SurfaceSize , image:: Image } ;
4344
4445#[ derive( Component , Debug , Clone ) ]
4546pub struct Surface ;
@@ -394,6 +395,7 @@ pub fn destroy(
394395pub fn resize (
395396 In ( ( window_entity, width, height) ) : In < ( Entity , u32 , u32 ) > ,
396397 mut windows : Query < & mut Window > ,
398+ mut graphics_query : Query < ( & RenderTarget , & mut SurfaceSize , & mut Projection ) > ,
397399) -> Result < ( ) > {
398400 if let Ok ( mut window) = windows. get_mut ( window_entity) {
399401 let scale = window. resolution . scale_factor ( ) ;
@@ -403,6 +405,17 @@ pub fn resize(
403405 . resolution
404406 . set_physical_resolution ( physical_w, physical_h) ;
405407 }
408+
409+ for ( target, mut surface_size, mut projection) in graphics_query. iter_mut ( ) {
410+ if let RenderTarget :: Window ( WindowRef :: Entity ( surface) ) = * target {
411+ if surface == window_entity {
412+ * surface_size = SurfaceSize ( width, height) ;
413+ if let Projection :: Custom ( ref mut custom) = * projection {
414+ custom. update ( width as f32 , height as f32 ) ;
415+ }
416+ }
417+ }
418+ }
406419 Ok ( ( ) )
407420}
408421
@@ -448,6 +461,20 @@ pub fn physical_height(In(entity): In<Entity>, query: Query<&Window>) -> u32 {
448461 . unwrap_or ( 0 )
449462}
450463
464+ pub fn width ( In ( entity) : In < Entity > , query : Query < & Window > ) -> u32 {
465+ query
466+ . get ( entity)
467+ . map ( |w| w. resolution . width ( ) as u32 )
468+ . unwrap_or ( 0 )
469+ }
470+
471+ pub fn height ( In ( entity) : In < Entity > , query : Query < & Window > ) -> u32 {
472+ query
473+ . get ( entity)
474+ . map ( |w| w. resolution . height ( ) as u32 )
475+ . unwrap_or ( 0 )
476+ }
477+
451478pub fn set_title (
452479 In ( ( entity, title) ) : In < ( Entity , String ) > ,
453480 mut windows : Query < & mut Window > ,
0 commit comments