Support multi-touch events on Android

Depends on tomaka/android-rs-glue#64.
This commit is contained in:
Matt Brubeck 2015-09-22 09:22:46 -07:00
parent 08cb668037
commit 1827910927
2 changed files with 14 additions and 11 deletions

View file

@ -28,7 +28,7 @@ khronos_api = "0.0.7"
clock_ticks = "0.0.5" clock_ticks = "0.0.5"
[target.arm-linux-androideabi.dependencies.android_glue] [target.arm-linux-androideabi.dependencies.android_glue]
version = "0" version = "0.1"
[target.x86_64-apple-ios.dependencies] [target.x86_64-apple-ios.dependencies]
objc = "0.1" objc = "0.1"

View file

@ -8,8 +8,7 @@ use std::sync::mpsc::{Receiver, channel};
use {CreationError, Event, MouseCursor}; use {CreationError, Event, MouseCursor};
use CreationError::OsError; use CreationError::OsError;
use events::ElementState::{Pressed, Released}; use events::ElementState::{Pressed, Released};
use events::Event::{MouseInput, MouseMoved}; use events::{Touch, TouchPhase};
use events::MouseButton;
use std::collections::VecDeque; use std::collections::VecDeque;
@ -68,15 +67,19 @@ impl<'a> Iterator for PollEventsIterator<'a> {
fn next(&mut self) -> Option<Event> { fn next(&mut self) -> Option<Event> {
match self.window.event_rx.try_recv() { match self.window.event_rx.try_recv() {
Ok(event) => { Ok(android_glue::Event::EventMotion(motion)) => {
match event { Some(Event::Touch(Touch {
android_glue::Event::EventDown => Some(MouseInput(Pressed, MouseButton::Left)), phase: match motion.action {
android_glue::Event::EventUp => Some(MouseInput(Released, MouseButton::Left)), android_glue::MotionAction::Down => TouchPhase::Started,
android_glue::Event::EventMove(x, y) => Some(MouseMoved((x as i32, y as i32))), android_glue::MotionAction::Move => TouchPhase::Moved,
_ => None, android_glue::MotionAction::Up => TouchPhase::Ended,
android_glue::MotionAction::Cancel => TouchPhase::Cancelled,
},
location: (motion.x as f64, motion.y as f64),
id: motion.pointer_id as u64,
}))
} }
} _ => {
Err(_) => {
None None
} }
} }