make warping be slightly snappier with impatient keypressing and a

minimum speed
This commit is contained in:
Dustin Carlino 2019-05-08 11:57:31 -07:00
parent 32b4c073a1
commit 240efa5ad7
2 changed files with 26 additions and 3 deletions

View File

@ -156,8 +156,9 @@ impl CommonState {
}
}
// TODO Maybe pixels/second or something would be smoother
const ANIMATION_TIME_S: f64 = 0.5;
// TODO Should factor in zoom too
const MIN_ANIMATION_SPEED: f64 = 200.0;
pub struct Warper {
started: Instant,
@ -182,8 +183,15 @@ impl Warper {
ctx.input.use_update_event();
}
let percent = elapsed_seconds(self.started) / ANIMATION_TIME_S;
if percent >= 1.0 {
let speed = line.length().inner_meters() / ANIMATION_TIME_S;
let total_time = if speed >= MIN_ANIMATION_SPEED {
ANIMATION_TIME_S
} else {
line.length().inner_meters() / MIN_ANIMATION_SPEED
};
let percent = elapsed_seconds(self.started) / total_time;
if percent >= 1.0 || ctx.input.nonblocking_is_keypress_event() {
ctx.canvas.center_on_map_pt(line.pt2());
ui.primary.current_selection = Some(self.id);
None

View File

@ -261,6 +261,21 @@ impl UserInput {
assert!(self.event == Event::Update)
}
pub fn nonblocking_is_keypress_event(&mut self) -> bool {
if self.context_menu_active() {
return false;
}
if self.event_consumed {
return false;
}
match self.event {
Event::KeyPress(_) => true,
_ => false,
}
}
// TODO I'm not sure this is even useful anymore
pub(crate) fn use_event_directly(&mut self) -> Option<Event> {
if self.event_consumed {