From 5316882cf592a13d07c972a3db0a374257a04b58 Mon Sep 17 00:00:00 2001 From: Danilo Date: Tue, 30 Jul 2024 15:29:58 -0300 Subject: [PATCH] =?UTF-8?q?Implementa=C3=A7=C3=B5es=20em=20GameWindow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/platform-dx/gdevicemanager.cpp | 13 +++++ framework/platform-dx/window.cpp | 73 +++++++++++++----------- inc/xna/default.hpp | 1 - inc/xna/game/gdevicemanager.hpp | 13 +++-- inc/xna/game/window.hpp | 43 ++++++++++++-- inc/xna/xna-dx.hpp | 3 + 6 files changed, 101 insertions(+), 45 deletions(-) diff --git a/framework/platform-dx/gdevicemanager.cpp b/framework/platform-dx/gdevicemanager.cpp index d7764d5..2fb1e9e 100644 --- a/framework/platform-dx/gdevicemanager.cpp +++ b/framework/platform-dx/gdevicemanager.cpp @@ -109,6 +109,19 @@ namespace xna { void GraphicsDeviceManager::ChangeDevice() { } + void GraphicsDeviceManager::ChangeDevice(bool forceCreate) { + if (!game) + Exception::Throw(Exception::INVALID_OPERATION); + + inDeviceTransition = true; + auto screenDeviceName = game->Window()->ScreenDeviceName(); + int clientWidth = game->Window()->ClientBounds().Width; + int clientHeight = game->Window()->ClientBounds().Height; + bool flag1 = false; + + //TODO + } + void GraphicsDeviceManager::AddDevices(bool anySuitableDevice, std::vector>& foundDevices) { const auto handle = game->Window()->Handle(); diff --git a/framework/platform-dx/window.cpp b/framework/platform-dx/window.cpp index 98f9506..f9ce345 100644 --- a/framework/platform-dx/window.cpp +++ b/framework/platform-dx/window.cpp @@ -2,20 +2,17 @@ namespace xna { GameWindow::GameWindow() { - impl = unew(); + impl = unew(this); impl->_hInstance = GetModuleHandle(NULL); impl->_windowIcon = LoadIcon(NULL, IDI_APPLICATION); impl->_windowCursor = LoadCursor(NULL, IDC_ARROW); impl->_windowStyle = static_cast(GameWindowMode::Windowed); impl->_windowCenterX = impl->_windowWidth / 2.0F; - impl->_windowCenterY = impl->_windowHeight / 2.0F; - - } - - GameWindow::~GameWindow() { - impl = nullptr; - } + impl->_windowCenterY = impl->_windowHeight / 2.0F; + impl->_windowWidth = GameWindow::DefaultClientWidth; + impl->_windowHeight = GameWindow::DefaultClientHeight; + } void GameWindow::PlatformImplementation::Position(int width, int height, bool update) { _windowPosX = width; @@ -34,9 +31,8 @@ namespace xna { if(update) Update(); } - void GameWindow::Title(String const& title) { - if (!impl) return; - + void GameWindow::Title(String const& value) { + title = value; impl->_windowTitle = title; } @@ -92,6 +88,29 @@ namespace xna { return _windowHandle ? true : false; } + + // + // GameWindow + // + + gameWindow->handle = reinterpret_cast(_windowHandle); + gameWindow->title = _windowTitle; + gameWindow->clientBounds = { _windowPosX, _windowPosY, _windowWidth, _windowHeight }; + gameWindow->currentOrientation = DisplayOrientation::Default; + + auto screens = Screen::AllScreens(); + + if (screens.size() == 1) + gameWindow->screenDeviceName = screens[0]->DeviceName(); + else { + for (size_t i = 0; i < screens.size(); ++i) { + const auto& screen = screens[i]; + + if (screen->Primary()) + gameWindow->screenDeviceName = screen->DeviceName(); + } + } + return true; } @@ -118,30 +137,13 @@ namespace xna { return _windowHandle ? true : false; } + gameWindow->clientBounds = { _windowPosX, _windowPosY, _windowWidth, _windowHeight }; + return true; - } + } - String GameWindow::Title() const { - if (!impl) return String(); - - return impl->_windowTitle; - } - - Rectangle GameWindow::ClientBounds() const { - if (!impl) return {}; - - return Rectangle( - impl->_windowPosX, - impl->_windowPosY, - impl->_windowWidth, - impl->_windowHeight - ); - } - - intptr_t GameWindow::Handle() const { - if (!impl) return 0; - - return reinterpret_cast(impl->_windowHandle); + bool GameWindow::IsWindowMinimized() const { + return IsIconic(impl->_windowHandle); } LRESULT GameWindow::PlatformImplementation::WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) @@ -242,4 +244,9 @@ namespace xna { return screen; } + + String GameWindow::ScreenDeviceName() const { + //TODO + return std::string(); + } } \ No newline at end of file diff --git a/inc/xna/default.hpp b/inc/xna/default.hpp index f09f6a9..ad0327a 100644 --- a/inc/xna/default.hpp +++ b/inc/xna/default.hpp @@ -168,7 +168,6 @@ namespace xna { class Effect; class GraphicsAdapter; class GraphicsDevice; - class GraphicsDeviceInformation; struct PresentationParameters; class RenderTarget2D; class SwapChain; diff --git a/inc/xna/game/gdevicemanager.hpp b/inc/xna/game/gdevicemanager.hpp index 8406a64..3f68f8d 100644 --- a/inc/xna/game/gdevicemanager.hpp +++ b/inc/xna/game/gdevicemanager.hpp @@ -139,12 +139,8 @@ namespace xna { //Applies any changes to device-related properties, changing the graphics device as necessary. void ApplyChanges(); bool Initialize(); - bool ToggleFullScreen(); - - private: - void ChangeDevice(bool forceCreate){} - void AddDevices(bool anySuitableDevice, std::vector>& foundDevices); - void AddDevices(GraphicsAdapter const& adapter, DisplayMode const& mode, sptr& baseDeviceInfo, std::vector>& foundDevices) const; + bool ToggleFullScreen(); + protected: void CreateDevice(); @@ -159,6 +155,10 @@ namespace xna { } private: + void ChangeDevice(bool forceCreate); + void AddDevices(bool anySuitableDevice, std::vector>& foundDevices); + void AddDevices(GraphicsAdapter const& adapter, DisplayMode const& mode, sptr& baseDeviceInfo, std::vector>& foundDevices) const; + bool BeginDraw() override { return false; } void EndDraw() override{ } @@ -184,6 +184,7 @@ namespace xna { Int resizedBackBufferWidth{ 0 }; Int resizedBackBufferHeight{ 0 }; bool allowMultiSampling{ false }; + bool inDeviceTransition{ false }; std::vector> foundDevices; }; diff --git a/inc/xna/game/window.hpp b/inc/xna/game/window.hpp index 1ae2066..cbd6b13 100644 --- a/inc/xna/game/window.hpp +++ b/inc/xna/game/window.hpp @@ -9,14 +9,47 @@ namespace xna { class GameWindow { public: GameWindow(); - ~GameWindow(); - String Title() const; - void Title(String const& title); - Rectangle ClientBounds() const; - intptr_t Handle() const; + + //Gets the current display orientation, which reflects the physical orientation of the phone in the user's hand. + constexpr DisplayOrientation CurrentOrientation() const { + return currentOrientation; + } + + //Gets and sets the title of the system window. + constexpr String Title() const { + return title; + } + + //Gets and sets the title of the system window. + void Title(String const& value); + + //Gets the handle to the system window. + constexpr intptr_t Handle() const { + return handle; + } + + //The screen dimensions of the game window's client rectangle. + constexpr Rectangle ClientBounds() const { + return clientBounds; + } + + //Gets the device name of the screen the window is currently in. + String ScreenDeviceName() const; static uptr ScreenFromAdapter(GraphicsAdapter const& adapter); static uptr ScreenFromHandle(intptr_t windowHandle); + bool IsWindowMinimized() const; + + inline static constexpr Int DefaultClientWidth = 800; + inline static constexpr Int DefaultClientHeight = 600; + + private: + String title; + intptr_t handle{ 0 }; + Rectangle clientBounds{}; + String screenDeviceName; + DisplayOrientation currentOrientation{ DisplayOrientation::Default }; + public: struct PlatformImplementation; diff --git a/inc/xna/xna-dx.hpp b/inc/xna/xna-dx.hpp index 15d12bd..42486fa 100644 --- a/inc/xna/xna-dx.hpp +++ b/inc/xna/xna-dx.hpp @@ -698,6 +698,8 @@ namespace xna { struct GameWindow::PlatformImplementation { public: + PlatformImplementation(GameWindow* gameWindow): gameWindow(gameWindow){} + constexpr void Mode(GameWindowMode mode) { _windowStyle = static_cast(mode); } @@ -776,6 +778,7 @@ namespace xna { private: friend class GameWindow; + GameWindow*& gameWindow; HINSTANCE _hInstance{ nullptr }; HWND _windowHandle{ nullptr };