Skip to content

Commit

Permalink
update Window's width & height methods to return f32
Browse files Browse the repository at this point in the history
also removes `logical_width` & `logical_height` as they are not longer different
  • Loading branch information
Nathan Jeffords committed Dec 9, 2020
1 parent c54179b commit e75d8fe
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 25 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.logical_width(), window.logical_height());
camera_projection.update(window.width(), window.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.logical_width()),
height: stretch::style::Dimension::Points(window.logical_height()),
width: stretch::style::Dimension::Points(window.width()),
height: stretch::style::Dimension::Points(window.height()),
},
..Default::default()
},
Expand Down
16 changes: 3 additions & 13 deletions crates/bevy_window/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,12 @@ impl Window {
}

#[inline]
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 {
pub fn width(&self) -> f32 {
(self.physical_width as f64 / self.scale_factor) as f32
}

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

Expand All @@ -161,7 +151,7 @@ impl Window {
.push(WindowCommand::SetMaximized { maximized });
}

pub fn set_resolution(&mut self, width: u32, height: u32) {
pub fn set_resolution(&mut self, width: f32, height: f32) {
self.physical_width = (width as f64 * self.scale_factor) as u32;
self.physical_height = (height as f64 * self.scale_factor) as u32;
self.command_queue.push(WindowCommand::SetResolution {
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 @@ -210,8 +210,8 @@ pub fn winit_runner(mut app: App) {
app.resources.get_mut::<Events<WindowResized>>().unwrap();
resize_events.send(WindowResized {
id: window_id,
height: window.logical_height(),
width: window.logical_width(),
height: window.height(),
width: window.width(),
});
}
WindowEvent::CloseRequested => {
Expand Down Expand Up @@ -309,7 +309,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().logical_height();
let window_height = windows.get_primary().unwrap().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.logical_height() / 2.;
let ground = -(win.logical_height() / 2.);
let ceiling = win.height() / 2.;
let ground = -(win.height() / 2.);

let wall_left = -(win.logical_width() / 2.);
let wall_right = win.logical_width() / 2.;
let wall_left = -(win.width() / 2.);
let wall_right = win.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.logical_width();
let height = window.logical_height();
let width = window.width();
let height = window.height();
let left = width / -2.0;
let right = width / 2.0;
let bottom = height / -2.0;
Expand Down

0 comments on commit e75d8fe

Please sign in to comment.