diff --git a/support/hololens/ServoApp/BrowserPage.cpp b/support/hololens/ServoApp/BrowserPage.cpp index 6130574aaef..2c2c6c6420b 100644 --- a/support/hololens/ServoApp/BrowserPage.cpp +++ b/support/hololens/ServoApp/BrowserPage.cpp @@ -35,6 +35,21 @@ void BrowserPage::OnPageLoaded(IInspectable const &, RoutedEventArgs const &) { swapChainPanel().PointerReleased( std::bind(&BrowserPage::OnSurfaceClicked, this, _1, _2)); + + swapChainPanel().ManipulationDelta( + std::bind(&BrowserPage::OnSurfaceManipulationDelta, this, _1, _2)); +} + +void BrowserPage::OnSurfaceManipulationDelta( + IInspectable const &, Input::ManipulationDeltaRoutedEventArgs const &e) { + auto x = e.Position().X; + auto y = e.Position().Y; + auto dx = e.Delta().Translation.X; + auto dy = e.Delta().Translation.Y; + Event event = {{Event::SCROLL}}; + event.scrollCoords = {dx, dy, x, y}; + SendEventToServo(event); + e.Handled(true); } void BrowserPage::OnSurfaceClicked(IInspectable const &, @@ -186,10 +201,15 @@ void BrowserPage::Loop(cancellation_token cancel) { for (auto &&e : mEvents) { switch (e.type) { case Event::CLICK: { - auto [x, y] = e.coords; + auto [x, y] = e.clickCoords; mServo->Click(x, y); break; } + case Event::SCROLL: { + auto [x, y, dx, dy] = e.scrollCoords; + mServo->Scroll(x, y, dx, dy); + break; + } case Event::FORWARD: mServo->GoForward(); break; diff --git a/support/hololens/ServoApp/BrowserPage.h b/support/hololens/ServoApp/BrowserPage.h index 89e5248722f..4eca25d363a 100644 --- a/support/hololens/ServoApp/BrowserPage.h +++ b/support/hololens/ServoApp/BrowserPage.h @@ -12,8 +12,9 @@ namespace winrt::ServoApp::implementation { struct Event { - enum { CLICK, BACK, FORWARD } type; - std::tuple coords; + enum { CLICK, SCROLL, BACK, FORWARD } type; + std::tuple clickCoords; + std::tuple scrollCoords; }; struct BrowserPage : BrowserPageT { @@ -31,6 +32,10 @@ public: OnSurfaceClicked(Windows::Foundation::IInspectable const &, Windows::UI::Xaml::Input::PointerRoutedEventArgs const &); + void BrowserPage::OnSurfaceManipulationDelta( + IInspectable const &, + Windows::UI::Xaml::Input::ManipulationDeltaRoutedEventArgs const &e); + private: void OnVisibilityChanged( Windows::UI::Core::CoreWindow const &, diff --git a/support/hololens/ServoApp/BrowserPage.xaml b/support/hololens/ServoApp/BrowserPage.xaml index bd1f88d8f5a..4247c9a1f68 100644 --- a/support/hololens/ServoApp/BrowserPage.xaml +++ b/support/hololens/ServoApp/BrowserPage.xaml @@ -28,7 +28,7 @@ - + diff --git a/support/hololens/ServoApp/Servo.cpp b/support/hololens/ServoApp/Servo.cpp index 8ffd2258a71..b262d420819 100644 --- a/support/hololens/ServoApp/Servo.cpp +++ b/support/hololens/ServoApp/Servo.cpp @@ -51,7 +51,7 @@ Servo::Servo(GLsizei width, GLsizei height) CInitOptions o; o.args = NULL; - o.url = "https://google.com"; + o.url = "https://servo.org"; o.width = mWindowWidth; o.height = mWindowHeight; o.density = 1.0; @@ -93,3 +93,4 @@ void Servo::SetSize(GLsizei width, GLsizei height) { } void Servo::Click(float x, float y) { click(x, y); } +void Servo::Scroll(float dx, float dy, float x, float y) { scroll(dx, dy, x, y); } diff --git a/support/hololens/ServoApp/Servo.h b/support/hololens/ServoApp/Servo.h index 118a6ab517c..2772d5ea20b 100644 --- a/support/hololens/ServoApp/Servo.h +++ b/support/hololens/ServoApp/Servo.h @@ -16,6 +16,7 @@ public: ~Servo(); void PerformUpdates(); void Click(float, float); + void Scroll(float dx, float dy, float x, float y); void SetSize(GLsizei width, GLsizei height); void SetBatchMode(bool); void GoBack();