Skip to content

Commit

Permalink
Merge pull request #12090 from driver1998/uwp-text-dwrite
Browse files Browse the repository at this point in the history
UWP: Full screen support
  • Loading branch information
hrydgard committed Jun 9, 2019
2 parents e5f1598 + 3cd037f commit 1d41b4e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
20 changes: 16 additions & 4 deletions UWP/App.cpp
Expand Up @@ -217,9 +217,10 @@ void App::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^
// Run() won't start until the CoreWindow is activated. // Run() won't start until the CoreWindow is activated.
CoreWindow::GetForCurrentThread()->Activate(); CoreWindow::GetForCurrentThread()->Activate();
// On mobile, we force-enter fullscreen mode. // On mobile, we force-enter fullscreen mode.
if (m_isPhone) { if (m_isPhone) g_Config.bFullScreen = true;

if (g_Config.bFullScreen)
Windows::UI::ViewManagement::ApplicationView::GetForCurrentView()->TryEnterFullScreenMode(); Windows::UI::ViewManagement::ApplicationView::GetForCurrentView()->TryEnterFullScreenMode();
}
} }


void App::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args) { void App::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args) {
Expand All @@ -228,9 +229,10 @@ void App::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args) {
// aware that a deferral may not be held indefinitely. After about five seconds, // aware that a deferral may not be held indefinitely. After about five seconds,
// the app will be forced to exit. // the app will be forced to exit.
SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral(); SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();
auto app = this;


create_task([this, deferral]() { create_task([app, deferral]() {
m_deviceResources->Trim(); app->m_deviceResources->Trim();
deferral->Complete(); deferral->Complete();
}); });
} }
Expand All @@ -246,6 +248,9 @@ void App::OnResuming(Platform::Object^ sender, Platform::Object^ args) {
// Window event handlers. // Window event handlers.


void App::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args) { void App::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args) {
auto view = Windows::UI::ViewManagement::ApplicationView::GetForCurrentView();
g_Config.bFullScreen = view->IsFullScreenMode;

int width = sender->Bounds.Width; int width = sender->Bounds.Width;
int height = sender->Bounds.Height; int height = sender->Bounds.Height;
float scale = m_deviceResources->GetDpi() / 96.0f; float scale = m_deviceResources->GetDpi() / 96.0f;
Expand All @@ -263,6 +268,13 @@ void App::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ ar
} }


void App::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args) { void App::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args) {

if (args->Visible == false) {
// MainScreen::OnExit and even App::OnWindowClosed
// doesn't seem to be called when closing the window
// Try to save the config here
g_Config.Save("App::OnVisibilityChanged");
}
m_windowVisible = args->Visible; m_windowVisible = args->Visible;
} }


Expand Down
8 changes: 8 additions & 0 deletions UWP/PPSSPP_UWPMain.cpp
Expand Up @@ -429,6 +429,14 @@ void System_SendMessage(const char *command, const char *parameter) {
g_main->LoadStorageFile(file); g_main->LoadStorageFile(file);
} }
}); });
} else if (!strcmp(command, "toggle_fullscreen")) {
auto view = Windows::UI::ViewManagement::ApplicationView::GetForCurrentView();
if (strcmp(parameter, "0") == 0) {
view->ExitFullScreenMode();
}
else if (strcmp(parameter, "1") == 0){
view->TryEnterFullScreenMode();
}
} }
} }


Expand Down
10 changes: 10 additions & 0 deletions ext/native/gfx_es2/draw_text_uwp.cpp
Expand Up @@ -151,6 +151,11 @@ TextDrawerUWP::~TextDrawerUWP() {
m_d2dContext->Release(); m_d2dContext->Release();
m_d2dDevice->Release(); m_d2dDevice->Release();
m_d2dFactory->Release(); m_d2dFactory->Release();

m_fontCollection->Release();
m_fontSet->Release();
m_fontFile->Release();
m_fontSetBuilder->Release();
m_dwriteFactory->Release(); m_dwriteFactory->Release();
delete ctx_; delete ctx_;
} }
Expand Down Expand Up @@ -206,6 +211,7 @@ void TextDrawerUWP::MeasureString(const char *str, size_t len, float *w, float *
if (iter != fontMap_.end()) { if (iter != fontMap_.end()) {
format = iter->second->textFmt; format = iter->second->textFmt;
} }
if (!format) return;


std::wstring wstr = ConvertUTF8ToWString(ReplaceAll(ReplaceAll(std::string(str, len), "\n", "\r\n"), "&&", "&")); std::wstring wstr = ConvertUTF8ToWString(ReplaceAll(ReplaceAll(std::string(str, len), "\n", "\r\n"), "&&", "&"));


Expand All @@ -223,6 +229,7 @@ void TextDrawerUWP::MeasureString(const char *str, size_t len, float *w, float *


DWRITE_TEXT_METRICS metrics; DWRITE_TEXT_METRICS metrics;
layout->GetMetrics(&metrics); layout->GetMetrics(&metrics);
layout->Release();


entry = new TextMeasureEntry(); entry = new TextMeasureEntry();
entry->width = metrics.width + 1; entry->width = metrics.width + 1;
Expand All @@ -242,6 +249,7 @@ void TextDrawerUWP::MeasureStringRect(const char *str, size_t len, const Bounds
if (iter != fontMap_.end()) { if (iter != fontMap_.end()) {
format = iter->second->textFmt; format = iter->second->textFmt;
} }
if (!format) return;


std::string toMeasure = std::string(str, len); std::string toMeasure = std::string(str, len);
if (align & FLAG_WRAP_TEXT) { if (align & FLAG_WRAP_TEXT) {
Expand Down Expand Up @@ -282,6 +290,7 @@ void TextDrawerUWP::MeasureStringRect(const char *str, size_t len, const Bounds


DWRITE_TEXT_METRICS metrics; DWRITE_TEXT_METRICS metrics;
layout->GetMetrics(&metrics); layout->GetMetrics(&metrics);
layout->Release();


entry = new TextMeasureEntry(); entry = new TextMeasureEntry();
entry->width = metrics.width + 1; entry->width = metrics.width + 1;
Expand Down Expand Up @@ -325,6 +334,7 @@ void TextDrawerUWP::DrawString(DrawBuffer &target, const char *str, float x, flo
if (iter != fontMap_.end()) { if (iter != fontMap_.end()) {
format = iter->second->textFmt; format = iter->second->textFmt;
} }
if (!format) return;


if (align & ALIGN_HCENTER) if (align & ALIGN_HCENTER)
format->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER); format->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER);
Expand Down
1 change: 0 additions & 1 deletion ext/native/gfx_es2/draw_text_uwp.h
Expand Up @@ -44,7 +44,6 @@ class TextDrawerUWP : public TextDrawer {
ID2D1Factory5* m_d2dFactory; ID2D1Factory5* m_d2dFactory;
ID2D1Device4* m_d2dDevice; ID2D1Device4* m_d2dDevice;
ID2D1DeviceContext4* m_d2dContext; ID2D1DeviceContext4* m_d2dContext;
ID2D1Bitmap1* m_d2dTargetBitmap;
ID2D1SolidColorBrush* m_d2dWhiteBrush; ID2D1SolidColorBrush* m_d2dWhiteBrush;


// DirectWrite drawing components. // DirectWrite drawing components.
Expand Down

0 comments on commit 1d41b4e

Please sign in to comment.