UWP: More mouse events

This commit is contained in:
Paul Rouget 2019-10-31 13:13:48 +01:00
parent de9c84f686
commit 112221f046
6 changed files with 64 additions and 6 deletions

View file

@ -240,7 +240,7 @@ pub unsafe extern "C" fn move_servo(servo: *mut ServoInstance, x: f32, y: f32) {
match servo.scroll_state {
ScrollState::TriggerUp => {
servo.scroll_state = ScrollState::TriggerUp;
let _ = call(|s| s.move_mouse(x, y));
let _ = call(|s| s.mouse_move(x, y));
},
ScrollState::TriggerDown(start)
if (start - point).square_length() < DRAG_CUTOFF_SQUARED =>
@ -249,14 +249,14 @@ pub unsafe extern "C" fn move_servo(servo: *mut ServoInstance, x: f32, y: f32) {
}
ScrollState::TriggerDown(start) => {
servo.scroll_state = ScrollState::TriggerDragging(start, point);
let _ = call(|s| s.move_mouse(x, y));
let _ = call(|s| s.mouse_move(x, y));
let delta = (point - start) * servo.scroll_scale;
let start = start.to_i32();
let _ = call(|s| s.scroll_start(delta.x, delta.y, start.x, start.y));
},
ScrollState::TriggerDragging(start, prev) => {
servo.scroll_state = ScrollState::TriggerDragging(start, point);
let _ = call(|s| s.move_mouse(x, y));
let _ = call(|s| s.mouse_move(x, y));
let delta = (point - prev) * servo.scroll_scale;
let start = start.to_i32();
let _ = call(|s| s.scroll(delta.x, delta.y, start.x, start.y));
@ -279,7 +279,7 @@ pub unsafe extern "C" fn trigger_servo(servo: *mut ServoInstance, x: f32, y: f32
servo.scroll_state = ScrollState::TriggerUp;
let _ = call(|s| s.mouse_up(start.x, start.y, MouseButton::Left));
let _ = call(|s| s.click(start.x as f32, start.y as f32));
let _ = call(|s| s.move_mouse(start.x, start.y));
let _ = call(|s| s.mouse_move(start.x, start.y));
},
ScrollState::TriggerDragging(start, prev) if !down => {
servo.scroll_state = ScrollState::TriggerUp;

View file

@ -397,7 +397,7 @@ impl ServoGlue {
}
/// Register a mouse movement.
pub fn move_mouse(&mut self, x: f32, y: f32) -> Result<(), &'static str> {
pub fn mouse_move(&mut self, x: f32, y: f32) -> Result<(), &'static str> {
let point = Point2D::new(x, y);
let event = WindowEvent::MouseWindowMoveEventClass(point);
self.process_event(event)

View file

@ -559,6 +559,14 @@ pub extern "C" fn pinchzoom_end(factor: f32, x: i32, y: i32) {
});
}
#[no_mangle]
pub extern "C" fn mouse_move(x: f32, y: f32) {
catch_any_panic(|| {
debug!("mouse_move");
call(|s| s.mouse_move(x, y));
});
}
#[no_mangle]
pub extern "C" fn mouse_down(x: f32, y: f32, button: CMouseButton) {
catch_any_panic(|| {

View file

@ -62,6 +62,9 @@ public:
void MouseUp(float x, float y, capi::CMouseButton b) {
capi::mouse_up(x, y, b);
}
void MouseMove(float x, float y) {
capi::mouse_move(x, y);
}
void Reload() { capi::reload(); }
void Stop() { capi::stop(); }

View file

@ -41,6 +41,14 @@ void ServoControl::OnLoaded(IInspectable const &, RoutedEventArgs const &) {
std::bind(&ServoControl::OnSurfacePointerPressed, this, _1, _2));
panel.PointerReleased(
std::bind(&ServoControl::OnSurfacePointerPressed, this, _1, _2));
panel.PointerCanceled(
std::bind(&ServoControl::OnSurfacePointerCanceled, this, _1, _2));
panel.PointerCaptureLost(
std::bind(&ServoControl::OnSurfacePointerCanceled, this, _1, _2));
panel.PointerMoved(
std::bind(&ServoControl::OnSurfacePointerMoved, this, _1, _2));
panel.PointerWheelChanged(
std::bind(&ServoControl::OnSurfaceWheelChanged, this, _1, _2));
panel.ManipulationStarted(
[=](IInspectable const &,
Input::ManipulationStartedRoutedEventArgs const &e) {
@ -63,7 +71,6 @@ void ServoControl::OnLoaded(IInspectable const &, RoutedEventArgs const &) {
}
Controls::SwapChainPanel ServoControl::Panel() {
// FIXME: is there a better way of doing this?
return GetTemplateChild(L"swapChainPanel").as<Controls::SwapChainPanel>();
}
@ -140,6 +147,34 @@ void ServoControl::OnSurfacePointerPressed(
}
}
void ServoControl::OnSurfacePointerCanceled(
IInspectable const &, Input::PointerRoutedEventArgs const &e) {
mPressedMouseButton = {};
}
void ServoControl::OnSurfacePointerMoved(
IInspectable const &, Input::PointerRoutedEventArgs const &e) {
if (e.Pointer().PointerDeviceType() ==
Windows::Devices::Input::PointerDeviceType::Mouse) {
auto point = e.GetCurrentPoint(Panel());
auto x = point.Position().X * mDPI;
auto y = point.Position().Y * mDPI;
RunOnGLThread([=] { mServo->MouseMove(x, y); });
}
}
void ServoControl::OnSurfaceWheelChanged(
IInspectable const &, Input::PointerRoutedEventArgs const &e) {
if (e.Pointer().PointerDeviceType() ==
Windows::Devices::Input::PointerDeviceType::Mouse) {
auto point = e.GetCurrentPoint(Panel());
auto x = point.Position().X * mDPI;
auto y = point.Position().Y * mDPI;
auto delta = point.Properties().MouseWheelDelta() * mDPI;
RunOnGLThread([=] { mServo->Scroll(0, (float)delta, x, y); });
}
}
void ServoControl::OnSurfaceResized(IInspectable const &,
SizeChangedEventArgs const &e) {
auto size = e.NewSize();

View file

@ -125,6 +125,18 @@ private:
void OnSurfacePointerPressed(IInspectable const &,
Windows::UI::Xaml::Input::PointerRoutedEventArgs const &);
void OnSurfacePointerCanceled(
IInspectable const &,
Windows::UI::Xaml::Input::PointerRoutedEventArgs const &);
void OnSurfacePointerMoved(
IInspectable const &,
Windows::UI::Xaml::Input::PointerRoutedEventArgs const &);
void OnSurfaceWheelChanged(
IInspectable const &,
Windows::UI::Xaml::Input::PointerRoutedEventArgs const &);
void OnSurfaceManipulationDelta(
IInspectable const &,
Windows::UI::Xaml::Input::ManipulationDeltaRoutedEventArgs const &);