-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab2add6
commit 3e1378d
Showing
6 changed files
with
167 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use bevy_ecs::component::Component; | ||
use bevy_ecs::prelude::ReflectComponent; | ||
use bevy_math::{IVec2, UVec2}; | ||
use bevy_reflect::Reflect; | ||
|
||
#[cfg(feature = "serialize")] | ||
use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; | ||
|
||
/// Represents a monitor attached to the system, which can be used to create windows. | ||
/// | ||
/// This component is synchronized with `winit` through `bevy_winit`, but is effectively | ||
/// read-only as `winit` does not support changing monitor properties. | ||
#[derive(Component, Debug, Clone, Reflect)] | ||
#[cfg_attr( | ||
feature = "serialize", | ||
derive(serde::Serialize, serde::Deserialize), | ||
reflect(Serialize, Deserialize) | ||
)] | ||
#[reflect(Component)] | ||
pub struct Monitor { | ||
/// The name of the monitor | ||
pub name: Option<String>, | ||
/// The height of the monitor in physical pixels | ||
pub physical_height: u32, | ||
/// The width of the monitor in physical pixels | ||
pub physical_width: u32, | ||
/// The position of the monitor in physical pixels | ||
pub physical_position: IVec2, | ||
/// The refresh rate of the monitor in millihertz | ||
pub refresh_rate_millihertz: Option<u32>, | ||
/// The scale factor of the monitor | ||
pub scale_factor: f64, | ||
/// The video modes that the monitor supports | ||
pub video_modes: Vec<VideoMode>, | ||
} | ||
|
||
/// A marker component for the primary monitor | ||
#[derive(Component, Debug, Clone, Reflect)] | ||
#[reflect(Component)] | ||
pub struct PrimaryMonitor; | ||
|
||
impl Monitor { | ||
/// Returns the physical size of the monitor in pixels | ||
pub fn physical_size(&self) -> UVec2 { | ||
UVec2::new(self.physical_width, self.physical_height) | ||
} | ||
} | ||
|
||
/// Represents a video mode that a monitor supports | ||
#[derive(Debug, Clone, Reflect)] | ||
#[cfg_attr( | ||
feature = "serialize", | ||
derive(serde::Serialize, serde::Deserialize), | ||
reflect(Serialize, Deserialize) | ||
)] | ||
pub struct VideoMode { | ||
/// The resolution of the video mode | ||
pub physical_size: UVec2, | ||
/// The bit depth of the video mode | ||
pub bit_depth: u16, | ||
/// The refresh rate in millihertz | ||
pub refresh_rate_millihertz: u32, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use winit::monitor::MonitorHandle; | ||
|
||
use bevy_ecs::entity::Entity; | ||
use bevy_ecs::system::Resource; | ||
|
||
/// Stores [`winit`] monitors and their corresponding entities | ||
#[derive(Resource, Debug, Default)] | ||
pub struct WinitMonitors { | ||
/// Stores [`winit`] monitors and their corresponding entities | ||
// we can't use a `HashMap` here because `MonitorHandle` doesn't implement `Hash` :( | ||
pub monitors: Vec<(MonitorHandle, Entity)>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters