/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #pragma once #include #include "../PlatformEnums.hpp" #include "../ICloseable.hpp" #include #include namespace openVulkanoCpp { enum WindowMode { WINDOWED = 0, BORDERLESS = 1, FULLSCREEN = 2, BORDERLESS_FULLSCREEN = 3 }; class IWindowHandler; class IVulkanWindow; class IOpenGlWindow; struct WindowConfiguration { uint32_t width = 1280, height = 720; int posX = 0, posY = 0; std::string title = "Window Title"; WindowMode windowMode = WINDOWED; }; class IWindow : public ICloseable { public: virtual ~IWindow() = default; virtual void Init(RenderAPI::RenderApi renderApi) = 0; virtual bool HasTitle() = 0; virtual const std::string& GetTitle() = 0; virtual void SetTitle(const std::string& title) = 0; virtual WindowMode GetWindowMode() = 0; virtual void SetWindowMode(WindowMode) = 0; virtual void SetFullscreen() { SetWindowMode(FULLSCREEN); } virtual void SetWindowed() { SetWindowMode(WINDOWED); } virtual const WindowConfiguration& GetWindowConfiguration() = 0; virtual uint32_t GetWidth() = 0; virtual uint32_t GetHeight() = 0; virtual void GetSize(int* width, int* height) = 0; virtual void GetSize(uint32_t* width, uint32_t* height) = 0; virtual glm::ivec2 GetSize() = 0; virtual void SetSize(uint32_t width, uint32_t height) = 0; virtual void SetSize(glm::ivec2 size) { SetSize(size.x, size.y); } virtual void SetSizeLimits(int minWidth, int minHeight, int maxWidth, int maxHeight) = 0; virtual int GetPositionX() = 0; virtual int GetPositionY() = 0; virtual void GetPosition(int* x, int* y) = 0; virtual glm::ivec2 GetPosition() = 0; virtual void SetPosition(int posX, int posY) = 0; virtual void SetPosition(glm::ivec2 pos) = 0; virtual void Show() = 0; virtual void Hide() = 0; virtual void Show(bool show) = 0; virtual IWindowHandler* GetWindowHandler() = 0; virtual void SetWindowHandler(IWindowHandler* handler) = 0; /** * \brief Gets the vulkan window implementation of the window. * \return The IVulkanWindow reference of the window. nullptr if the current Window dose not implement IVulkanWindow */ virtual IVulkanWindow* GetVulkanWindow() = 0; virtual IOpenGlWindow* GetOpenGlWindow() = 0; [[nodiscard]] virtual uint32_t GetWindowId() const = 0; protected: static uint32_t CreateWindowId() { static uint32_t id = 0; return id++; } }; class IWindowHandler { public: virtual ~IWindowHandler() = default; virtual void OnWindowMinimize(IWindow* window) = 0; virtual void OnWindowRestore(IWindow* window) = 0; virtual void OnWindowFocusLost(IWindow* window) = 0; virtual void OnWindowFocusGained(IWindow* window) = 0; virtual void OnWindowMove(IWindow* window, int posX, int posY) = 0; virtual void OnWindowResize(IWindow* window, uint32_t newWidth, uint32_t newHeight) = 0; virtual void OnWindowClose(IWindow* window) = 0; }; class WindowInitFailedException : public std::runtime_error { public: WindowInitFailedException(char const* const message) : runtime_error(message) {} }; }