feat: Add window class
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include <destrum/Window.h>
|
||||
#include <destrum/Graphics/GfxDevice.h>
|
||||
#include <destrum/Graphics/Renderer.h>
|
||||
#include <destrum/Graphics/Pipelines/ImguiPass.h>
|
||||
@@ -25,6 +26,8 @@ public:
|
||||
std::string windowTitle;
|
||||
std::filesystem::path exeDir;
|
||||
bool showDebugUi{true};
|
||||
WindowMode windowMode{WindowMode::Windowed};
|
||||
bool startMaximized{false};
|
||||
};
|
||||
|
||||
App();
|
||||
@@ -46,7 +49,7 @@ public:
|
||||
virtual void customWindowsMenu() {}
|
||||
|
||||
protected:
|
||||
SDL_Window* window{nullptr};
|
||||
Window window;
|
||||
AppParams m_params{};
|
||||
|
||||
GfxDevice gfxDevice;
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
#ifndef DESTRUM_WINDOW_H
|
||||
#define DESTRUM_WINDOW_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include <glm/vec2.hpp>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
enum class WindowMode {
|
||||
Windowed,
|
||||
Fullscreen,
|
||||
BorderlessFullscreen,
|
||||
};
|
||||
|
||||
struct WindowDesc {
|
||||
std::string title{"Destrum"};
|
||||
glm::ivec2 size{1280, 720};
|
||||
glm::ivec2 minimumSize{320, 180};
|
||||
WindowMode mode{WindowMode::Windowed};
|
||||
bool resizable{true};
|
||||
bool maximized{false};
|
||||
};
|
||||
|
||||
class Window final {
|
||||
public:
|
||||
Window() = default;
|
||||
~Window();
|
||||
|
||||
Window(const Window&) = delete;
|
||||
Window& operator=(const Window&) = delete;
|
||||
Window(Window&&) = delete;
|
||||
Window& operator=(Window&&) = delete;
|
||||
|
||||
void Create(const WindowDesc& desc);
|
||||
void Destroy();
|
||||
|
||||
void ProcessEvent(const SDL_Event& event);
|
||||
[[nodiscard]] bool ConsumeResized();
|
||||
[[nodiscard]] bool ConsumeCloseRequested();
|
||||
|
||||
[[nodiscard]] bool IsCreated() const { return m_Handle != nullptr; }
|
||||
[[nodiscard]] SDL_Window* GetHandle() const { return m_Handle; }
|
||||
[[nodiscard]] std::uint32_t GetId() const;
|
||||
|
||||
void SetTitle(std::string_view title);
|
||||
[[nodiscard]] std::string GetTitle() const;
|
||||
|
||||
void SetSize(const glm::ivec2& size);
|
||||
[[nodiscard]] glm::ivec2 GetSize() const;
|
||||
[[nodiscard]] glm::ivec2 GetDrawableSize() const;
|
||||
[[nodiscard]] float GetAspectRatio() const;
|
||||
void SetMinimumSize(const glm::ivec2& size);
|
||||
void SetMaximumSize(const glm::ivec2& size);
|
||||
|
||||
void SetPosition(const glm::ivec2& position);
|
||||
[[nodiscard]] glm::ivec2 GetPosition() const;
|
||||
void Center();
|
||||
|
||||
void Maximize();
|
||||
void Minimize();
|
||||
void Restore();
|
||||
void ToggleMaximized();
|
||||
[[nodiscard]] bool IsMaximized() const;
|
||||
[[nodiscard]] bool IsMinimized() const;
|
||||
|
||||
void SetMode(WindowMode mode);
|
||||
[[nodiscard]] WindowMode GetMode() const;
|
||||
void ToggleFullscreen();
|
||||
[[nodiscard]] bool IsFullscreen() const { return GetMode() != WindowMode::Windowed; }
|
||||
|
||||
void SetResizable(bool resizable);
|
||||
[[nodiscard]] bool IsResizable() const;
|
||||
void SetBordered(bool bordered);
|
||||
[[nodiscard]] bool IsBordered() const;
|
||||
void SetAlwaysOnTop(bool alwaysOnTop);
|
||||
|
||||
void Show();
|
||||
void Hide();
|
||||
void Focus();
|
||||
[[nodiscard]] bool IsVisible() const;
|
||||
[[nodiscard]] bool HasFocus() const;
|
||||
|
||||
[[nodiscard]] int GetDisplayIndex() const;
|
||||
[[nodiscard]] glm::ivec2 GetDisplaySize() const;
|
||||
|
||||
private:
|
||||
[[nodiscard]] std::uint32_t getFlags() const;
|
||||
[[nodiscard]] SDL_Window* requireHandle() const;
|
||||
|
||||
SDL_Window* m_Handle{nullptr};
|
||||
bool m_Resized{false};
|
||||
bool m_CloseRequested{false};
|
||||
};
|
||||
|
||||
#endif // DESTRUM_WINDOW_H
|
||||
Reference in New Issue
Block a user