You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//! A Rust library for tracking key/mouse press events from windows for use in update loops
3
+
//! A Piston library for tracking key/mouse press events
4
+
//! from windows for use in update loops
5
5
6
6
externcrate input;
7
7
8
8
use input::Button;
9
9
use std::collections::HashMap;
10
10
11
-
12
-
/// Master struct for the button controller. Consumes button data from any source (though most commonly window event loop generated press events) and tracks them in an update loop friendly form.
11
+
/// Master struct for the button controller.
12
+
/// Consumes button data from any source
13
+
/// (though most commonly window event loop generated press events)
14
+
/// and tracks them in an update loop friendly form.
13
15
#[derive(Clone)]
14
16
pubstructButtonController{
15
17
current_buttons:HashMap<Button,bool>,
16
18
last_buttons:HashMap<Button,bool>,
17
19
}
18
20
19
21
implButtonController{
20
-
21
22
/// Creates a new ButtonController.
22
23
pubfnnew() -> ButtonController{
23
24
ButtonController{
@@ -26,24 +27,31 @@ impl ButtonController {
26
27
}
27
28
}
28
29
29
-
/// Copies the current input state into the last known button state. Call this in your update loop logic, once per update.
30
+
/// Copies the current input state into the last known button state.
31
+
/// Call this in your update loop logic, once per update.
30
32
pubfnupdate(&mutself){
31
33
for(button, state)in&self.current_buttons{
32
34
self.last_buttons.insert(*button,*state);
33
35
}
34
36
}
35
37
36
-
/// Tracks that a button is currently pressed. The most common way to do so is passing in Button contents from PressEvents generated from your relevant window class.
38
+
/// Tracks that a button is currently pressed.
39
+
/// The most common way to do so is passing in Button contents
40
+
/// from PressEvents generated from your relevant window class.
37
41
pubfnregister_press(&mutself,button:&Button){
38
42
self.current_buttons.insert(*button,true);
39
43
}
40
44
41
-
/// Tracks that a button is currently un-pressed (or notes that a previously pressed button is now not pressed). The most common way to do so is passing in Button contents from ReleaseEvents generated from your relevant window class.
45
+
/// Tracks that a button is currently un-pressed
46
+
/// (or notes that a previously pressed button is now not pressed).
47
+
/// The most common way to do so is passing in Button contents
48
+
/// from ReleaseEvents generated from your relevant window class.
42
49
pubfnregister_release(&mutself,button:&Button){
43
50
self.current_buttons.insert(*button,false);
44
51
}
45
52
46
-
/// Checks if a button is pressed as of the current update. Will return false if a button has never been registered as pressed.
53
+
/// Checks if a button is pressed as of the current update.
54
+
/// Will return false if a button has never been registered as pressed.
/// Checks for a combination of a button press/release across the current and last update. Most useful for determining whether a button was just pressed or released.
0 commit comments