mirror of
https://github.com/italicsjenga/rust_minifb.git
synced 2025-01-27 19:16:34 +11:00
Added Window.is_key_released (#62)
* Added Window.is_key_released * Add is_key_released for the other platforms
This commit is contained in:
parent
6137568ef5
commit
3aaf613edd
6 changed files with 37 additions and 0 deletions
|
@ -8,6 +8,7 @@ pub struct KeyHandler {
|
||||||
prev_time: f64,
|
prev_time: f64,
|
||||||
delta_time: f32,
|
delta_time: f32,
|
||||||
keys: [bool; 512],
|
keys: [bool; 512],
|
||||||
|
keys_prev: [bool; 512],
|
||||||
keys_down_duration: [f32; 512],
|
keys_down_duration: [f32; 512],
|
||||||
key_repeat_delay: f32,
|
key_repeat_delay: f32,
|
||||||
key_repeat_rate: f32,
|
key_repeat_rate: f32,
|
||||||
|
@ -18,6 +19,7 @@ impl KeyHandler {
|
||||||
KeyHandler {
|
KeyHandler {
|
||||||
key_callback: None,
|
key_callback: None,
|
||||||
keys: [false; 512],
|
keys: [false; 512],
|
||||||
|
keys_prev: [false; 512],
|
||||||
keys_down_duration: [-1.0; 512],
|
keys_down_duration: [-1.0; 512],
|
||||||
prev_time: time::precise_time_s(),
|
prev_time: time::precise_time_s(),
|
||||||
delta_time: 0.0,
|
delta_time: 0.0,
|
||||||
|
@ -64,6 +66,7 @@ impl KeyHandler {
|
||||||
} else {
|
} else {
|
||||||
self.keys_down_duration[i] = -1.0;
|
self.keys_down_duration[i] = -1.0;
|
||||||
}
|
}
|
||||||
|
self.keys_prev[i] = self.keys[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +126,14 @@ impl KeyHandler {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn is_key_pressed(&self, key: Key, repeat: KeyRepeat) -> bool {
|
pub fn is_key_pressed(&self, key: Key, repeat: KeyRepeat) -> bool {
|
||||||
return Self::key_pressed(self, key as usize, repeat);
|
return Self::key_pressed(self, key as usize, repeat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn is_key_released(&self, key: Key) -> bool {
|
||||||
|
let idx = key as usize;
|
||||||
|
return self.keys_prev[idx] && !self.keys[idx];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -462,6 +462,14 @@ impl Window {
|
||||||
self.0.is_key_pressed(key, repeat)
|
self.0.is_key_pressed(key, repeat)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Check if a single key was released since last call to update.
|
||||||
|
///
|
||||||
|
#[inline]
|
||||||
|
pub fn is_key_released(&self, key: Key) -> bool {
|
||||||
|
self.0.is_key_released(key)
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Sets the delay for when a key is being held before it starts being repeated the default
|
/// Sets the delay for when a key is being held before it starts being repeated the default
|
||||||
/// value is 0.25 sec
|
/// value is 0.25 sec
|
||||||
|
|
|
@ -420,6 +420,11 @@ impl Window {
|
||||||
self.key_handler.is_key_pressed(key, repeat)
|
self.key_handler.is_key_pressed(key, repeat)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn is_key_released(&self, key: Key) -> bool {
|
||||||
|
self.key_handler.is_key_released(key)
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_input_callback(&mut self, callback: Box<InputCallback>) {
|
pub fn set_input_callback(&mut self, callback: Box<InputCallback>) {
|
||||||
self.key_handler.set_input_callback(callback)
|
self.key_handler.set_input_callback(callback)
|
||||||
|
|
|
@ -202,6 +202,10 @@ impl Window {
|
||||||
self.key_handler.is_key_pressed(key, repeat)
|
self.key_handler.is_key_pressed(key, repeat)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_key_released(&self, key: Key) -> bool {
|
||||||
|
self.key_handler.is_key_released(key)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_input_callback(&mut self, callback: Box<InputCallback>) {
|
pub fn set_input_callback(&mut self, callback: Box<InputCallback>) {
|
||||||
self.key_handler.set_input_callback(callback)
|
self.key_handler.set_input_callback(callback)
|
||||||
}
|
}
|
||||||
|
|
|
@ -353,6 +353,11 @@ impl Window {
|
||||||
self.key_handler.is_key_pressed(key, repeat)
|
self.key_handler.is_key_pressed(key, repeat)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn is_key_released(&self, key: Key) -> bool {
|
||||||
|
self.key_handler.is_key_released(key)
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_input_callback(&mut self, callback: Box<InputCallback>) {
|
pub fn set_input_callback(&mut self, callback: Box<InputCallback>) {
|
||||||
self.key_handler.set_input_callback(callback)
|
self.key_handler.set_input_callback(callback)
|
||||||
|
|
|
@ -595,6 +595,11 @@ impl Window {
|
||||||
self.key_handler.is_key_pressed(key, repeat)
|
self.key_handler.is_key_pressed(key, repeat)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn is_key_released(&self, key: Key) -> bool {
|
||||||
|
self.key_handler.is_key_released(key)
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_open(&self) -> bool {
|
pub fn is_open(&self) -> bool {
|
||||||
return self.is_open
|
return self.is_open
|
||||||
|
|
Loading…
Add table
Reference in a new issue