Skip to content

Commit

Permalink
Windows 10 Anniversary Update - March 2017 Update 3
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnewthing committed Mar 16, 2017
2 parents 3892c2d + 706be8e commit b085a99
Show file tree
Hide file tree
Showing 44 changed files with 4,507 additions and 117 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ For additional Windows samples, see [Windows on GitHub](http://microsoft.github.
</tr>
<tr>
<td><a href="Samples/HolographicSpatialMapping">Holographic spatial mapping</a></td>
<td><a href="Samples/HolographicVoiceInput">Holographic voice input</a></td>
<td><a href="Samples/HolographicTagAlong">Tag-along hologram</a></td>
</tr>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ using Windows::Graphics::Display::DisplayInformation;


Scenario_Document1::Scenario_Document1()
: rootPage(MainPage::Current)
: m_rootPage(MainPage::Current)
{
m_eventToken.Value = 0;

InitializeComponent();

String^ text =
Expand All @@ -81,32 +79,35 @@ Scenario_Document1::Scenario_Document1()
// Initialize FontDownloadListener, register the event handler, and initiate
// the download.
FontDownloadListener::Initialize();
m_eventToken = FontDownloadListener::DownloadCompleted += ref new FontDownloadCompletedHandler(this, &Scenario_Document1::FontDownloadListener_DownloadCompleted);
m_downloadCompletedEventToken = FontDownloadListener::DownloadCompleted += ref new FontDownloadCompletedHandler(this, &Scenario_Document1::FontDownloadListener_DownloadCompleted);
FontDownloadListener::BeginDownload();

// When the SurfaceImageSource is created, we'll need to know the current DPI.
// We'll also need an event handler to re-create the image source if the DPI changes.
DisplayInformation^ displayInformation = DisplayInformation::GetForCurrentView();
m_dpi = displayInformation->LogicalDpi;
displayInformation->DpiChanged += ref new TypedEventHandler<DisplayInformation^, Object^>([this](DisplayInformation^ sender, Object^)
{
this->HandleDpiChanged(sender);
});
m_displayInformation = DisplayInformation::GetForCurrentView();
m_dpi = m_displayInformation->LogicalDpi;
m_dpiChangedEventToken = m_displayInformation->DpiChanged += ref new TypedEventHandler<DisplayInformation^, Object^>(this, &Scenario_Document1::DisplayInformation_DpiChanged);

// When the app window is hidden, XAML may release resource used by the
// SurfaceImageSource. We'll need to make sure it gets re-created if the
// window was hidden and then becomes visible again.
Window::Current->VisibilityChanged += ref new Windows::UI::Xaml::WindowVisibilityChangedEventHandler(this, &SDKTemplate::Scenario_Document1::OnVisibilityChanged);
m_visibilityChangedEventToken = Window::Current->VisibilityChanged += ref new WindowVisibilityChangedEventHandler(this, &Scenario_Document1::Window_VisibilityChanged);

// As the page is loaded, after this constructor has exited, XAML will be
// re-sizing the TextLayoutFrame scroll viewer element and the SizeChanged
// handler will get invoked. That's when the image source will first get created.
}

void Scenario_Document1::OnNavigatedFrom(NavigationEventArgs^ e)
{
FontDownloadListener::DownloadCompleted -= m_downloadCompletedEventToken;
m_displayInformation->DpiChanged -= m_dpiChangedEventToken;
Window::Current->VisibilityChanged -= m_visibilityChangedEventToken;
}

// Event handlers:

void Scenario_Document1::TextLayoutFrame_SizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e)
void Scenario_Document1::TextLayoutFrame_SizeChanged(Object^ sender, SizeChangedEventArgs^ e)
{
// Get the current available width and update the TextLayout if different.
// The available width will be the actual width less the left and right padding.
Expand Down Expand Up @@ -142,15 +143,6 @@ void Scenario_Document1::TextLayoutFrame_SizeChanged(Platform::Object^ sender, W
}


void Scenario_Document1::OnNavigatedFrom(NavigationEventArgs^ e)
{
if (m_eventToken.Value != 0)
{
FontDownloadListener::DownloadCompleted -= m_eventToken;
}
}


void Scenario_Document1::FontDownloadListener_DownloadCompleted()
{
// DownloadCompleted is called from a worker thread, so schedule work
Expand Down Expand Up @@ -178,13 +170,24 @@ void Scenario_Document1::FontDownloadListener_DownloadCompleted()
}


void Scenario_Document1::HandleDpiChanged(DisplayInformation^ displayInformation)
void Scenario_Document1::DisplayInformation_DpiChanged(DisplayInformation^ displayInformation, Object^ e)
{
m_dpi = displayInformation->LogicalDpi;
PresentTextLayout();
}


void Scenario_Document1::Window_VisibilityChanged(Object^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ e)
{
// Re-create the SurfaceImageSource if the window has just become visible.
if (e->Visible)
{
PresentTextLayout();
}
}



// Private helper methods:

void Scenario_Document1::RequestTextLayoutUpdate()
Expand Down Expand Up @@ -249,15 +252,5 @@ void Scenario_Document1::UpdateStatus()
NotifyType statusType = (fontsUsed == m_downloadableFontName) ? NotifyType::StatusMessage : NotifyType::ErrorMessage;

// Now update the status.
rootPage->NotifyUser("Fonts actually used: " + fontsUsed, statusType);
}


