Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UWP: More mouse events #24597

Merged
merged 1 commit into from Nov 1, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -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));

This comment has been minimized.

@jdm

jdm Oct 31, 2019

Member

This is surprisingly difficult for my brain to read 😅

This comment has been minimized.

@paulrouget

paulrouget Oct 31, 2019

Author Contributor

just to be consistent with other method names.

},
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;
@@ -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)
@@ -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(|| {
@@ -62,6 +62,9 @@ class Servo {
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(); }
@@ -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();
@@ -125,6 +125,18 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
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 &);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.