Resize Servo on surface resize

This commit is contained in:
Paul Rouget 2019-08-22 07:55:17 +02:00
parent 10f86935b8
commit b2c56940eb
2 changed files with 15 additions and 2 deletions

View file

@ -51,6 +51,8 @@ void ServoControl::OnLoaded(IInspectable const &, RoutedEventArgs const &) {
}); });
panel.ManipulationDelta( panel.ManipulationDelta(
std::bind(&ServoControl::OnSurfaceManipulationDelta, this, _1, _2)); std::bind(&ServoControl::OnSurfaceManipulationDelta, this, _1, _2));
Panel().SizeChanged(
std::bind(&ServoControl::OnSurfaceResized, this, _1, _2));
InitializeConditionVariable(&mGLCondVar); InitializeConditionVariable(&mGLCondVar);
InitializeCriticalSection(&mGLLock); InitializeCriticalSection(&mGLLock);
CreateRenderSurface(); CreateRenderSurface();
@ -100,6 +102,14 @@ void ServoControl::OnSurfaceClicked(IInspectable const &,
e.Handled(true); 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() { void ServoControl::GoBack() {
RunOnGLThread([=] { mServo->GoBack(); }); RunOnGLThread([=] { mServo->GoBack(); });
} }

View file

@ -62,7 +62,7 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
mOnCaptureGesturesStartedEvent.remove(token); mOnCaptureGesturesStartedEvent.remove(token);
} }
winrt::event_token OnCaptureGesturesEnded(EventDelegate const &handler) { winrt::event_token OnCaptureGesturesEnded(EventDelegate const &handler) {
return mOnCaptureGesturesEndedEvent.add(handler); return mOnCaptureGesturesEndedEvent.add(handler);
}; };
void OnCaptureGesturesEnded(winrt::event_token const &token) noexcept { void OnCaptureGesturesEnded(winrt::event_token const &token) noexcept {
@ -118,7 +118,10 @@ private:
void OnSurfaceManipulationDelta( void OnSurfaceManipulationDelta(
IInspectable const &, 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 <typename Callable> void RunOnUIThread(Callable); template <typename Callable> void RunOnUIThread(Callable);
void RunOnGLThread(std::function<void()>); void RunOnGLThread(std::function<void()>);