Skip to content

Commit d56013b

Browse files
committed
ch
1 parent 856202c commit d56013b

5 files changed

Lines changed: 85 additions & 9 deletions

File tree

crates/processing_glfw/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,19 @@ impl GlfwContext {
300300
WindowEvent::Focus(focused) => {
301301
input_set_focus(surface, focused).unwrap();
302302
}
303+
WindowEvent::Size(width, height) => {
304+
let scale = self.content_scale();
305+
let logical_w = ((width as f32) / scale).max(1.0) as i32;
306+
let logical_h = ((height as f32) / scale).max(1.0) as i32;
307+
if logical_w != width || logical_h != height {
308+
// processing_render::surface_resize(
309+
// surface,
310+
// logical_w as u32,
311+
// logical_h as u32,
312+
// )
313+
// .unwrap();
314+
}
315+
}
303316
_ => {}
304317
}
305318
}

crates/processing_pyo3/src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use graphics::{
3434
};
3535
use material::Material;
3636

37+
use processing_render::surface_logical_width;
3738
use pyo3::{
3839
BoundObject,
3940
exceptions::PyRuntimeError,
@@ -120,13 +121,14 @@ pub(crate) fn reset_tracked_globals() {
120121
fn sync_globals(module: &Bound<'_, PyModule>, globals: &Bound<'_, PyAny>) -> PyResult<()> {
121122
let graphics =
122123
get_graphics(module)?.ok_or_else(|| PyRuntimeError::new_err("call size() first"))?;
123-
input::sync_globals(
124-
globals,
125-
graphics.surface.entity,
126-
graphics.width,
127-
graphics.height,
128-
)?;
129-
surface::sync_globals(globals, &graphics.surface, graphics.width, graphics.height)?;
124+
// let width = ::processing::prelude::surface_logical_width(graphics.surface.entity)
125+
// .map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
126+
// let height = ::processing::prelude::surface_logical_height(graphics.surface.entity)
127+
// .map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
128+
let width = graphics.width;
129+
let height = graphics.height;
130+
input::sync_globals(globals, graphics.surface.entity, width, height)?;
131+
surface::sync_globals(globals, &graphics.surface, width, height)?;
130132
time::sync_globals(globals)?;
131133
Ok(())
132134
}

crates/processing_render/src/graphics.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ impl CameraProjection for ProcessingProjection {
118118
// this gets called with the render target's physical dimensions (i.e. accounting for
119119
// scale factor), but our projection is in logical pixel units
120120
// TODO: handle resizes?
121+
// self.width = _width;
122+
// self.height = _height;
121123
}
122124

123125
fn far(&self) -> f32 {

crates/processing_render/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,24 @@ pub fn surface_physical_height(entity: Entity) -> error::Result<u32> {
17021702
})
17031703
}
17041704

1705+
pub fn surface_logical_width(entity: Entity) -> error::Result<u32> {
1706+
app_mut(|app| {
1707+
Ok(app
1708+
.world_mut()
1709+
.run_system_cached_with(surface::logical_width, entity)
1710+
.unwrap())
1711+
})
1712+
}
1713+
1714+
pub fn surface_logical_height(entity: Entity) -> error::Result<u32> {
1715+
app_mut(|app| {
1716+
Ok(app
1717+
.world_mut()
1718+
.run_system_cached_with(surface::logical_height, entity)
1719+
.unwrap())
1720+
})
1721+
}
1722+
17051723
pub fn monitor_list() -> error::Result<Vec<Entity>> {
17061724
app_mut(|app| Ok(app.world_mut().run_system_cached(monitor::list).unwrap()))
17071725
}

crates/processing_render/src/surface.rs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
use bevy::{
2222
app::{App, Plugin},
2323
asset::Assets,
24+
camera::{CameraProjection, 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
};
3334
use raw_window_handle::{
@@ -39,7 +40,10 @@ use processing_core::error::{self, ProcessingError, Result};
3940
#[cfg(not(target_os = "windows"))]
4041
use std::ptr::NonNull;
4142

42-
use crate::image::Image;
43+
use crate::{
44+
graphics::{ProcessingProjection, SurfaceSize},
45+
image::Image,
46+
};
4347

4448
#[derive(Component, Debug, Clone)]
4549
pub struct Surface;
@@ -394,7 +398,19 @@ pub fn destroy(
394398
pub fn resize(
395399
In((window_entity, width, height)): In<(Entity, u32, u32)>,
396400
mut windows: Query<&mut Window>,
401+
mut graphics_query: Query<(&RenderTarget, &mut SurfaceSize, &mut Projection)>,
397402
) -> Result<()> {
403+
let width = width.max(1);
404+
let height = height.max(1);
405+
406+
// let Ok(window) = windows.get_mut(window_entity) else {
407+
// return Ok(());
408+
// };
409+
//
410+
// if window.mode != WindowMode::Windowed {
411+
// return Ok(());
412+
// }
413+
398414
if let Ok(mut window) = windows.get_mut(window_entity) {
399415
let scale = window.resolution.scale_factor();
400416
let physical_w = (width as f32 * scale) as u32;
@@ -403,6 +419,17 @@ pub fn resize(
403419
.resolution
404420
.set_physical_resolution(physical_w, physical_h);
405421
}
422+
423+
// for (target, mut surface_size, mut projection) in graphics_query.iter_mut() {
424+
// if let RenderTarget::Window(WindowRef::Entity(surface)) = *target {
425+
// if surface == window_entity {
426+
// *surface_size = SurfaceSize(width, height);
427+
// if let Projection::Custom(ref mut custom) = *projection {
428+
// custom.update(width as f32, height as f32);
429+
// }
430+
// }
431+
// }
432+
// }
406433
Ok(())
407434
}
408435

@@ -448,6 +475,20 @@ pub fn physical_height(In(entity): In<Entity>, query: Query<&Window>) -> u32 {
448475
.unwrap_or(0)
449476
}
450477

478+
pub fn logical_width(In(entity): In<Entity>, query: Query<&Window>) -> u32 {
479+
query
480+
.get(entity)
481+
.map(|w| w.resolution.width() as u32)
482+
.unwrap_or(0)
483+
}
484+
485+
pub fn logical_height(In(entity): In<Entity>, query: Query<&Window>) -> u32 {
486+
query
487+
.get(entity)
488+
.map(|w| w.resolution.height() as u32)
489+
.unwrap_or(0)
490+
}
491+
451492
pub fn set_title(
452493
In((entity, title)): In<(Entity, String)>,
453494
mut windows: Query<&mut Window>,

0 commit comments

Comments
 (0)