Skip to content

Commit

Permalink
restore the return type of window's width and height function
Browse files Browse the repository at this point in the history
* add back `logical_width` & `logical_height` so that code that wants full
  precision still has access, updated several places in engine that wanted
  `f32` to use these.
  • Loading branch information
Nathan Jeffords committed Dec 7, 2020
1 parent 2e44163 commit 1d35220
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_render/src/camera/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn camera_system<T: CameraProjection + Component>(
for (entity, mut camera, mut camera_projection) in queries.q0_mut().iter_mut() {
if let Some(window) = windows.get(camera.window) {
if changed_window_ids.contains(&window.id()) || added_cameras.contains(&entity) {
camera_projection.update(window.width(), window.height());
camera_projection.update(window.logical_width(), window.logical_height());
camera.projection_matrix = camera_projection.get_projection_matrix();
camera.depth_calculation = camera_projection.depth_calculation();
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ui/src/flex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ impl FlexSurface {
*node,
stretch::style::Style {
size: stretch::geometry::Size {
width: stretch::style::Dimension::Points(window.width()),
height: stretch::style::Dimension::Points(window.height()),
width: stretch::style::Dimension::Points(window.logical_width()),
height: stretch::style::Dimension::Points(window.logical_height()),
},
..Default::default()
},
Expand Down
14 changes: 12 additions & 2 deletions crates/bevy_window/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,22 @@ impl Window {
}

#[inline]
pub fn width(&self) -> f32 {
pub fn width(&self) -> u32 {
self.logical_width() as u32
}

#[inline]
pub fn height(&self) -> u32 {
self.logical_height() as u32
}

#[inline]
pub fn logical_width(&self) -> f32 {
(self.physical_width as f64 / self.scale_factor) as f32
}

#[inline]
pub fn height(&self) -> f32 {
pub fn logical_height(&self) -> f32 {
(self.physical_height as f64 / self.scale_factor) as f32
}

Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ pub fn winit_runner(mut app: App) {
app.resources.get_mut::<Events<WindowResized>>().unwrap();
resize_events.send(WindowResized {
id: window_id,
height: window.height(),
width: window.width(),
height: window.logical_height(),
width: window.logical_width(),
});
}
WindowEvent::CloseRequested => {
Expand Down Expand Up @@ -313,7 +313,7 @@ pub fn winit_runner(mut app: App) {

// FIXME?: On Android window start is top while on PC/Linux/OSX on bottom
if cfg!(target_os = "android") {
let window_height = windows.get_primary().unwrap().height();
let window_height = windows.get_primary().unwrap().logical_height();
location.y = window_height - location.y;
}
touch_input_events.send(converters::convert_touch_input(touch, location));
Expand Down
8 changes: 4 additions & 4 deletions examples/2d/contributors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ fn collision_system(

let win = wins.get_primary().unwrap();

let ceiling = win.height() / 2.;
let ground = -(win.height() / 2.);
let ceiling = win.logical_height() / 2.;
let ground = -(win.logical_height() / 2.);

let wall_left = -(win.width() / 2.);
let wall_right = win.width() / 2.;
let wall_left = -(win.logical_width() / 2.);
let wall_right = win.logical_width() / 2.;

for (mut v, mut t) in q.iter_mut() {
let left = t.translation.x - SPRITE_SIZE / 2.0;
Expand Down
4 changes: 2 additions & 2 deletions examples/ecs/parallel_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ fn bounce_system(
mut sprites: Query<(&Transform, &mut Velocity)>,
) {
let window = windows.get_primary().expect("No primary window.");
let width = window.width();
let height = window.height();
let width = window.logical_width();
let height = window.logical_height();
let left = width / -2.0;
let right = width / 2.0;
let bottom = height / -2.0;
Expand Down

0 comments on commit 1d35220

Please sign in to comment.