storm/graphics/window/mod.rs
1#[cfg(not(target_arch = "wasm32"))]
2#[path = "platform/native.rs"]
3mod native;
4#[cfg(not(target_arch = "wasm32"))]
5pub use self::native::OpenGLWindow;
6
7#[cfg(target_arch = "wasm32")]
8#[path = "platform/wasm.rs"]
9mod wasm;
10#[cfg(target_arch = "wasm32")]
11pub use self::wasm::OpenGLWindow;
12
13mod display_mode;
14mod window_settings;
15
16pub use display_mode::{DisplayMode, Vsync};
17pub use window_settings::WindowSettings;
18
19use cgmath::Vector2;
20use winit::event_loop::EventLoop;
21
22pub(crate) trait OpenGLWindowContract: Sized {
23 fn new(desc: &WindowSettings, event_loop: &EventLoop<()>) -> (Self, glow::Context);
24
25 /// Gets the scale factor of the window. This is related to DPI scaling.
26 fn scale_factor(&self) -> f32;
27
28 /// Gets the logical size of the window. This may differ from the viewport's logical size.
29 fn logical_size(&self) -> Vector2<f32>;
30
31 /// Gets the physical size of the window. This may differ from the viewport's physical size.
32 fn physical_size(&self) -> Vector2<f32>;
33
34 /// Grabs the cursor, preventing it from leaving the window.
35 ///
36 /// ## Platform-specific
37 ///
38 /// - **macOS:** This locks the cursor in a fixed location, which looks visually awkward.
39 fn set_cursor_grab(&self, grab: bool);
40
41 /// Sets the visibility of the cursor.
42 ///
43 /// ## Platform-specific
44 ///
45 /// - **Windows:** The cursor is only hidden within the confines of the window.
46 /// - **X11:** The cursor is only hidden within the confines of the window.
47 /// - **Wayland:** The cursor is only hidden within the confines of the window.
48 /// - **macOS:** The cursor is hidden as long as the window has input focus, even if the cursor is
49 /// outside of the window.
50 fn set_cursor_visible(&self, grab: bool);
51
52 /// Sets the title of the window.
53 ///
54 /// ## Platform-specific
55 ///
56 /// - **Web:** This sets the page title.
57 fn set_title(&self, title: &str);
58
59 /// Sets the display mode of the window.
60 fn set_display_mode(&self, display_mode: DisplayMode);
61
62 /// Swaps the buffers in case of double or triple buffering. You should call this function every
63 /// time you have finished rendering, or the image may not be displayed on the screen.
64 ///
65 /// ## Platform-specific
66 ///
67 /// - **Web:** This is a no-op.
68 fn swap_buffers(&self);
69}