#[cfg(feature = "keycodes")]
#[cfg(all(feature = "svg", feature = "system"))]
#[cfg(feature = "std")]
pub use mouse::Cursor;
#[cfg(feature = "std")]
pub mod windowing;
#[cfg(feature = "std")]
#[deprecated(note = "Replace `glfw` with `framework::glfw` instead ")]
#[cfg(feature = "glfw")]
#[cfg(not(target_arch = "wasm32"))]
pub use windowing::glfw;
#[deprecated(note = "Replace `minifb` with `framework::minifb` instead")]
#[cfg(feature = "minifb")]
#[cfg(not(target_arch = "wasm32"))]
pub use windowing::minifb;
#[deprecated(
note = "Replace `framework_traits` with `windowing::traits` instead"
)]
#[cfg(feature = "std")]
#[cfg(feature = "system")]
pub use windowing::traits as framework_traits;
#[allow(clippy::non_minimal_cfg)]
#[cfg(all(
//feature = "svg",
// feature = "system",
//feature = "keycodes",
feature = "std"
))]
pub mod mouse;
#[cfg(feature = "std")]
pub mod file_system;
pub mod shared;
pub mod time;
#[cfg(feature = "system")]
#[cfg(feature = "keycodes")]
#[cfg(feature = "keyboard_query")]
pub mod keyboard;
#[cfg(feature = "system")]
#[cfg(feature = "std")]
use crate::extensions::*;
use crate::math::NumberWithMonotoneOps;
#[cfg(feature = "std")]
use crate::prelude::Buffer;
pub const trait Time {
fn get_elapsed_time(&self) -> f64;
}
#[cfg_attr(all(feature = "strum"), derive(strum::EnumIter))]
#[cfg_attr(all(feature = "enum_ext"), enum_ext::enum_extend)]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "c_compatible", repr(C))]
pub enum CursorStyle {
Default,
HandOpen,
HandClosed,
Alias,
AllScroll,
ArrowBottomLeft,
ArrowBottomRight,
SideBottom,
Cell,
CenteredPointer,
ResizeHorizontally,
ColorPicker,
ContextMenu,
Copy,
Crosshair,
HandClosedNoDrop,
ArrowDown,
Draft,
Fleur,
Help,
ArrowLeft,
SideLeft,
NoDrop,
NotAllowed,
Pencil,
Pirate,
Pointer,
ArrowRight,
MirroredPointer,
SideRight,
ResizeNESW,
ResizeNWSE,
SizeHor,
ResizeVertically,
Text,
ArrowTopLeft,
ArrowTopRight,
SideTop,
ArrowUp,
VerticalText,
ZoomIn,
ZoomOut,
}
#[cfg_attr(all(feature = "strum"), derive(strum::EnumIter))]
#[cfg_attr(all(feature = "enum_ext"), enum_ext::enum_extend)]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "c_compatible", repr(C))]
pub enum MouseButton {
Left,
Right,
Middle,
Extra1,
Extra2,
Extra3,
Extra4,
Unsupported,
}
pub mod keycodes;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[allow(clippy::struct_excessive_bools)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "c_compatible", repr(C))]
pub struct WindowSettings {
pub borderless: bool,
pub title_visible: bool,
pub window_level: WindowLevel,
pub position: (i32, i32),
pub size: (i32, i32),
pub resizable: bool,
pub os_menu: bool,
pub visible: bool,
}
#[cfg(feature = "system")]
#[cfg(feature = "std")]
impl WindowSettings {
#[must_use]
#[cfg(any(
target_arch = "wasm32",
target_os = "linux",
target_os = "windows"
))]
pub fn default(buffer: &Buffer) -> Self {
let size =
(buffer.width, buffer.height).try_tuple_into().unwrap_or_default();
Self {
borderless: false,
title_visible: true,
window_level: WindowLevel::Normal,
position: crate::system::get_center_of_screen_for_object(
size.0, size.1,
),
resizable: false,
os_menu: true,
size,
visible: true,
}
}
#[must_use]
pub const fn set_visible(mut self, visible: bool) -> Self {
self.visible = visible;
self
}
#[must_use]
pub const fn set_size(mut self, size: (i32, i32)) -> Self {
self.size = size;
self
}
#[must_use]
pub fn set_size_to_buffer(mut self, buffer: &Buffer) -> Self {
self.size =
(buffer.width, buffer.height).try_tuple_into().unwrap_or_default();
self
}
#[must_use]
pub const fn set_position(mut self, position: (i32, i32)) -> Self {
self.position = position;
self
}
#[must_use]
pub const fn set_title_visible(mut self, title: bool) -> Self {
self.title_visible = title;
self
}
#[must_use]
pub const fn set_borderless(mut self, borderless: bool) -> Self {
self.borderless = borderless;
self
}
#[must_use]
pub const fn set_window_level(mut self, window_level: WindowLevel) -> Self {
self.window_level = window_level;
self
}
#[must_use]
pub const fn set_resizable(mut self, resizable: bool) -> Self {
self.resizable = resizable;
self
}
#[must_use]
pub const fn set_os_menu(mut self, os_menu: bool) -> Self {
self.os_menu = os_menu;
self
}
#[must_use]
#[cfg(any(
target_arch = "wasm32",
target_os = "linux",
target_os = "windows"
))]
pub fn center_window(mut self) -> Self {
self.position = crate::system::get_center_of_screen_for_object(
self.size.0,
self.size.1,
);
self
}
#[must_use]
pub const fn multiply_size(mut self, by: i32) -> Self {
self.size = self.size.mul((by, by));
self
}
#[cfg(any(
target_arch = "wasm32",
target_os = "linux",
target_os = "windows"
))]
#[must_use]
pub fn fullscreen(mut self) -> Self {
use crate::system::action::Screen;
self.size = {
use crate::misc::EasyUnwrapUnchecked;
crate::system::Os::get_screen_resolution()
.try_tuple_into()
.easy_unwrap_unchecked()
};
self
}
}
#[cfg_attr(all(feature = "strum"), derive(strum::EnumIter))]
#[cfg_attr(all(feature = "enum_ext"), enum_ext::enum_extend)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[derive(PartialEq, Copy, Clone, Debug, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "c_compatible", repr(C))]
pub enum WindowLevel {
AlwaysOnBottom,
Normal,
AlwaysOnTop,
}
#[derive(Debug)]
#[cfg(feature = "std")]
#[cfg_attr(feature = "c_compatible", repr(C))]
pub struct DoubleBuffer {
front: Buffer,
back: Buffer,
front_is_back: std::sync::atomic::AtomicBool, }
#[cfg(feature = "std")]
impl DoubleBuffer {
#[must_use]
pub fn new(width: usize, height: usize) -> Self {
Self {
front: Buffer::new_empty((width, height)),
back: Buffer::new_empty((width, height)),
front_is_back: std::sync::atomic::AtomicBool::new(false),
}
}
pub fn read(&self) -> &Buffer {
if self.front_is_back.load(std::sync::atomic::Ordering::Acquire) {
&self.back
} else {
&self.front
}
}
pub fn write(&mut self, new_data: Buffer) {
if self.front_is_back.load(std::sync::atomic::Ordering::Acquire) {
self.front = new_data;
self.front_is_back
.store(false, std::sync::atomic::Ordering::Release);
} else {
self.back = new_data;
self.front_is_back
.store(true, std::sync::atomic::Ordering::Release);
}
}
}
use crate::prelude::{IntoPatch, TryIntoPatch};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "c_compatible", repr(C))]
pub struct ScreenNormalizer<S> {
screen_width: S,
screen_height: S,
}
impl<S: Copy + NumberWithMonotoneOps> ScreenNormalizer<S> {
pub const fn new(screen_size: (S, S)) -> Self {
Self {
screen_width: screen_size.0,
screen_height: screen_size.1,
}
}
pub fn try_percentile_to_x<T>(&self, p: S) -> Option<T>
where
S: TryIntoPatch<T>,
{
(p * self.screen_width).try_into_value()
}
pub fn try_percentile_to_y<T>(&self, p: S) -> Option<T>
where
S: TryIntoPatch<T>,
{
(p * self.screen_height).try_into_value()
}
pub fn try_percentile_to_xy<T>(&self, pxy: (S, S)) -> Option<(T, T)>
where
S: TryIntoPatch<T>,
{
let x = (pxy.0 * self.screen_width).try_into_value()?;
let y = (pxy.1 * self.screen_height).try_into_value()?;
Some((x, y))
}
pub fn try_x_to_percentile<T: TryIntoPatch<S>>(&self, x: T) -> Option<S> {
if let Some(value) = (x).try_into_value() {
return Some(value / self.screen_width);
}
core::intrinsics::cold_path();
None
}
pub fn try_y_to_percentile<T: TryIntoPatch<S>>(&self, y: T) -> Option<S> {
if let Some(value) = y.try_into_value() {
return Some(value / self.screen_height);
}
core::intrinsics::cold_path();
None
}
pub fn percentile_to_x<T>(&self, p: S) -> T
where
S: IntoPatch<T>,
{
(p * self.screen_width).into_value()
}
pub fn percentile_to_y<T>(&self, p: S) -> T
where
S: IntoPatch<T>,
{
(p * self.screen_height).into_value()
}
pub fn percentile_to_xy<T>(&self, pxy: (S, S)) -> (T, T)
where
S: IntoPatch<T>,
{
let x = (pxy.0 * self.screen_width).into_value();
let y = (pxy.1 * self.screen_height).into_value();
(x, y)
}
pub fn x_to_percentile<T: IntoPatch<S>>(&self, x: T) -> S {
(x).into_value() / self.screen_width
}
pub fn y_to_percentile<T: IntoPatch<S>>(&self, y: T) -> S {
y.into_value() / self.screen_height
}
}