From b2c56940ebe4ac5ec8875616ec7bd07765cd4be8 Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Thu, 22 Aug 2019 07:55:17 +0200 Subject: [PATCH] Resize Servo on surface resize --- .../hololens/ServoApp/ServoControl/ServoControl.cpp | 10 ++++++++++ support/hololens/ServoApp/ServoControl/ServoControl.h | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.cpp b/support/hololens/ServoApp/ServoControl/ServoControl.cpp index ef172357bfe..56c4938490e 100644 --- a/support/hololens/ServoApp/ServoControl/ServoControl.cpp +++ b/support/hololens/ServoApp/ServoControl/ServoControl.cpp @@ -51,6 +51,8 @@ void ServoControl::OnLoaded(IInspectable const &, RoutedEventArgs const &) { }); panel.ManipulationDelta( std::bind(&ServoControl::OnSurfaceManipulationDelta, this, _1, _2)); + Panel().SizeChanged( + std::bind(&ServoControl::OnSurfaceResized, this, _1, _2)); InitializeConditionVariable(&mGLCondVar); InitializeCriticalSection(&mGLLock); CreateRenderSurface(); @@ -100,6 +102,14 @@ void ServoControl::OnSurfaceClicked(IInspectable const &, e.Handled(true); } +void ServoControl::OnSurfaceResized(IInspectable const &, + SizeChangedEventArgs const &e) { + auto size = e.NewSize(); + auto w = size.Width * mDPI; + auto h = size.Height * mDPI; + RunOnGLThread([=] { mServo->SetSize(w, h); }); +} + void ServoControl::GoBack() { RunOnGLThread([=] { mServo->GoBack(); }); } diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.h b/support/hololens/ServoApp/ServoControl/ServoControl.h index fd708cd93f0..54d1caf8c12 100644 --- a/support/hololens/ServoApp/ServoControl/ServoControl.h +++ b/support/hololens/ServoApp/ServoControl/ServoControl.h @@ -62,7 +62,7 @@ struct ServoControl : ServoControlT, public servo::ServoDelegate { mOnCaptureGesturesStartedEvent.remove(token); } - winrt::event_token OnCaptureGesturesEnded(EventDelegate const &handler) { + winrt::event_token OnCaptureGesturesEnded(EventDelegate const &handler) { return mOnCaptureGesturesEndedEvent.add(handler); }; void OnCaptureGesturesEnded(winrt::event_token const &token) noexcept { @@ -118,7 +118,10 @@ private: void OnSurfaceManipulationDelta( IInspectable const &, - Windows::UI::Xaml::Input::ManipulationDeltaRoutedEventArgs const &e); + Windows::UI::Xaml::Input::ManipulationDeltaRoutedEventArgs const &); + + void OnSurfaceResized(IInspectable const &, + Windows::UI::Xaml::SizeChangedEventArgs const &); template void RunOnUIThread(Callable); void RunOnGLThread(std::function);