void Scenario_Document1::OnVisibilityChanged(Platform::Object ^sender, Windows::UI::Core::VisibilityChangedEventArgs ^e)
{
// Re-create the SurfaceImageSource if the window has just become visible.
if (e->Visible)
{
PresentTextLayout();
}
m_rootPage->NotifyUser("Fonts actually used: " + fontsUsed, statusType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,33 @@ namespace SDKTemplate
{
public:
Scenario_Document1();
void HandleDpiChanged(DisplayInformation^ displayInformation);

protected:
virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;

private:
MainPage^ rootPage;
MainPage^ m_rootPage;
TextLayout^ m_textLayout;
TextLayoutImageSource^ m_textLayoutImageSource;
FontDownloadListener^ m_fontDownloadListener;
Windows::Foundation::EventRegistrationToken m_eventToken;
Windows::UI::Color m_textColor;
Windows::UI::Color m_textBackgroundColor;
Platform::String^ m_downloadableFontName;
bool m_layoutUpdateInProgress = false;
Windows::Graphics::Display::DisplayInformation^ m_displayInformation;
float m_dpi = 96.0f;

void TextLayoutFrame_SizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e);
void FontDownloadListener_DownloadCompleted();
Windows::Foundation::EventRegistrationToken m_downloadCompletedEventToken{};
Windows::Foundation::EventRegistrationToken m_dpiChangedEventToken{};
Windows::Foundation::EventRegistrationToken m_visibilityChangedEventToken{};

void RequestTextLayoutUpdate();
void UpdateTextLayout();
void PresentTextLayout();
void UpdateStatus();
void OnVisibilityChanged(Platform::Object ^sender, Windows::UI::Core::VisibilityChangedEventArgs ^e);
void DisplayInformation_DpiChanged(DisplayInformation^ sender, Object^ e);
void FontDownloadListener_DownloadCompleted();
void TextLayoutFrame_SizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e);
void Window_VisibilityChanged(Platform::Object^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ e);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ using Windows::Graphics::Display::DisplayInformation;


Scenario_Document2::Scenario_Document2()
: rootPage(MainPage::Current)
: m_rootPage(MainPage::Current)
{
m_eventToken.Value = 0;

InitializeComponent();

String^ text =
Expand All @@ -58,25 +56,28 @@ Scenario_Document2::Scenario_Document2()
// Initialize FontDownloadListener, register the event handler, and initiate
// the download.
FontDownloadListener::Initialize();
m_eventToken = FontDownloadListener::DownloadCompleted += ref new FontDownloadCompletedHandler(this, &Scenario_Document2::FontDownloadListener_DownloadCompleted);
m_downloadCompletedEventToken = FontDownloadListener::DownloadCompleted += ref new FontDownloadCompletedHandler(this, &Scenario_Document2::FontDownloadListener_DownloadCompleted);
FontDownloadListener::BeginDownload();

// Handle DPI.
DisplayInformation^ displayInformation = DisplayInformation::GetForCurrentView();
m_dpi = displayInformation->LogicalDpi;
displayInformation->DpiChanged += ref new TypedEventHandler<DisplayInformation^, Object^>([this](DisplayInformation^ sender, Object^)
{
this->HandleDpiChanged(sender);
});
m_displayInformation = DisplayInformation::GetForCurrentView();
m_dpi = m_displayInformation->LogicalDpi;
m_dpiChangedEventToken = m_displayInformation->DpiChanged += ref new TypedEventHandler<DisplayInformation^, Object^>(this, &Scenario_Document2::DisplayInformation_DpiChanged);

// Handle window visibility change.
Window::Current->VisibilityChanged += ref new Windows::UI::Xaml::WindowVisibilityChangedEventHandler(this, &SDKTemplate::Scenario_Document2::OnVisibilityChanged);
m_visibilityChangedEventToken = Window::Current->VisibilityChanged += ref new WindowVisibilityChangedEventHandler(this, &SDKTemplate::Scenario_Document2::Window_VisibilityChanged);
}

void Scenario_Document2::OnNavigatedFrom(NavigationEventArgs^ e)
{
FontDownloadListener::DownloadCompleted -= m_downloadCompletedEventToken;
m_displayInformation->DpiChanged -= m_dpiChangedEventToken;
Window::Current->VisibilityChanged -= m_visibilityChangedEventToken;
}

// Event handlers:

void Scenario_Document2::TextLayoutFrame_SizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e)
void Scenario_Document2::TextLayoutFrame_SizeChanged(Object^ sender, SizeChangedEventArgs^ e)
{
// Get the current available width and update the TextLayout if different.
// The available width will be the actual width less the left and right padding.
Expand All @@ -98,14 +99,6 @@ void Scenario_Document2::TextLayoutFrame_SizeChanged(Platform::Object^ sender, W
}


void Scenario_Document2::OnNavigatedFrom(NavigationEventArgs^ e)
{
if (m_eventToken.Value != 0)
{
FontDownloadListener::DownloadCompleted -= m_eventToken;
}
}


void Scenario_Document2::FontDownloadListener_DownloadCompleted()
{
Expand All @@ -118,13 +111,24 @@ void Scenario_Document2::FontDownloadListener_DownloadCompleted()
}


void Scenario_Document2::HandleDpiChanged(DisplayInformation^ displayInformation)
void Scenario_Document2::DisplayInformation_DpiChanged(DisplayInformation^ displayInformation, Object^ e)
{
m_dpi = displayInformation->LogicalDpi;
PresentTextLayout();
}


void Scenario_Document2::Window_VisibilityChanged(Object^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ e)
{
// Re-create the SurfaceImageSource if the window has just become visible.
if (e->Visible)
{
PresentTextLayout();
}
}



// Private helper methods:

void Scenario_Document2::RequestTextLayoutUpdate()
Expand All @@ -151,6 +155,8 @@ void Scenario_Document2::UpdateTextLayout()

// Update the status bar to show what fonts have actually been used.
UpdateStatus();

m_layoutUpdateInProgress = false;
}


