Skip to content

Commit 987f4be

Browse files
authored
Merge pull request #7 from bvssvni/master
Published 0.1.0
2 parents 7d03d35 + 1d79bed commit 987f4be

File tree

5 files changed

+37
-66
lines changed

5 files changed

+37
-66
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99

1010
# Generated by Cargo
1111
/target/
12+
13+
Cargo.lock

Cargo.lock

Lines changed: 0 additions & 49 deletions
This file was deleted.

Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ version = "0.1.0"
44
authors = [
55
"Sean Hagar <rcix2010@gmail.com>"
66
]
7-
keywords = ["key", "button", "controller", "mouse", "press"]
8-
description = "A Rust library for tracking key/mouse press events from windows for use in update loops"
7+
keywords = ["key", "button", "tracker", "mouse", "piston"]
8+
description = "A Piston library for tracking key/mouse press events from windows for use in update loops"
9+
license = "MIT"
10+
repository = "https://github.com/PistonDevelopers/button_tracker.git"
11+
homepage = "https://github.com/PistonDevelopers/button_tracker"
912

1013
[lib]
1114
name = "button_tracker"
1215
path = "src/lib.rs"
1316

1417
[dependencies.pistoncore-input]
15-
version = "*"
18+
version = "0.17.0"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# button_tracker
2-
A Rust library for tracking key/mouse press events from windows for use in update loops
2+
A Piston library for tracking key/mouse press events from windows for use in update loops

src/lib.rs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
#![deny(missing_docs)]
22

3-
4-
//! 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
55
66
extern crate input;
77

88
use input::Button;
99
use std::collections::HashMap;
1010

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.
1315
#[derive(Clone)]
1416
pub struct ButtonController {
1517
current_buttons: HashMap<Button, bool>,
1618
last_buttons: HashMap<Button, bool>,
1719
}
1820

1921
impl ButtonController {
20-
2122
/// Creates a new ButtonController.
2223
pub fn new() -> ButtonController {
2324
ButtonController {
@@ -26,24 +27,31 @@ impl ButtonController {
2627
}
2728
}
2829

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.
3032
pub fn update(&mut self) {
3133
for (button, state) in &self.current_buttons {
3234
self.last_buttons.insert(*button, *state);
3335
}
3436
}
3537

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.
3741
pub fn register_press(&mut self, button: &Button) {
3842
self.current_buttons.insert(*button, true);
3943
}
4044

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.
4249
pub fn register_release(&mut self, button: &Button) {
4350
self.current_buttons.insert(*button, false);
4451
}
4552

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.
4755
pub fn current_pressed(&mut self, button: &Button) -> bool {
4856
if let Some(state) = self.current_buttons.get(button) {
4957
*state
@@ -52,7 +60,8 @@ impl ButtonController {
5260
}
5361
}
5462

55-
/// Checks if a button is pressed as of the last update. Will return false if a button has never been registered as pressed.
63+
/// Checks if a button is pressed as of the last update.
64+
/// Will return false if a button has never been registered as pressed.
5665
pub fn last_pressed(&mut self, button: &Button) -> bool {
5766
if let Some(state) = self.last_buttons.get(button) {
5867
*state
@@ -61,9 +70,15 @@ impl ButtonController {
6170
}
6271
}
6372

64-
/// 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.
65-
pub fn pressed_state(&mut self, button: &Button, last_state: bool, current_state: bool) -> bool {
73+
/// Checks for a combination of a button press/release across
74+
/// the current and last update.
75+
/// Most useful for determining whether a button was just pressed
76+
/// or released.
77+
pub fn pressed_state(&mut self,
78+
button: &Button,
79+
last_state: bool,
80+
current_state: bool)
81+
-> bool {
6682
self.last_pressed(button) == last_state && self.current_pressed(button) == current_state
6783
}
68-
6984
}

0 commit comments

Comments
 (0)