mirror of
https://github.com/Zenithsiz/zsw.git
synced 2026-02-03 17:52:15 +00:00
Window geometry is now checked every frame.
This commit is contained in:
parent
0f287775bf
commit
f902c6cf98
@ -208,8 +208,6 @@ impl WinitApp {
|
||||
let wgpu_renderer =
|
||||
WgpuRenderer::new(Arc::clone(&window), self.shared.wgpu).context("Unable to create wgpu renderer")?;
|
||||
|
||||
let window_geometry = app_window.window_geometry;
|
||||
|
||||
let msaa_samples = 4;
|
||||
let panels_renderer = PanelsRenderer::new(&wgpu_renderer, self.shared.wgpu, msaa_samples)
|
||||
.context("Unable to create panels renderer")?;
|
||||
@ -223,7 +221,6 @@ impl WinitApp {
|
||||
self::renderer(
|
||||
&shared,
|
||||
&window,
|
||||
window_geometry,
|
||||
wgpu_renderer,
|
||||
panels_renderer,
|
||||
egui_renderer,
|
||||
@ -311,7 +308,6 @@ where
|
||||
async fn renderer(
|
||||
shared: &Shared,
|
||||
window: &Window,
|
||||
window_geometry: Rect<i32, u32>,
|
||||
mut wgpu_renderer: WgpuRenderer,
|
||||
mut panels_renderer: PanelsRenderer,
|
||||
mut egui_renderer: EguiRenderer,
|
||||
@ -319,10 +315,13 @@ async fn renderer(
|
||||
mut settings_menu: SettingsMenu,
|
||||
) -> Result<(), AppError> {
|
||||
loop {
|
||||
// TODO: Only update this when we receive a move/resize event instead of querying each frame?
|
||||
let window_geometry = self::window_geometry(window)?;
|
||||
|
||||
// Paint egui
|
||||
// TODO: Have `egui_renderer` do this for us on render?
|
||||
let (egui_paint_jobs, egui_textures_delta) =
|
||||
match self::paint_egui(shared, window, window_geometry, &egui_painter, &mut settings_menu).await {
|
||||
match self::paint_egui(shared, window, &egui_painter, &mut settings_menu, window_geometry).await {
|
||||
Ok((paint_jobs, textures_delta)) => (paint_jobs, Some(textures_delta)),
|
||||
Err(err) => {
|
||||
tracing::warn!("Unable to draw egui: {}", err.pretty());
|
||||
@ -342,7 +341,7 @@ async fn renderer(
|
||||
&wgpu_renderer,
|
||||
shared.wgpu,
|
||||
&shared.panels_renderer_layouts,
|
||||
&window_geometry,
|
||||
window_geometry,
|
||||
window,
|
||||
&shared.panels,
|
||||
)
|
||||
@ -375,15 +374,15 @@ async fn renderer(
|
||||
async fn paint_egui(
|
||||
shared: &Shared,
|
||||
window: &Window,
|
||||
window_geometry: Rect<i32, u32>,
|
||||
egui_painter: &EguiPainter,
|
||||
settings_menu: &mut SettingsMenu,
|
||||
window_geometry: Rect<i32, u32>,
|
||||
) -> Result<(Vec<egui::ClippedPrimitive>, egui::TexturesDelta), AppError> {
|
||||
let full_output_fut = egui_painter.draw(window, async |ctx| {
|
||||
// Adjust cursor pos to account for the scale factor
|
||||
let scale_factor = window.scale_factor();
|
||||
let cursor_pos = shared.cursor_pos.load().cast::<f32>().to_logical(scale_factor);
|
||||
// Adjust cursor pos to account for the scale factor
|
||||
let scale_factor = window.scale_factor();
|
||||
let cursor_pos = shared.cursor_pos.load().cast::<f32>().to_logical(scale_factor);
|
||||
|
||||
let full_output_fut = egui_painter.draw(window, async |ctx| {
|
||||
// Draw the settings menu
|
||||
tokio::task::block_in_place(|| {
|
||||
settings_menu.draw(
|
||||
@ -408,7 +407,7 @@ async fn paint_egui(
|
||||
!panel
|
||||
.geometries
|
||||
.iter()
|
||||
.any(|geometry| geometry.geometry_on(&window_geometry).contains(cursor_pos))
|
||||
.any(|geometry| geometry.geometry_on(window_geometry).contains(cursor_pos))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -469,6 +468,16 @@ async fn paint_egui(
|
||||
Ok((paint_jobs, textures_delta))
|
||||
}
|
||||
|
||||
/// Gets the window geometry for a window
|
||||
fn window_geometry(window: &Window) -> Result<Rect<i32, u32>, AppError> {
|
||||
let window_pos = window.inner_position().context("Unable to get window position")?;
|
||||
let window_size = window.inner_size();
|
||||
Ok(Rect {
|
||||
pos: cgmath::point2(window_pos.x, window_pos.y),
|
||||
size: cgmath::vec2(window_size.width, window_size.height),
|
||||
})
|
||||
}
|
||||
|
||||
/// A resize
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Resize {
|
||||
|
||||
@ -41,7 +41,7 @@ impl PanelGeometry {
|
||||
}
|
||||
|
||||
/// Returns this geometry's rectangle for a certain window
|
||||
pub fn geometry_on(&self, window_geometry: &Rect<i32, u32>) -> Rect<i32, u32> {
|
||||
pub fn geometry_on(&self, window_geometry: Rect<i32, u32>) -> Rect<i32, u32> {
|
||||
let mut geometry = self.geometry;
|
||||
geometry.pos -= Vector2::new(window_geometry.pos.x, window_geometry.pos.y);
|
||||
|
||||
@ -52,7 +52,7 @@ impl PanelGeometry {
|
||||
// Note: This matrix simply goes from a geometry in physical units
|
||||
// onto shader coordinates.
|
||||
#[must_use]
|
||||
pub fn pos_matrix(&self, window_geometry: &Rect<i32, u32>, surface_size: PhysicalSize<u32>) -> Matrix4<f32> {
|
||||
pub fn pos_matrix(&self, window_geometry: Rect<i32, u32>, surface_size: PhysicalSize<u32>) -> Matrix4<f32> {
|
||||
let geometry = self.geometry_on(window_geometry);
|
||||
|
||||
let x_scale = geometry.size[0] as f32 / surface_size.width as f32;
|
||||
|
||||
@ -106,17 +106,14 @@ impl PanelsRenderer {
|
||||
}
|
||||
|
||||
/// Renders a panel
|
||||
#[expect(
|
||||
clippy::too_many_lines,
|
||||
reason = "TODO: Split it up"
|
||||
)]
|
||||
#[expect(clippy::too_many_lines, reason = "TODO: Split it up")]
|
||||
pub async fn render(
|
||||
&mut self,
|
||||
frame: &mut FrameRender,
|
||||
wgpu_renderer: &WgpuRenderer,
|
||||
wgpu_shared: &WgpuShared,
|
||||
layouts: &PanelsRendererLayouts,
|
||||
window_geometry: &Rect<i32, u32>,
|
||||
window_geometry: Rect<i32, u32>,
|
||||
window: &Window,
|
||||
panels: &Panels,
|
||||
) -> Result<(), AppError> {
|
||||
@ -264,7 +261,7 @@ impl PanelsRenderer {
|
||||
layouts: &PanelsRendererLayouts,
|
||||
surface_size: PhysicalSize<u32>,
|
||||
panel_state: &PanelState,
|
||||
window_geometry: &Rect<i32, u32>,
|
||||
window_geometry: Rect<i32, u32>,
|
||||
window: &Window,
|
||||
geometry: &mut PanelGeometry,
|
||||
render_pass: &mut wgpu::RenderPass<'_>,
|
||||
|
||||
@ -17,9 +17,6 @@ pub struct AppWindow {
|
||||
/// Monitor name
|
||||
pub _monitor_name: String,
|
||||
|
||||
/// Monitor geometry
|
||||
pub window_geometry: Rect<i32, u32>,
|
||||
|
||||
/// Window
|
||||
pub window: Window,
|
||||
}
|
||||
@ -56,7 +53,6 @@ pub fn create(event_loop: &ActiveEventLoop) -> Result<Vec<AppWindow>, AppError>
|
||||
|
||||
Ok(AppWindow {
|
||||
_monitor_name: monitor_name,
|
||||
window_geometry: monitor_geometry,
|
||||
window,
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user