Expand All @@ -173,15 +179,5 @@ void Scenario_Document2::UpdateStatus()
NotifyType statusType = (fontsUsed == m_downloadableFontName) ? NotifyType::StatusMessage : NotifyType::ErrorMessage;

// Now update the status.
rootPage->NotifyUser("Fonts actually used: " + fontsUsed, statusType);
}


void Scenario_Document2::OnVisibilityChanged(Platform::Object ^sender, Windows::UI::Core::VisibilityChangedEventArgs ^e)
{
// Re-create the SurfaceImageSource if the window has just become visible.
if (e->Visible)
{
PresentTextLayout();
}
m_rootPage->NotifyUser("Fonts actually used: " + fontsUsed, statusType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,33 @@ namespace SDKTemplate
{
public:
Scenario_Document2();
void HandleDpiChanged(DisplayInformation^ displayInformation);

protected:
virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;

private:
MainPage^ rootPage;
MainPage^ m_rootPage;
TextLayout^ m_textLayout;
TextLayoutImageSource^ m_textLayoutImageSource;
FontDownloadListener^ m_fontDownloadListener;
Windows::Foundation::EventRegistrationToken m_eventToken;
Windows::UI::Color m_textColor;
Windows::UI::Color m_textBackgroundColor;
Platform::String^ m_downloadableFontName;
bool m_layoutUpdateInProgress = false;
Windows::Graphics::Display::DisplayInformation^ m_displayInformation;
float m_dpi = 96.0f;

void TextLayoutFrame_SizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e);
void FontDownloadListener_DownloadCompleted();
Windows::Foundation::EventRegistrationToken m_downloadCompletedEventToken{};
Windows::Foundation::EventRegistrationToken m_dpiChangedEventToken{};
Windows::Foundation::EventRegistrationToken m_visibilityChangedEventToken{};

void RequestTextLayoutUpdate();
void UpdateTextLayout();
void PresentTextLayout();
void UpdateStatus();
void OnVisibilityChanged(Platform::Object ^sender, Windows::UI::Core::VisibilityChangedEventArgs ^e);
void DisplayInformation_DpiChanged(DisplayInformation^ sender, Object^ e);
void FontDownloadListener_DownloadCompleted();
void TextLayoutFrame_SizeChanged(Platform::Object^ sender, Windows::UI::Xaml::SizeChangedEventArgs^ e);
void Window_VisibilityChanged(Platform::Object^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ e);
};
}
Loading

0 comments on commit b085a99

Please sign in to comment.