Skip to content

Commit

Permalink
Support Scroll in HoloLens mode
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrouget committed Jul 23, 2019
1 parent 24d2213 commit 380e54b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
22 changes: 21 additions & 1 deletion support/hololens/ServoApp/BrowserPage.cpp
Expand Up @@ -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 &,
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions support/hololens/ServoApp/BrowserPage.h
Expand Up @@ -12,8 +12,9 @@
namespace winrt::ServoApp::implementation {

struct Event {
enum { CLICK, BACK, FORWARD } type;
std::tuple<float, float> coords;
enum { CLICK, SCROLL, BACK, FORWARD } type;
std::tuple<float, float> clickCoords;
std::tuple<float, float, float, float> scrollCoords;
};

struct BrowserPage : BrowserPageT<BrowserPage> {
Expand All @@ -31,6 +32,10 @@ struct BrowserPage : BrowserPageT<BrowserPage> {
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 &,
Expand Down
2 changes: 1 addition & 1 deletion support/hololens/ServoApp/BrowserPage.xaml
Expand Up @@ -28,7 +28,7 @@
<Button x:Name="immersiveButton" Click="OnImmersiveButtonClicked">Run Immersive</Button>
</StackPanel>
</Grid>
<SwapChainPanel x:Name="swapChainPanel" MinHeight="200" MinWidth="200" Grid.Row="1">
<SwapChainPanel x:Name="swapChainPanel" MinHeight="200" MinWidth="200" Grid.Row="1" ManipulationMode="All">
</SwapChainPanel>
</Grid>
</Page>
3 changes: 2 additions & 1 deletion support/hololens/ServoApp/Servo.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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); }
1 change: 1 addition & 0 deletions support/hololens/ServoApp/Servo.h
Expand Up @@ -16,6 +16,7 @@ class Servo {
~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();
Expand Down

0 comments on commit 380e54b

Please sign in to comment.