From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- Runtime/Graphics/ScreenManager.cpp | 201 +++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 Runtime/Graphics/ScreenManager.cpp (limited to 'Runtime/Graphics/ScreenManager.cpp') diff --git a/Runtime/Graphics/ScreenManager.cpp b/Runtime/Graphics/ScreenManager.cpp new file mode 100644 index 0000000..4094338 --- /dev/null +++ b/Runtime/Graphics/ScreenManager.cpp @@ -0,0 +1,201 @@ +#include "UnityPrefix.h" +#include "ScreenManager.h" +#include "Runtime/Shaders/GraphicsCaps.h" +#include "Runtime/GfxDevice/GfxDevice.h" +#include "Runtime/GfxDevice/GfxDeviceSetup.h" + +static ScreenManagerPlatform* gScreenManager = NULL; + +#if UNITY_IPHONE + extern "C" void NotifyAutoOrientationChange(); +#endif + + +void InitScreenManager() +{ + Assert(gScreenManager == NULL); + gScreenManager = new ScreenManagerPlatform(); +} + +void ReleaseScreenManager() +{ + Assert(gScreenManager != NULL); + delete gScreenManager; + gScreenManager = NULL; +} + +ScreenManagerPlatform &GetScreenManager() +{ + Assert(gScreenManager != NULL); + return *gScreenManager; +} + +ScreenManagerPlatform* GetScreenManagerPtr() +{ + return gScreenManager; +} + +ScreenManager::ScreenManager () +{ + m_Width = 0; + m_Height = 0; + m_SwitchResolutionCallback = NULL; + m_CursorInWindow = false; + m_IsFullscreen = false; + m_AllowCursorHide = true; + m_AllowCursorLock = true; + + m_ScreenOrientation = kPortrait; + m_RequestedOrientation = kScreenOrientationUnknown; + + // Do not allow to autorotate by default. + m_EnabledOrientations = 0; +} + +void ScreenManager::RequestResolution (int width, int height, bool fullscreen, int preferredRefreshRate) +{ + m_ResolutionRequest.width = width; + m_ResolutionRequest.height = height; + m_ResolutionRequest.fullScreen = fullscreen ? 1 : 0; + m_ResolutionRequest.refreshRate = preferredRefreshRate; +} + +void ScreenManager::RequestSetFullscreen (bool fullscreen) +{ + m_ResolutionRequest.fullScreen = fullscreen ? 1 : 0; +} + +bool ScreenManager::HasFullscreenRequested () const +{ + return m_ResolutionRequest.fullScreen == 1; +} + +void ScreenManager::SetCursorInsideWindow (bool insideWindow) +{ + m_CursorInWindow = insideWindow; + SetShowCursor(GetShowCursor()); +} + +int ScreenManager::FindClosestResolution (const ScreenManager::Resolutions& resolutions, int width, int height) const +{ + if (resolutions.empty ()) + return -1; + + int maxDistance = std::numeric_limits::max (); + int index = 0; + for (int i=0;i