diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt index 770b414..afe3bc1 100644 --- a/framework/CMakeLists.txt +++ b/framework/CMakeLists.txt @@ -13,26 +13,18 @@ add_executable (xna WIN32 "platform/texture-dx.cpp" "platform/blendstate-dx.cpp" "platform/game-dx.cpp" - "csharp/stream.cpp" "platform/gdevicemanager-dx.cpp" - "platform/shader-dx.cpp" "platform/rasterizerstate-dx.cpp" - - - - "platform/samplerstate-dx.cpp" "platform/sprite-dx.cpp" - "platform/depthstencilstate-dx.cpp" "platform/keyboard-dx.cpp" "platform/mouse-dx.cpp" "platform/gamepad-dx.cpp" "platform/soundeffect-dx.cpp" "platform/displaymode-dx.cpp" - "game/component.cpp" "content/manager.cpp" "content/reader.cpp" @@ -47,7 +39,9 @@ add_executable (xna WIN32 "common/color.cpp" "common/collision.cpp" "common/gjk.cpp" -"common/numerics.cpp" "common/packedvalue.cpp" "platform/buffer.cpp") +"common/numerics.cpp" +"common/packedvalue.cpp" +"platform/buffer.cpp" ) if (CMAKE_VERSION VERSION_GREATER 3.12) set_property(TARGET xna PROPERTY CXX_STANDARD 20) diff --git a/framework/platform/device-dx.cpp b/framework/platform/device-dx.cpp index 251b131..133762a 100644 --- a/framework/platform/device-dx.cpp +++ b/framework/platform/device-dx.cpp @@ -3,11 +3,9 @@ #include "graphics/blendstate.hpp" #include "graphics/rendertarget.hpp" #include "platform-dx/device-dx.hpp" -#include "platform-dx/gdeviceinfo-dx.hpp" #include "platform-dx/gdevicemanager-dx.hpp" #include "platform-dx/implementations.hpp" -#include "platform-dx/window-dx.hpp" -#include "platform-dx/implementations.hpp" +#include "game/gdeviceinfo.hpp" namespace xna { GraphicsDevice::GraphicsDevice() { @@ -16,12 +14,12 @@ namespace xna { } GraphicsDevice::GraphicsDevice(GraphicsDeviceInformation const& info) { - _adapter = info.Adapter(); - _presentationParameters = info.PresentationParameters(); + _adapter = info.Adapter; + _presentationParameters = info.Parameters; _adapter->CurrentDisplayMode( - _presentationParameters.BackBufferFormat, - _presentationParameters.BackBufferWidth, - _presentationParameters.BackBufferHeight); + _presentationParameters->BackBufferFormat, + _presentationParameters->BackBufferWidth, + _presentationParameters->BackBufferHeight); } bool GraphicsDevice::Initialize(GameWindow& gameWindow) { @@ -41,7 +39,7 @@ namespace xna { static_cast(bounds.Height), 0.0F, 1.F); - COLORREF color = gameWindow.Color(); + COLORREF color = gameWindow.impl->Color(); _backgroundColor[0] = GetRValue(color) / 255.0f; _backgroundColor[1] = GetGValue(color) / 255.0f; _backgroundColor[2] = GetBValue(color) / 255.0f; @@ -50,7 +48,7 @@ namespace xna { _swapChain = New(_this); _swapChain->Initialize(); - hr = _factory->MakeWindowAssociation(gameWindow.WindowHandle(), DXGI_MWA_NO_ALT_ENTER); + hr = _factory->MakeWindowAssociation(gameWindow.impl->WindowHandle(), DXGI_MWA_NO_ALT_ENTER); if (FAILED(hr)) return false; _renderTarget2D = New(_this); diff --git a/framework/platform/game-dx.cpp b/framework/platform/game-dx.cpp index f52fdf7..d90a3bf 100644 --- a/framework/platform/game-dx.cpp +++ b/framework/platform/game-dx.cpp @@ -1,11 +1,9 @@ #include "csharp/type.hpp" #include "game/time.hpp" #include "platform-dx/audioengine-dx.hpp" -#include "platform-dx/device-dx.hpp" #include "platform-dx/game-dx.hpp" #include "platform-dx/gdevicemanager-dx.hpp" #include "platform-dx/implementations.hpp" -#include "platform-dx/window-dx.hpp" namespace xna { Game::Game() { @@ -13,9 +11,9 @@ namespace xna { _contentManager = New("", services); _gameWindow = New(); - _gameWindow->Color(146, 150, 154); + _gameWindow->impl->Color(146, 150, 154); _gameWindow->Title("XN65"); - _gameWindow->Size( + _gameWindow->impl->Size( GraphicsDeviceManager::DefaultBackBufferWidth, GraphicsDeviceManager::DefaultBackBufferHeight, false); @@ -23,7 +21,7 @@ namespace xna { } void Game::Exit() { - _gameWindow->Close(); + _gameWindow->impl->Close(); } int Game::Run() { diff --git a/framework/platform/gdevicemanager-dx.cpp b/framework/platform/gdevicemanager-dx.cpp index 5d61b0e..99c72ff 100644 --- a/framework/platform/gdevicemanager-dx.cpp +++ b/framework/platform/gdevicemanager-dx.cpp @@ -1,8 +1,6 @@ #include "platform-dx/gdevicemanager-dx.hpp" #include "platform-dx/device-dx.hpp" #include "platform-dx/game-dx.hpp" -#include "platform-dx/window-dx.hpp" -#include "platform-dx/gdeviceinfo-dx.hpp" #include "graphics/presentparams.hpp" #include "graphics/swapchain.hpp" #include "platform-dx/implementations.hpp" @@ -10,17 +8,18 @@ namespace xna { GraphicsDeviceManager::GraphicsDeviceManager(Game*& game) : _game(game) { sptr adp = GraphicsAdapter::DefaultAdapter(); - _information.Adapter(adp); - _information.GraphicsProfile(xna::GraphicsProfile::HiDef); + _information.Adapter = adp; + _information.Profile = xna::GraphicsProfile::HiDef; - PresentationParameters parameters; - parameters.BackBufferWidth = _backBufferWidth; - parameters.BackBufferHeight = _backBufferHeight; - parameters.BackBufferFormat = SurfaceFormat::Color; - parameters.Fullscreen = false; - _information.PresentationParameters(parameters); + auto parameters = snew(); + parameters->BackBufferWidth = _backBufferWidth; + parameters->BackBufferHeight = _backBufferHeight; + parameters->BackBufferFormat = SurfaceFormat::Color; + parameters->Fullscreen = false; + _information.Parameters = parameters; - if(_game) _information.Window(_game->Window()); + if(_game) + _information.Window =_game->Window(); } bool GraphicsDeviceManager::Initialize() { @@ -65,8 +64,8 @@ namespace xna { bool GraphicsDeviceManager::CreateDevice() { if (_isDeviceDirty) { - _information._parameters.BackBufferWidth = _backBufferWidth; - _information._parameters.BackBufferHeight = _backBufferHeight; + _information.Parameters->BackBufferWidth = _backBufferWidth; + _information.Parameters->BackBufferHeight = _backBufferHeight; } auto result = initWindow(); @@ -81,32 +80,32 @@ namespace xna { bool GraphicsDeviceManager::initWindow() { - auto window = _information.Window(); + auto window = _information.Window; if (!window) { window = _game->Window(); - _information.Window(window); + _information.Window = window; } - window->Size(_backBufferWidth, _backBufferHeight); + window->impl->Size(_backBufferWidth, _backBufferHeight); - if (!window->Create()) { + if (!window->impl->Create()) { MessageBox(nullptr, "Falha na criação da janela", "XN65", MB_OK); return false; } - _information._parameters.DeviceWindowHandle = reinterpret_cast(window->WindowHandle()); + _information.Parameters->DeviceWindowHandle = reinterpret_cast(window->impl->WindowHandle()); return true; } bool GraphicsDeviceManager::initDevice() { - auto window = _information.Window(); + auto window = _information.Window; _device = New(_information); if (!_device->Initialize(*window)) { - MessageBox(window->WindowHandle(), "Falha na inicialização do dispositivo gráfico", "XN65", MB_OK); + MessageBox(window->impl->WindowHandle(), "Falha na inicialização do dispositivo gráfico", "XN65", MB_OK); _device = nullptr; return false; } diff --git a/framework/platform/swapchain-dx.cpp b/framework/platform/swapchain-dx.cpp index 6205414..8b2202e 100644 --- a/framework/platform/swapchain-dx.cpp +++ b/framework/platform/swapchain-dx.cpp @@ -59,23 +59,23 @@ namespace xna { const auto parameters = m_device->_presentationParameters; - impl->dxDescription.Width = static_cast(parameters.BackBufferWidth); - impl->dxDescription.Height = static_cast(parameters.BackBufferHeight); - impl->dxDescription.Format = DxHelpers::ConvertSurfaceToDXGIFORMAT(parameters.BackBufferFormat); + impl->dxDescription.Width = static_cast(parameters->BackBufferWidth); + impl->dxDescription.Height = static_cast(parameters->BackBufferHeight); + impl->dxDescription.Format = DxHelpers::ConvertSurfaceToDXGIFORMAT(parameters->BackBufferFormat); impl->dxDescription.SampleDesc.Count = 1; impl->dxDescription.SampleDesc.Quality = 0; impl->dxDescription.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; impl->dxDescription.BufferCount = 2; - impl->dxDescription.SwapEffect = static_cast(parameters.PresentationSwapEffect); + impl->dxDescription.SwapEffect = static_cast(parameters->PresentationSwapEffect); impl->dxDescription.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; impl->dxDescription.AlphaMode = DXGI_ALPHA_MODE::DXGI_ALPHA_MODE_UNSPECIFIED; impl->dxFullScreenDescription.RefreshRate.Numerator = 60; impl->dxFullScreenDescription.RefreshRate.Denominator = 1; impl->dxFullScreenDescription.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; impl->dxFullScreenDescription.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; - impl->dxFullScreenDescription.Windowed = !parameters.Fullscreen; + impl->dxFullScreenDescription.Windowed = !parameters->Fullscreen; - HWND hwnd = reinterpret_cast(parameters.DeviceWindowHandle); + HWND hwnd = reinterpret_cast(parameters->DeviceWindowHandle); return internalInit(*m_device, hwnd, impl->dxSwapChain, impl->dxDescription, impl->dxFullScreenDescription); } diff --git a/framework/platform/window-dx.cpp b/framework/platform/window-dx.cpp index 1573e5b..f365ae4 100644 --- a/framework/platform/window-dx.cpp +++ b/framework/platform/window-dx.cpp @@ -1,19 +1,23 @@ -#include "platform-dx/window-dx.hpp" -#include "input/gamepad.hpp" #include "platform-dx/implementations.hpp" namespace xna { GameWindow::GameWindow() { - _hInstance = GetModuleHandle(NULL); - _windowIcon = LoadIcon(NULL, IDI_APPLICATION); - _windowCursor = LoadCursor(NULL, IDC_ARROW); - _windowStyle = static_cast(GameWindowMode::Windowed); - _windowCenterX = _windowWidth / 2.0F; - _windowCenterY = _windowHeight / 2.0F; + impl = unew(); + + 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; } - void GameWindow::Position(int width, int height, bool update) { + GameWindow::~GameWindow() { + impl = nullptr; + } + + void GameWindow::PlatformImplementation::Position(int width, int height, bool update) { _windowPosX = width; _windowPosY = height; setCenter(); @@ -21,7 +25,7 @@ namespace xna { if(update) Update(); } - void GameWindow::Size(int width, int height, bool update) { + void GameWindow::PlatformImplementation::Size(int width, int height, bool update) { _windowWidth = width; _windowHeight = height; setPosition(); @@ -31,10 +35,12 @@ namespace xna { } void GameWindow::Title(String const& title) { - _windowTitle = title; + if (!impl) return; + + impl->_windowTitle = title; } - bool GameWindow::Create() { + bool GameWindow::PlatformImplementation::Create() { WNDCLASSEX wndClass{}; wndClass.cbSize = sizeof(WNDCLASSEX); wndClass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; @@ -89,7 +95,7 @@ namespace xna { return true; } - bool GameWindow::Update() { + bool GameWindow::PlatformImplementation::Update() { if (_windowStyle == static_cast(GameWindowMode::Windowed)) { RECT winRect = { 0, 0, _windowWidth, _windowHeight }; @@ -116,23 +122,29 @@ namespace xna { } String GameWindow::Title() const { - return _windowTitle; + if (!impl) return String(); + + return impl->_windowTitle; } Rectangle GameWindow::ClientBounds() const { + if (!impl) return {}; + return Rectangle( - _windowPosX, - _windowPosY, - _windowWidth, - _windowHeight + impl->_windowPosX, + impl->_windowPosY, + impl->_windowWidth, + impl->_windowHeight ); } intptr_t GameWindow::Handle() const { - return reinterpret_cast(_windowHandle); + if (!impl) return 0; + + return reinterpret_cast(impl->_windowHandle); } - LRESULT GameWindow::WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) + LRESULT GameWindow::PlatformImplementation::WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_DESTROY: @@ -140,18 +152,18 @@ namespace xna { return 0; case WM_ACTIVATE: case WM_ACTIVATEAPP: - Keyboard::impl->ProcessMessage(msg, wParam, lParam); - Mouse::impl->ProcessMessage(msg, wParam, lParam); + if(Keyboard::impl) Keyboard::impl->ProcessMessage(msg, wParam, lParam); + if(Mouse::impl) Mouse::impl->ProcessMessage(msg, wParam, lParam); break; case WM_SYSKEYDOWN: if (!(wParam == VK_RETURN && (lParam & 0x60000000) == 0x20000000)) { - Keyboard::impl->ProcessMessage(msg, wParam, lParam); + if (Keyboard::impl) Keyboard::impl->ProcessMessage(msg, wParam, lParam); } break; case WM_KEYDOWN: case WM_KEYUP: case WM_SYSKEYUP: - Keyboard::impl->ProcessMessage(msg, wParam, lParam); + if (Keyboard::impl) Keyboard::impl->ProcessMessage(msg, wParam, lParam); break; case WM_INPUT: @@ -166,13 +178,13 @@ namespace xna { case WM_XBUTTONDOWN: case WM_XBUTTONUP: case WM_MOUSEHOVER: - Mouse::impl->ProcessMessage(msg, wParam, lParam); + if (Mouse::impl) Mouse::impl->ProcessMessage(msg, wParam, lParam); break; case WM_KILLFOCUS: - GamePad::impl->Suspend(); + if (GamePad::impl) GamePad::impl->Suspend(); break; case WM_SETFOCUS: - GamePad::impl->Resume(); + if (GamePad::impl) GamePad::impl->Resume(); break; } return DefWindowProc(hWnd, msg, wParam, lParam); diff --git a/inc/game/gdeviceinfo.hpp b/inc/game/gdeviceinfo.hpp index bb8661f..f815e5f 100644 --- a/inc/game/gdeviceinfo.hpp +++ b/inc/game/gdeviceinfo.hpp @@ -1,21 +1,15 @@ #ifndef XNA_GAME_GDEVICEINFO_HPP #define XNA_GAME_GDEVICEINFO_HPP -#include "../forward.hpp" -#include "../enums.hpp" +#include "../default.hpp" namespace xna { - class IGraphicsDeviceInformation { + class GraphicsDeviceInformation { public: - virtual ~IGraphicsDeviceInformation(){} - virtual sptr Adapter() const = 0; - virtual void Adapter(sptr const& value) = 0; - virtual xna::PresentationParameters PresentationParameters() const = 0; - virtual void PresentationParameters(xna::PresentationParameters const& value) = 0; - virtual xna::GraphicsProfile GraphicsProfile() const = 0; - virtual void GraphicsProfile(xna::GraphicsProfile value) = 0; - virtual sptr Window() const = 0; - virtual void Window(sptr const& window) = 0; + sptr Adapter = nullptr; + xna::GraphicsProfile Profile{ xna::GraphicsProfile::Reach }; + sptr Parameters = nullptr; + sptr Window = nullptr; }; } diff --git a/inc/game/window.hpp b/inc/game/window.hpp index 163cfb0..7dc99eb 100644 --- a/inc/game/window.hpp +++ b/inc/game/window.hpp @@ -1,18 +1,22 @@ #ifndef XNA_GAME_WINDOW_HPP #define XNA_GAME_WINDOW_HPP -#include "../enums.hpp" +#include "../default.hpp" #include "../common/numerics.hpp" namespace xna { - class IGameWindow { + class GameWindow { public: - virtual ~IGameWindow(){} + GameWindow(); + ~GameWindow(); + String Title() const; + void Title(String const& title); + Rectangle ClientBounds() const; + intptr_t Handle() const; - virtual String Title() const = 0; - virtual void Title(String const& title) = 0; - virtual Rectangle ClientBounds() const = 0; - virtual intptr_t Handle() const = 0; + public: + struct PlatformImplementation; + uptr impl = nullptr; }; } diff --git a/inc/input/gamepad.hpp b/inc/input/gamepad.hpp index b2c32a1..55d5f39 100644 --- a/inc/input/gamepad.hpp +++ b/inc/input/gamepad.hpp @@ -153,7 +153,7 @@ namespace xna { bool Connected{ false }; Ushort Vid{ 0 }; Ushort Pid{ 0 }; - GamePadId Id; + GamePadId Id{}; }; struct GamePadState { diff --git a/inc/platform-dx/device-dx.hpp b/inc/platform-dx/device-dx.hpp index e80e2ac..2d9b679 100644 --- a/inc/platform-dx/device-dx.hpp +++ b/inc/platform-dx/device-dx.hpp @@ -6,9 +6,7 @@ #include "../graphics/presentparams.hpp" #include "../graphics/viewport.hpp" #include "dxheaders.hpp" -#include "gdeviceinfo-dx.hpp" -#include "window-dx.hpp" -#include "graphics/presentparams.hpp" +#include "game/gdeviceinfo.hpp" namespace xna { class GraphicsDevice : public IGraphicsDevice, public std::enable_shared_from_this { @@ -77,7 +75,7 @@ namespace xna { sptr _renderTarget2D{ nullptr }; sptr _blendState{ nullptr }; xna::Viewport _viewport{}; - xna::PresentationParameters _presentationParameters; + sptr _presentationParameters; private: unsigned int _createDeviceFlags{ 0 }; diff --git a/inc/platform-dx/dxheaders.hpp b/inc/platform-dx/dxheaders.hpp index c08436a..6009b28 100644 --- a/inc/platform-dx/dxheaders.hpp +++ b/inc/platform-dx/dxheaders.hpp @@ -30,6 +30,7 @@ //Windows #define NOMINMAX #include +#include #include #include #include \ No newline at end of file diff --git a/inc/platform-dx/gdeviceinfo-dx.hpp b/inc/platform-dx/gdeviceinfo-dx.hpp deleted file mode 100644 index a5e760a..0000000 --- a/inc/platform-dx/gdeviceinfo-dx.hpp +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef XNA_PLATFORM_GDEVICEINFOR_DX_HPP -#define XNA_PLATFORM_GDEVICEINFOR_DX_HPP - -#include "../game/gdeviceinfo.hpp" -#include "window-dx.hpp" -#include "graphics/presentparams.hpp" - -namespace xna { - class GraphicsDeviceInformation : public IGraphicsDeviceInformation { - public: - virtual ~GraphicsDeviceInformation() override {} - - inline virtual sptr Adapter() const override { - return _adapter; - }; - - inline virtual void Adapter(sptr const& value) override { - _adapter = value; - } - - virtual xna::PresentationParameters PresentationParameters() const override{ - return _parameters; - }; - - virtual void PresentationParameters(xna::PresentationParameters const& value) override{ - _parameters = value; - }; - - virtual xna::GraphicsProfile GraphicsProfile() const override { - return _profile; - }; - - virtual void GraphicsProfile(xna::GraphicsProfile value) override { - _profile = value; - }; - - inline virtual sptr Window() const override { - return _window; - } - - inline virtual void Window(sptr const& window) override { - _window = window; - } - - public: - sptr _adapter{ nullptr }; - xna::GraphicsProfile _profile{xna::GraphicsProfile::Reach}; - xna::PresentationParameters _parameters{}; - sptr _window{ nullptr }; - }; -} - -#endif \ No newline at end of file diff --git a/inc/platform-dx/gdevicemanager-dx.hpp b/inc/platform-dx/gdevicemanager-dx.hpp index d6d7e07..1ba3e0e 100644 --- a/inc/platform-dx/gdevicemanager-dx.hpp +++ b/inc/platform-dx/gdevicemanager-dx.hpp @@ -2,7 +2,7 @@ #define XNA_PLATFORM_GDEVICEMANAGER_DX_HPP #include "../game/gdevicemanager.hpp" -#include "gdeviceinfo-dx.hpp" +#include "game/gdeviceinfo.hpp" namespace xna { class GraphicsDeviceManager : public IGraphicsDeviceManager { diff --git a/inc/platform-dx/implementations.hpp b/inc/platform-dx/implementations.hpp index 03a5d02..30d6ed2 100644 --- a/inc/platform-dx/implementations.hpp +++ b/inc/platform-dx/implementations.hpp @@ -2,11 +2,11 @@ #define XNA_PLATFORM_DX_IMPLEMENTATIONS_HPP #include "dxheaders.hpp" +#include "platform-dx/device-dx.hpp" #include "graphics/adapter.hpp" #include "graphics/blendstate.hpp" #include "graphics/buffer.hpp" #include "graphics/depthstencilstate.hpp" -#include "graphics/device.hpp" #include "graphics/displaymode.hpp" #include "graphics/sprite.hpp" #include "graphics/samplerstate.hpp" @@ -19,7 +19,7 @@ #include "graphics/swapchain.hpp" #include "graphics/texture.hpp" #include "graphics/rendertarget.hpp" -#include "device-dx.hpp" +#include "game/window.hpp" namespace xna { struct SpriteFont::PlatformImplementation { @@ -345,6 +345,118 @@ namespace xna { ID3D11InputLayout* _inputLayout{ nullptr }; std::vector _description{}; }; + + enum class GameWindowMode : UINT { + Fullscreen = WS_POPUP | WS_VISIBLE, + Windowed = WS_OVERLAPPED | WS_SYSMENU | WS_VISIBLE, + Borderless = WS_EX_TOPMOST | WS_POPUP | WS_VISIBLE, + }; + + struct GameWindow::PlatformImplementation { + public: + constexpr void Mode(GameWindowMode mode) { + _windowStyle = static_cast(mode); + } + + constexpr GameWindowMode Mode() const { + return static_cast(_windowStyle); + } + + void Position(int width, int height, bool update = true); + void Size(int width, int height, bool update = true); + + inline HINSTANCE HInstance() const { + return _hInstance; + } + + inline HWND WindowHandle() const { + return _windowHandle; + } + + constexpr int Width() const { + return _windowWidth; + } + + constexpr int Height() const { + return _windowHeight; + } + + inline void Icon(unsigned int icon) { + _windowIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(icon)); + } + + inline void Icon(HICON icon) { + _windowIcon = icon; + } + + inline void Cursor(unsigned int cursor) { + _windowCursor = LoadCursor(GetModuleHandle(NULL), MAKEINTRESOURCE(cursor)); + } + + inline void Cursor(HCURSOR cursor) { + _windowCursor = cursor; + } + + constexpr float CenterX() const { + return _windowCenterX; + } + + constexpr float CenterY() const { + return _windowCenterY; + } + + inline void CursorVisibility(bool visible) const { + ShowCursor(visible); + } + + inline void Close() { + PostMessage(_windowHandle, WM_DESTROY, 0, 0); + } + + constexpr COLORREF Color() const { + return _windowColor; + } + + constexpr void Color(COLORREF color) { + _windowColor = color; + } + + constexpr void Color(BYTE r, BYTE g, BYTE b) { + _windowColor = RGB(r, g, b); + } + + bool Create(); + bool Update(); + + static LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + + private: + friend class GameWindow; + + HINSTANCE _hInstance{ nullptr }; + HWND _windowHandle{ nullptr }; + int _windowWidth{ 800 }; + int _windowHeight{ 600 }; + HICON _windowIcon{ nullptr }; + HCURSOR _windowCursor{ nullptr }; + COLORREF _windowColor{ RGB(0,0,0) }; + String _windowTitle{ "Xna++ Game Development" }; + DWORD _windowStyle{ 0 }; + int _windowPosX{ 0 }; + int _windowPosY{ 0 }; + float _windowCenterX{ 0 }; + float _windowCenterY{ 0 }; + + inline void setPosition() { + _windowPosX = GetSystemMetrics(SM_CXSCREEN) / 2 - _windowWidth / 2; + _windowPosY = GetSystemMetrics(SM_CYSCREEN) / 2 - _windowHeight / 2; + } + + inline void setCenter() { + _windowCenterX = _windowWidth / 2.0f; + _windowCenterY = _windowHeight / 2.0f; + } + }; } #endif \ No newline at end of file diff --git a/inc/platform-dx/window-dx.hpp b/inc/platform-dx/window-dx.hpp deleted file mode 100644 index ef04c73..0000000 --- a/inc/platform-dx/window-dx.hpp +++ /dev/null @@ -1,129 +0,0 @@ -#ifndef XNA_PLATFORM_WINDOW_DX_HPP -#define XNA_PLATFORM_WINDOW_DX_HPP - -#include "../game/window.hpp" -#include -#include - -namespace xna { - - enum class GameWindowMode : UINT { - Fullscreen = WS_POPUP | WS_VISIBLE, - Windowed = WS_OVERLAPPED | WS_SYSMENU | WS_VISIBLE, - Borderless = WS_EX_TOPMOST | WS_POPUP | WS_VISIBLE, - }; - - class GameWindow : public IGameWindow { - public: - GameWindow(); - - constexpr void Mode(GameWindowMode mode) { - _windowStyle = static_cast(mode); - } - - constexpr GameWindowMode Mode() const { - return static_cast(_windowStyle); - } - - void Position(int width, int height, bool update = true); - void Size(int width, int height, bool update = true); - - inline HINSTANCE HInstance() const { - return _hInstance; - } - - inline HWND WindowHandle() const { - return _windowHandle; - } - - inline int Width() const { - return _windowWidth; - } - - inline int Height() const { - return _windowHeight; - } - - inline void Icon(unsigned int icon) { - _windowIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(icon)); - } - - inline void Icon(HICON icon) { - _windowIcon = icon; - } - - inline void Cursor(unsigned int cursor) { - _windowCursor = LoadCursor(GetModuleHandle(NULL), MAKEINTRESOURCE(cursor)); - } - - inline void Cursor(HCURSOR cursor) { - _windowCursor = cursor; - } - - inline float CenterX() const { - return _windowCenterX; - } - - inline float CenterY() const { - return _windowCenterY; - } - - inline void CursorVisibility(bool visible) const { - ShowCursor(visible); - } - - inline void Close() { - PostMessage(_windowHandle, WM_DESTROY, 0, 0); - } - - inline COLORREF Color() const { - return _windowColor; - } - - inline void Color(COLORREF color) { - _windowColor = color; - } - - inline void Color(BYTE r, BYTE g, BYTE b) { - _windowColor = RGB(r, g, b); - } - - bool Create(); - bool Update(); - - static LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); - - virtual String Title() const override; - virtual void Title(String const& title) override; - virtual Rectangle ClientBounds() const override; - virtual intptr_t Handle() const override; - - private: - HINSTANCE _hInstance{ nullptr }; - HWND _windowHandle{ nullptr }; - int _windowWidth{ 800 }; - int _windowHeight{ 600 }; - HICON _windowIcon{ nullptr }; - HCURSOR _windowCursor{ nullptr }; - COLORREF _windowColor{ RGB(0,0,0) }; - String _windowTitle{ "Xna++ Game Development" }; - DWORD _windowStyle{ 0 }; - int _windowPosX{ 0 }; - int _windowPosY{ 0 }; - float _windowCenterX{ 0 }; - float _windowCenterY{ 0 }; - - private: - inline void setPosition() { - _windowPosX = GetSystemMetrics(SM_CXSCREEN) / 2 - _windowWidth / 2; - _windowPosY = GetSystemMetrics(SM_CYSCREEN) / 2 - _windowHeight / 2; - } - - inline void setCenter() { - _windowCenterX = _windowWidth / 2.0f; - _windowCenterY = _windowHeight / 2.0f; - } - }; -} - -#endif \ No newline at end of file diff --git a/inc/platform-dx/xna-dx.hpp b/inc/platform-dx/xna-dx.hpp index ad91760..357d37d 100644 --- a/inc/platform-dx/xna-dx.hpp +++ b/inc/platform-dx/xna-dx.hpp @@ -4,9 +4,7 @@ #include "dx/StepTimer.hpp" #include "dxheaders.hpp" #include "game-dx.hpp" -#include "gdeviceinfo-dx.hpp" #include "gdevicemanager-dx.hpp" #include "init-dx.hpp" #include "soundeffect-dx.hpp" -#include "window-dx.hpp" #include "implementations.hpp" \ No newline at end of file