storm/lib.rs
1#![no_std]
2#![allow(dead_code, non_camel_case_types, non_snake_case)]
3
4pub extern crate log;
5
6extern crate alloc;
7// TODO: Resolve when glow is fixed. They use standard HashSet >:(
8// #[cfg(any(test, not(target_arch = "wasm32")))]
9extern crate std;
10
11/// Asset utilities.
12pub mod asset;
13/// Audio primitives. Creating and controlling sounds are included in here.
14pub mod audio;
15/// Color primitives. These are used in the graphics and image modules for managing images and
16/// textures.
17pub mod color;
18/// Event utilities.
19pub mod event;
20/// Graphics primitives.
21pub mod graphics;
22/// Image utilities. Images are used for creating textures.
23pub mod image;
24/// Math utilities.
25pub mod math;
26/// Synchronization utilities.
27pub mod sync;
28/// Time utilities.
29pub mod time;
30
31mod engine;
32
33pub use cgmath;
34pub use engine::{start, Context};
35pub use fontdue;
36
37/// Type that holds all of your application state and handles events.
38pub trait App: 'static + Sized {
39 /// Function to create the app from a context.
40 /// # Arguments
41 ///
42 /// * `ctx` - The engine context. This can be used to call various API functions.
43 fn new(_ctx: &mut Context<Self>) -> Self;
44
45 /// This event is useful as a place to put your code that should be run after all state-changing
46 /// events have been handled and you want to do stuff (updating state, performing calculations,
47 /// etc) that happens as the "main body" of your event loop.
48 /// # Arguments
49 ///
50 /// * `ctx` - The engine context. This can be used to call various API functions.
51 /// * `delta` - The time passed since the last update in seconds.
52 fn on_update(&mut self, _ctx: &mut Context<Self>, _delta: f32) {}
53
54 /// The window has requested it close.
55 fn on_close_requested(&mut self, _ctx: &mut Context<Self>) {}
56
57 /// Received a character. This includes control characters.
58 /// # Arguments
59 ///
60 /// * `ctx` - The engine context. This can be used to call various API functions.
61 /// * `character` - The character typed.
62 fn on_received_character(&mut self, _ctx: &mut Context<Self>, _character: char) {}
63
64 /// Keyboard press event. Includes a flag for if this is a repeat event.
65 /// # Arguments
66 ///
67 /// * `ctx` - The engine context. This can be used to call various API functions.
68 /// * `key` - The button pressed.
69 /// * `is_repeat` - Flag for if this key was already pressed. Some environments may fire repeat
70 /// key pressed events when the key is held.
71 fn on_key_pressed(&mut self, _ctx: &mut Context<Self>, _key: event::KeyboardButton, _is_repeat: bool) {}
72
73 /// Keyboard release event.
74 /// # Arguments
75 ///
76 /// * `ctx` - The engine context. This can be used to call various API functions.
77 /// * `key` - The button released.
78 fn on_key_released(&mut self, _ctx: &mut Context<Self>, _key: event::KeyboardButton) {}
79
80 /// Cursor press event. Contains the button pressed and the position it was pressed at.
81 /// # Arguments
82 ///
83 /// * `ctx` - The engine context. This can be used to call various API functions.
84 /// * `button` - The button pressed.
85 /// * `physical_pos` - Cursor position at time of press. This is based on the physical size of
86 /// the window, with (0,0) being the bottom left.
87 /// * `normalized_pos` - Cursor position at time of press. This is normalized where the x and y
88 /// values are between -1 and 1, with the bottom left of the screen being (-1, -1), and the top
89 /// right being (1, 1). This may be useful for converting screen space coordinates into world
90 /// space.
91 fn on_cursor_pressed(
92 &mut self,
93 _ctx: &mut Context<Self>,
94 _button: event::CursorButton,
95 _physical_pos: cgmath::Vector2<f32>,
96 _normalized_pos: cgmath::Vector2<f32>,
97 ) {
98 }
99
100 /// Cursor press event. Contains the button pressed and the position it was pressed at.
101 /// # Arguments
102 ///
103 /// * `ctx` - The engine context. This can be used to call various API functions.
104 /// * `button` - The button released.
105 /// * `physical_pos` - Cursor position at time of release. This is base with (0,0) being the
106 /// bottom left.
107 /// * `normalized_pos` - Cursor position at time of release. This is normalized where the x and
108 /// y values are between -1 and 1, with the bottom left of the screen being (-1, -1), and the
109 /// top right being (1, 1). This may be useful for converting screen space coordinates into
110 /// world space.
111 fn on_cursor_released(
112 &mut self,
113 _ctx: &mut Context<Self>,
114 _button: event::CursorButton,
115 _physical_pos: cgmath::Vector2<f32>,
116 _normalized_pos: cgmath::Vector2<f32>,
117 ) {
118 }
119
120 /// Cursor wheel scroll event..
121 /// # Arguments
122 ///
123 /// * `ctx` - The engine context. This can be used to call various API functions.
124 /// * `direction` - The direction scrolled.
125 fn on_cursor_scroll(&mut self, _ctx: &mut Context<Self>, _direction: event::ScrollDirection) {}
126
127 /// Cursor moved event. Use this for interacting with UI. Contains the new position of the
128 /// cursor.
129 /// # Arguments
130 ///
131 /// * `ctx` - The engine context. This can be used to call various API functions.
132 /// * `physical_pos` - Current cursor position. This is based on the physical size of the
133 /// window, with (0,0) being the bottom left.
134 /// * `normalized_pos` - Current cursor position. This is normalized where the x and y values
135 /// are between -1 and 1, with the bottom left of the screen being (-1, -1), and the top right
136 /// being (1, 1). This may be useful for converting screen space coordinates into world space.
137 fn on_cursor_moved(
138 &mut self,
139 _ctx: &mut Context<Self>,
140 _physical_pos: cgmath::Vector2<f32>,
141 _normalized_pos: cgmath::Vector2<f32>,
142 ) {
143 }
144
145 /// Cursor delta event. Use this to control a 3D camera. Contains the represents raw, unfiltered
146 /// physical motion. Represents the change in physical position of the pointing device.
147 /// # Arguments
148 ///
149 /// * `ctx` - The engine context. This can be used to call various API functions.
150 /// * `delta` - Change from last position. The units are arbitrary and up to the device.
151 /// * `focused` - Flag for if the window is focused. This event may return deltas even when the
152 /// window is not focused.
153 fn on_cursor_delta(&mut self, _ctx: &mut Context<Self>, _delta: cgmath::Vector2<f32>, _focused: bool) {}
154
155 /// Cursor left the bounds of the window event.
156 fn on_cursor_left(&mut self, _ctx: &mut Context<Self>) {}
157
158 /// Cursor entered the bounds of the window event.
159 fn on_cursor_entered(&mut self, _ctx: &mut Context<Self>) {}
160
161 /// Window resized event. Contains the new dimensions of the window.
162 /// # Arguments
163 ///
164 /// * `ctx` - The engine context. This can be used to call various API functions.
165 /// * `physical_size` - The size of the viewport.
166 /// * `logical_size` - The logical size of the viewport. This is derived from the physical_size
167 /// divided by the scale_factor.
168 /// * `scale_factor` - The window's scale factor. This is a multiplier between the physical size
169 /// and logical size of the window.
170 fn on_window_resized(
171 &mut self,
172 _ctx: &mut Context<Self>,
173 _physical_size: cgmath::Vector2<f32>,
174 _logical_size: cgmath::Vector2<f32>,
175 _scale_factor: f32,
176 ) {
177 }
178
179 /// The window gained or lost focus.
180 /// # Arguments
181 ///
182 /// * `ctx` - The engine context. This can be used to call various API functions.
183 /// * `focused` - The parameter is true if the window has gained focus, and false if it has lost focus.
184 fn on_window_focused(&mut self, _ctx: &mut Context<Self>, _focused: bool) {}
185}