Add touch pressure information for touch events on iOS (#1090)
* Add touch pressure information for touch events on iOS * Add a variant for calibrated touch pressure
This commit is contained in:
parent
8e73287646
commit
1366dc326a
10 changed files with 131 additions and 14 deletions
|
|
@ -75,6 +75,7 @@ impl EventLoop {
|
|||
android_glue::MotionAction::Cancel => TouchPhase::Cancelled,
|
||||
},
|
||||
location,
|
||||
force: None, // TODO
|
||||
id: motion.pointer_id as u64,
|
||||
device_id: DEVICE_ID,
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -362,6 +362,7 @@ extern "C" fn touch_callback(
|
|||
phase,
|
||||
id: touch.identifier as u64,
|
||||
location,
|
||||
force: None, // TODO
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,24 @@ pub enum UITouchPhase {
|
|||
Cancelled,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[allow(dead_code)]
|
||||
#[repr(isize)]
|
||||
pub enum UIForceTouchCapability {
|
||||
Unknown = 0,
|
||||
Unavailable,
|
||||
Available,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[allow(dead_code)]
|
||||
#[repr(isize)]
|
||||
pub enum UITouchType {
|
||||
Direct = 0,
|
||||
Indirect,
|
||||
Pencil,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct UIEdgeInsets {
|
||||
|
|
|
|||
|
|
@ -6,13 +6,14 @@ use objc::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
event::{DeviceId as RootDeviceId, Event, Touch, TouchPhase, WindowEvent},
|
||||
event::{DeviceId as RootDeviceId, Event, Force, Touch, TouchPhase, WindowEvent},
|
||||
platform::ios::MonitorHandleExtIOS,
|
||||
platform_impl::platform::{
|
||||
app_state::AppState,
|
||||
event_loop,
|
||||
ffi::{
|
||||
id, nil, CGFloat, CGPoint, CGRect, UIInterfaceOrientationMask, UIRectEdge, UITouchPhase,
|
||||
id, nil, CGFloat, CGPoint, CGRect, UIForceTouchCapability, UIInterfaceOrientationMask,
|
||||
UIRectEdge, UITouchPhase, UITouchType,
|
||||
},
|
||||
window::PlatformSpecificWindowBuilderAttributes,
|
||||
DeviceId,
|
||||
|
|
@ -218,6 +219,27 @@ unsafe fn get_window_class() -> &'static Class {
|
|||
break;
|
||||
}
|
||||
let location: CGPoint = msg_send![touch, locationInView: nil];
|
||||
let touch_type: UITouchType = msg_send![touch, type];
|
||||
let trait_collection: id = msg_send![object, traitCollection];
|
||||
let touch_capability: UIForceTouchCapability =
|
||||
msg_send![trait_collection, forceTouchCapability];
|
||||
let force = if touch_capability == UIForceTouchCapability::Available {
|
||||
let force: CGFloat = msg_send![touch, force];
|
||||
let max_possible_force: CGFloat = msg_send![touch, maximumPossibleForce];
|
||||
let altitude_angle: Option<f64> = if touch_type == UITouchType::Pencil {
|
||||
let angle: CGFloat = msg_send![touch, altitudeAngle];
|
||||
Some(angle as _)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
Some(Force::Calibrated {
|
||||
force: force as _,
|
||||
max_possible_force: max_possible_force as _,
|
||||
altitude_angle,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let touch_id = touch as u64;
|
||||
let phase: UITouchPhase = msg_send![touch, phase];
|
||||
let phase = match phase {
|
||||
|
|
@ -235,6 +257,7 @@ unsafe fn get_window_class() -> &'static Class {
|
|||
device_id: RootDeviceId(DeviceId { uiscreen }),
|
||||
id: touch_id,
|
||||
location: (location.x as f64, location.y as f64).into(),
|
||||
force,
|
||||
phase,
|
||||
}),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ pub(crate) fn implement_touch<T: 'static>(
|
|||
),
|
||||
phase: TouchPhase::Started,
|
||||
location: (x, y).into(),
|
||||
force: None, // TODO
|
||||
id: id as u64,
|
||||
}),
|
||||
wid,
|
||||
|
|
@ -61,6 +62,7 @@ pub(crate) fn implement_touch<T: 'static>(
|
|||
),
|
||||
phase: TouchPhase::Ended,
|
||||
location: pt.location.into(),
|
||||
force: None, // TODO
|
||||
id: id as u64,
|
||||
}),
|
||||
pt.wid,
|
||||
|
|
@ -78,6 +80,7 @@ pub(crate) fn implement_touch<T: 'static>(
|
|||
),
|
||||
phase: TouchPhase::Moved,
|
||||
location: (x, y).into(),
|
||||
force: None, // TODO
|
||||
id: id as u64,
|
||||
}),
|
||||
pt.wid,
|
||||
|
|
@ -94,6 +97,7 @@ pub(crate) fn implement_touch<T: 'static>(
|
|||
),
|
||||
phase: TouchPhase::Cancelled,
|
||||
location: pt.location.into(),
|
||||
force: None, // TODO
|
||||
id: pt.id as u64,
|
||||
}),
|
||||
pt.wid,
|
||||
|
|
|
|||
|
|
@ -918,6 +918,7 @@ impl<T: 'static> EventProcessor<T> {
|
|||
device_id: mkdid(xev.deviceid),
|
||||
phase,
|
||||
location,
|
||||
force: None, // TODO
|
||||
id: xev.detail as u64,
|
||||
}),
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1499,6 +1499,7 @@ unsafe extern "system" fn public_window_callback<T>(
|
|||
continue;
|
||||
},
|
||||
location,
|
||||
force: None, // TODO
|
||||
id: input.dwID as u64,
|
||||
device_id: DEVICE_ID,
|
||||
}),
|
||||
|
|
@ -1603,6 +1604,7 @@ unsafe extern "system" fn public_window_callback<T>(
|
|||
continue;
|
||||
},
|
||||
location,
|
||||
force: None, // TODO
|
||||
id: pointer_info.pointerId as u64,
|
||||
device_id: DEVICE_ID,
|
||||
}),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue