fn user_interface_system(
    cam_query: Query<(
        &mut OrthographicProjection,
        &mut Transform,
        &mut Camera,
        &mut VisibleEntities,
    )>,
    mut transform_query: Query<&mut Transform, (With<Sprite>, Without<Camera>)>,
    mouse_state: Res<Input<MouseButton>>,
    mut motion_evr: EventReader<MouseMotion>,
    mut wheel_evr: EventReader<MouseWheel>,
) {
    // handle zooming when the user scrolls
    for event in wheel_evr.iter() {
        cam_query.for_each_mut(|(mut ortho, _transform, mut camera, mut entities)| {
            // filter out extraneous cameras
            if camera.name != Some(bevy::render::render_graph::base::camera::CAMERA_2D.to_string())
            {
                return;
            }

            const ZOOM_SPEED: f32 = 0.1;
            let scale_difference = (10.0 as f32).powf(event.y as f32 * ZOOM_SPEED);

            // adjust camera scaling
            ortho.far += (1000.0 / (0.1 * event.y)).abs();
            ortho.scale *= scale_difference;
            camera.projection_matrix = ortho.get_projection_matrix();

            // scale visible entities
            for e in entities.value.iter_mut() {
                match transform_query.get_component_mut::<Transform>(e.entity) {
                    Ok(mut t) => {
                        t.scale *= Vec3::ONE * scale_difference;
                    }
                    Err(_) => (),
                };
            }
        });
    }

    // handle paning when the user middle clicks and drags
    cam_query.for_each_mut(|(op, mut t, c, _e)| {
        // make sure we are using the right camera
        if c.name != Some(bevy::render::render_graph::base::camera::CAMERA_2D.to_string()) {
            return;
        }

        if mouse_state.pressed(MouseButton::Middle) {
            motion_evr
                .iter()
                .for_each(|m| t.translation += op.scale * Vec3::new(-m.delta.x, m.delta.y, 0.0));
        }
    })
}
/// :SYSTEM: Allows the user to scroll, pan, and zoom the display.
///
/// Note: zooming does
/// not visually scale visible entities, because the display is more of a map than a camera.
/// because of the vast distances of outer space, sprites would be way to small to see if they
/// zoomed to scale.
:SYSTEM: Allows the user to scroll, pan, and zoom the display.
Note: zooming does
not visually scale visible entities, because the display is more of a map than a camera.
because of the vast distances of outer space, sprites would be way to small to see if they
zoomed to scale.
: SYSTEM : Allows the user to scroll pan and zoom the display . Note : zooming does not visually scale visible entities because the display is more of a map than a camera . because of the vast distances of outer space sprites would be way to small to see if they zoomed to scale .
fn user_interface_system(
    cam_query: Query<(
        &mut OrthographicProjection,
        &mut Transform,
        &mut Camera,
        &mut VisibleEntities,
    )>,
    mut transform_query: Query<&mut Transform, (With<Sprite>, Without<Camera>)>,
    mouse_state: Res<Input<MouseButton>>,
    mut motion_evr: EventReader<MouseMotion>,
    mut wheel_evr: EventReader<MouseWheel>,
) {
    // handle zooming when the user scrolls
    for event in wheel_evr.iter() {
        cam_query.for_each_mut(|(mut ortho, _transform, mut camera, mut entities)| {
            // filter out extraneous cameras
            if camera.name != Some(bevy::render::render_graph::base::camera::CAMERA_2D.to_string())
            {
                return;
            }
            const ZOOM_SPEED: f32 = 0.1;
            let scale_difference = (10.0 as f32).powf(event.y as f32 * ZOOM_SPEED);
            // adjust camera scaling
            ortho.far += (1000.0 / (0.1 * event.y)).abs();
            ortho.scale *= scale_difference;
            camera.projection_matrix = ortho.get_projection_matrix();
            // scale visible entities
            for e in entities.value.iter_mut() {
                match transform_query.get_component_mut::<Transform>(e.entity) {
                    Ok(mut t) => {
                        t.scale *= Vec3::ONE * scale_difference;
                    }
                    Err(_) => (),
                };
            }
        });
    }
    // handle paning when the user middle clicks and drags
    cam_query.for_each_mut(|(op, mut t, c, _e)| {
        // make sure we are using the right camera
        if c.name != Some(bevy::render::render_graph::base::camera::CAMERA_2D.to_string()) {
            return;
        }
        if mouse_state.pressed(MouseButton::Middle) {
            motion_evr
                .iter()
                .for_each(|m| t.translation += op.scale * Vec3::new(-m.delta.x, m.delta.y, 0.0));
        }
    })
}
fn user_interface_system ( cam_query : Query < ( & mut OrthographicProjection , & mut Transform , & mut Camera , & mut VisibleEntities , ) > , mut transform_query : Query < & mut Transform , ( With < Sprite > , Without < Camera > ) > , mouse_state : Res < Input < MouseButton > > , mut motion_evr : EventReader < MouseMotion > , mut wheel_evr : EventReader < MouseWheel > , ) { // handle zooming when the user scrolls for event in wheel_evr . iter ( ) { cam_query . for_each_mut ( | ( mut ortho , _transform , mut camera , mut entities ) | { // filter out extraneous cameras if camera . name != Some ( bevy :: render :: render_graph :: base :: camera :: CAMERA_2D . to_string ( ) ) { return ; } const ZOOM_SPEED : f32 = 0.1 ; let scale_difference = ( 10.0 as f32 ) . powf ( event . y as f32 * ZOOM_SPEED ) ; // adjust camera scaling ortho . far += ( 1000.0 / ( 0.1 * event . y ) ) . abs ( ) ; ortho . scale *= scale_difference ; camera . projection_matrix = ortho . get_projection_matrix ( ) ; // scale visible entities for e in entities . value . iter_mut ( ) { match transform_query . get_component_mut :: < Transform > ( e . entity ) { Ok ( mut t ) => { t . scale *= Vec3 :: ONE * scale_difference ; } Err ( _ ) => ( ) , } ; } } ) ; } // handle paning when the user middle clicks and drags cam_query . for_each_mut ( | ( op , mut t , c , _e ) | { // make sure we are using the right camera if c . name != Some ( bevy :: render :: render_graph :: base :: camera :: CAMERA_2D . to_string ( ) ) { return ; } if mouse_state . pressed ( MouseButton :: Middle ) { motion_evr . iter ( ) . for_each ( | m | t . translation += op . scale * Vec3 :: new ( - m . delta . x , m . delta . y , 0.0 ) ) ; } } ) }
:SYSTEM: Allows the user to scroll, pan, and zoom the display.
: SYSTEM : Allows the user to scroll pan and zoom the display .
cam_query
Query<(
        &mut OrthographicProjection,
        &mut Transform,
        &mut Camera,
        &mut VisibleEntities,
    )>
transform_query
Query<&mut Transform, (With<Sprite>, Without<Camera>)>
mouse_state
Res<Input<MouseButton>>
motion_evr
EventReader<MouseMotion>
wheel_evr
EventReader<MouseWheel>
cam_query
Query<(
        &mut OrthographicProjection,
        &mut Transform,
        &mut Camera,
        &mut VisibleEntities,
    )>
transform_query
Query<&mut Transform, (With<Sprite>, Without<Camera>)>
mouse_state
Res<Input<MouseButton>>
motion_evr
EventReader<MouseMotion>
wheel_evr
EventReader<MouseWheel>