Merge remains of screen into window

This commit is contained in:
Hanno Braun 2025-03-25 20:38:55 +01:00
parent f948e327ca
commit b07d5dd47c
7 changed files with 45 additions and 48 deletions

View File

@ -4,7 +4,7 @@ use std::f64::consts::FRAC_PI_2;
use fj_interop::TriMesh;
use fj_math::{Aabb, Point, Scalar, Transform, Vector};
use crate::screen::NormalizedScreenPosition;
use crate::window::NormalizedScreenPosition;
/// The camera abstraction
///

View File

@ -15,9 +15,8 @@ use winit::{
use crate::{
RendererInitError,
input::{DEFAULT_CAMERA_TUNING_CONFIG, InputEvent},
screen::ScreenSize,
viewer::ViewerWindow,
window::{self, Window},
window::{self, ScreenSize, Window},
};
/// # Display the provided mesh in a window that processes input

View File

@ -4,7 +4,10 @@ use thiserror::Error;
use tracing::{error, trace};
use wgpu::util::DeviceExt as _;
use crate::{camera::Camera, screen::ScreenSize, window::Window};
use crate::{
camera::Camera,
window::{ScreenSize, Window},
};
use super::{
DEPTH_FORMAT, DeviceError, SAMPLE_COUNT, device::Device,

View File

@ -13,7 +13,6 @@ mod camera;
mod display;
mod graphics;
mod input;
mod screen;
mod viewer;
mod window;

View File

@ -1,39 +0,0 @@
//! Types that describe aspects of the screen
/// Cursor position in normalized coordinates (-1 to +1)
///
/// The center of the screen is at (0, 0). The aspect ratio is taken into
/// account.
#[derive(Clone, Copy, Debug)]
pub struct NormalizedScreenPosition {
/// The x coordinate of the position [-1, 1]
pub x: f64,
/// The y coordinate of the position [-1, 1]
pub y: f64,
}
/// The size of the screen
#[derive(Clone, Copy, Debug)]
pub struct ScreenSize {
/// The width of the screen
pub width: u32,
/// The height of the screen
pub height: u32,
}
impl ScreenSize {
/// # Indicate whether the screen size is valid
///
/// A screen size is valid, if neither of its dimensions is zero. But it can
/// be reported as zero by spurious screen resize events.
pub fn is_valid(&self) -> bool {
self.width > 0 && self.height > 0
}
/// Convert size to `f64`
pub fn as_f64(&self) -> [f64; 2] {
[self.width, self.height].map(Into::into)
}
}

View File

@ -10,8 +10,7 @@ use crate::{
CameraTuningConfig, DEFAULT_CAMERA_TUNING_CONFIG, InputEvent,
MouseButton,
},
screen::{NormalizedScreenPosition, ScreenSize},
window::Window,
window::{NormalizedScreenPosition, ScreenSize, Window},
};
pub struct ViewerWindow {

View File

@ -2,8 +2,6 @@ use std::sync::Arc;
use winit::event_loop::ActiveEventLoop;
use crate::screen::ScreenSize;
/// A window that can be used with `fj-viewer`
pub struct Window {
inner: Arc<winit::window::Window>,
@ -63,3 +61,41 @@ impl Window {
#[derive(Debug, thiserror::Error)]
#[error("Error initializing window")]
pub struct WindowError(#[from] pub winit::error::OsError);
/// Cursor position in normalized coordinates (-1 to +1)
///
/// The center of the screen is at (0, 0). The aspect ratio is taken into
/// account.
#[derive(Clone, Copy, Debug)]
pub struct NormalizedScreenPosition {
/// The x coordinate of the position [-1, 1]
pub x: f64,
/// The y coordinate of the position [-1, 1]
pub y: f64,
}
/// The size of the screen
#[derive(Clone, Copy, Debug)]
pub struct ScreenSize {
/// The width of the screen
pub width: u32,
/// The height of the screen
pub height: u32,
}
impl ScreenSize {
/// # Indicate whether the screen size is valid
///
/// A screen size is valid, if neither of its dimensions is zero. But it can
/// be reported as zero by spurious screen resize events.
pub fn is_valid(&self) -> bool {
self.width > 0 && self.height > 0
}
/// Convert size to `f64`
pub fn as_f64(&self) -> [f64; 2] {
[self.width, self.height].map(Into::into)
}
}