aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ports/libmlservo/src/lib.rs8
-rw-r--r--ports/libsimpleservo/api/src/lib.rs2
-rw-r--r--ports/libsimpleservo/capi/src/lib.rs8
-rw-r--r--support/hololens/ServoApp/ServoControl/Servo.h3
-rw-r--r--support/hololens/ServoApp/ServoControl/ServoControl.cpp37
-rw-r--r--support/hololens/ServoApp/ServoControl/ServoControl.h12
6 files changed, 64 insertions, 6 deletions
diff --git a/ports/libmlservo/src/lib.rs b/ports/libmlservo/src/lib.rs
index 32371c823d9..5cb2c12b10c 100644
--- a/ports/libmlservo/src/lib.rs
+++ b/ports/libmlservo/src/lib.rs
@@ -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;
diff --git a/ports/libsimpleservo/api/src/lib.rs b/ports/libsimpleservo/api/src/lib.rs
index 57844593a95..12fba7a6d3e 100644
--- a/ports/libsimpleservo/api/src/lib.rs
+++ b/ports/libsimpleservo/api/src/lib.rs
@@ -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)
diff --git a/ports/libsimpleservo/capi/src/lib.rs b/ports/libsimpleservo/capi/src/lib.rs
index 595c724737e..32f3b368ea6 100644
--- a/ports/libsimpleservo/capi/src/lib.rs
+++ b/ports/libsimpleservo/capi/src/lib.rs
@@ -560,6 +560,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(|| {
debug!("mouse_down");
diff --git a/support/hololens/ServoApp/ServoControl/Servo.h b/support/hololens/ServoApp/ServoControl/Servo.h
index 8c968a71835..3cf3bc63d93 100644
--- a/support/hololens/ServoApp/ServoControl/Servo.h
+++ b/support/hololens/ServoApp/ServoControl/Servo.h
@@ -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(); }
diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.cpp b/support/hololens/ServoApp/ServoControl/ServoControl.cpp
index 6c6fa094dad..47e6ab7b5c0 100644
--- a/support/hololens/ServoApp/ServoControl/ServoControl.cpp
+++ b/support/hololens/ServoApp/ServoControl/ServoControl.cpp
@@ -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();
diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.h b/support/hololens/ServoApp/ServoControl/ServoControl.h
index aa58f2f6ee1..816e68d095c 100644
--- a/support/hololens/ServoApp/ServoControl/ServoControl.h
+++ b/support/hololens/ServoApp/ServoControl/ServoControl.h
@@ -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 &);