pub struct Window {
pub handle: PWindow,
pub events: GlfwReceiver<(f64, WindowEvent)>,
/* private fields */
}
Expand description
It’s just a simple GLFW window holder with custom basic input system.
§Example
use tinystorm::window::{WindowBuilder};
let mut window = WindowBuilder::default()
.with_size(800, 600)
.with_title("My Window")
.with_vsync(false)
.with_max_fps(144 * 5)
.with_msaa(4)
.build();
while window.is_running() {
window.poll_events();
// Render your scene here
window.swap_buffers();
}
Fields§
§handle: PWindow
GLFW window handle you can use for more precise control of your application.
events: GlfwReceiver<(f64, WindowEvent)>
Current frame events you can use like a custom event handler. Updated only after Self::poll_events is called.
Implementations§
Source§impl Window
impl Window
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Is window still running. Primarily used in the main game loop.
§Example
while window.is_running() { ... }
Sourcepub fn poll_events(&mut self)
pub fn poll_events(&mut self)
Handles events in current frame. Please call it at the frame start to avoid input lag.
§Example
while window.is_running() {
window.poll_events();
...
}
Sourcepub fn swap_buffers(&mut self)
pub fn swap_buffers(&mut self)
Swaps front framebuffer with back that scene was rendered on. Please call it at the frame end to avoid input lag.
§Example
while window.is_running() {
...
window.swap_buffers();
}
Sourcepub fn set_position(&mut self, x: i32, y: i32)
pub fn set_position(&mut self, x: i32, y: i32)
Sets window position in pixels from top-left corner
Sourcepub fn set_height(&mut self, value: i32)
pub fn set_height(&mut self, value: i32)
Sets window height in pixels
Sourcepub fn grab_mouse(&mut self)
pub fn grab_mouse(&mut self)
Hides mouse and keeps it at the window center. Used primarily for first-person games where you don’t want to see the cursor.
Sourcepub fn release_mouse(&mut self)
pub fn release_mouse(&mut self)
Shows mouse back and releases it from the window center. Used primarily for first-person games. For example, when you want to show a menu and release the mouse back.
Sourcepub fn toggle_mouse(&mut self)
pub fn toggle_mouse(&mut self)
Changes mouse state to grabbed/released. If mouse is grabbed - it would be released, else - it would be grabbed.
Sourcepub fn is_key_pressed(&self, key: Key) -> bool
pub fn is_key_pressed(&self, key: Key) -> bool
Checks if specific key is pressed.
§Example
use tinystorm::{window::WindowBuilder, glfw::Key};
let mut window = WindowBuilder::default().build();
while window.is_running() {
window.poll_events();
// If key is pressed it would print "Key A is pressed!",
// and it would print that each frame until key is released.
if window.is_key_pressed(Key::A) {
println!("Key A is pressed!");
}
window.swap_buffers();
}
Sourcepub fn is_key_just_pressed(&self, key: Key) -> bool
pub fn is_key_just_pressed(&self, key: Key) -> bool
Checks if specific key is just pressed.
§Example
use tinystorm::{window::WindowBuilder, glfw::Key};
let mut window = WindowBuilder::default().build();
while window.is_running() {
window.poll_events();
// If key was just pressed at this frame it would print "Key B is just pressed!",
// but on next frame it wouldn't trigger.
//
// Used primarily when you want to check if key is just clicked,
// but not pressed for a certain time.
if window.is_key_just_pressed(Key::B) {
println!("Key B is just pressed!");
}
window.swap_buffers();
}
Checks if specific mouse button is pressed.
§Example
use tinystorm::{window::WindowBuilder, glfw::MouseButton};
let mut window = WindowBuilder::default().build();
while window.is_running() {
window.poll_events();
// If mouse button is pressed it would print "Left mouse button is pressed!",
// and it would print that each frame until mouse button is released.
if window.is_mouse_button_pressed(MouseButton::Left) {
println!("Left mouse button is pressed!");
}
window.swap_buffers();
}
Checks if specific mouse button is just pressed.
§Example
use tinystorm::{window::WindowBuilder, glfw::MouseButton};
let mut window = WindowBuilder::default().build();
while window.is_running() {
window.poll_events();
// If mouse button was just pressed at this frame it would print "Middle mouse button is just pressed!",
// but on next frame it wouldn't trigger.
//
// Used primarily when you want to check if mouse button is just clicked,
// but not pressed for a certain time.
if window.is_mouse_button_just_pressed(MouseButton::Middle) {
println!("Middle mouse button is just pressed!");
}
window.swap_buffers();
}
Sourcepub fn get_mouse_x(&self) -> f32
pub fn get_mouse_x(&self) -> f32
Gets mouse cursor X position in pixels from top-left corner relative to window.
Sourcepub fn get_mouse_y(&self) -> f32
pub fn get_mouse_y(&self) -> f32
Gets mouse cursor Y position in pixels from top-left corner relative to window.
Sourcepub fn get_mouse_dx(&self) -> f32
pub fn get_mouse_dx(&self) -> f32
Gets mouse cursor delta X position in pixels from top-left corner. It represents a horizontal mouse cursor movement in current frame.
Sourcepub fn get_mouse_dy(&self) -> f32
pub fn get_mouse_dy(&self) -> f32
Gets mouse cursor delta Y position in pixels from top-left corner. It represents a vertical mouse cursor movement in current frame.
Sourcepub fn get_height(&self) -> u32
pub fn get_height(&self) -> u32
Gets window height in pixels.
Sourcepub fn get_aspect(&self) -> f32
pub fn get_aspect(&self) -> f32
Gets window aspect ratio. Formula: window.get_width() as f32 / window.get_height() as f32
Sourcepub fn get_delta_raw(&self) -> Duration
pub fn get_delta_raw(&self) -> Duration
Gets delta time between last and current frames as Duration so you can get it in any format you want. It’s used primarily for physics calculation, player movement or animations that are time-related.
Sourcepub fn get_delta(&self) -> f32
pub fn get_delta(&self) -> f32
Gets delta time between last and current frames in seconds. It’s used primarily for physics calculation, player movement or animations that are time-related.
Sourcepub fn is_mouse_grabbed(&self) -> bool
pub fn is_mouse_grabbed(&self) -> bool
Returns if mouse is grabbed (it means it’s hidden and moved to window center, primarily used for first-person games) or released.
Sourcepub fn close(&mut self)
pub fn close(&mut self)
Turn off the window prematurely. (It would just make Window::is_running() false)
Auto Trait Implementations§
impl Freeze for Window
impl RefUnwindSafe for Window
impl !Send for Window
impl !Sync for Window
impl Unpin for Window
impl UnwindSafe for Window
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.