Foray Library
rapid prototyping framework for crossplatform development of vulkan hardware ray tracing applications
Loading...
Searching...
No Matches
foray_window.hpp
Go to the documentation of this file.
1#pragma once
2#include "../foray_basics.hpp"
3#include "../foray_vulkan.hpp"
4#include "foray_helpers.hpp"
6#include <memory>
7#include <sdl2/SDL.h>
8#include <sdl2/SDL_vulkan.h>
9#include <string>
10#include <vector>
11
12namespace foray::osi {
14 class Window
15 {
16 public:
17 static const int32_t WINDOWPOS_AUTO = INT32_MAX;
18
19 static std::vector<Window*>& Windows();
20
21 static Window* FindBySDLId(uint32_t id);
22
24
25 Window(const Window& other) = delete;
26 Window(const Window&& other) = delete;
27 void operator=(const Window& other) = delete;
28 virtual ~Window();
29
32 inline bool Exists() const { return mHandle != nullptr; }
34 virtual void Create();
36 virtual void Destroy();
37
39 inline const std::string& Title() const { return mTitle; };
42 void Title(const std::string& title);
45 inline VkExtent2D Size() const { return (mDisplayMode > EDisplayMode::WindowedResizable ? mFullScreenSize : mWindowedSize); };
48 void Size(const VkExtent2D size);
50 inline VkOffset2D Position() const { return mPosition; }
52 void Position(const VkOffset2D pos);
54 void DisplayMode(EDisplayMode mode, bool preserveSize = false);
56 inline EDisplayMode DisplayMode() const { return mDisplayMode; };
57
58 SDL_Window* GetSdlWindowHandle() const { return mHandle; }
59
60 virtual uint32_t SDLId() const;
61
62 virtual VkSurfaceKHR GetOrCreateSurfaceKHR(VkInstance instance);
63 virtual std::vector<const char*> GetVkSurfaceExtensions() const;
64
65 virtual void HandleEvent(const Event* event);
66
67 protected:
68 inline static std::vector<Window*> sWindows = std::vector<Window*>();
69
70 SDL_Window* mHandle = nullptr;
71 VkSurfaceKHR mSurface = nullptr;
72 uint32_t mId;
73
74 std::string mTitle;
76 int32_t mDisplayId;
77 VkExtent2D mFullScreenSize;
78 VkExtent2D mWindowedSize;
79 VkOffset2D mPosition;
80
81 SDL_threadID mOwningThreadID;
82
83 virtual void HandleEvent_Resized(const EventWindowResized* event);
85
86 virtual void assertThreadIsOwner();
87 };
88
89} // namespace foray
Event type fired when the windows closure is requested (by OS or user through OS)
Definition foray_event.hpp:182
Event type fired when a window is resized.
Definition foray_event.hpp:155
Base class for operating system events.
Definition foray_event.hpp:13
Window class. Provides access to common properties of operating system level windows.
Definition foray_window.hpp:15
VkOffset2D mPosition
Definition foray_window.hpp:79
VkExtent2D mWindowedSize
Definition foray_window.hpp:78
SDL_Window * GetSdlWindowHandle() const
Definition foray_window.hpp:58
SDL_Window * mHandle
Definition foray_window.hpp:70
static Window * FindBySDLId(uint32_t id)
Window(const Window &other)=delete
virtual VkSurfaceKHR GetOrCreateSurfaceKHR(VkInstance instance)
VkExtent2D mFullScreenSize
Definition foray_window.hpp:77
int32_t mDisplayId
Definition foray_window.hpp:76
void Size(const VkExtent2D size)
(Setter) WindowPtr Size. Only works in windowed display modes.
virtual void HandleEvent(const Event *event)
virtual void HandleEvent_Closed(const EventWindowCloseRequested *event)
void operator=(const Window &other)=delete
virtual void assertThreadIsOwner()
EDisplayMode mDisplayMode
Definition foray_window.hpp:75
virtual uint32_t SDLId() const
VkSurfaceKHR mSurface
Definition foray_window.hpp:71
bool Exists() const
Check if the window exists on an OS level.
Definition foray_window.hpp:32
static std::vector< Window * > sWindows
Definition foray_window.hpp:68
static std::vector< Window * > & Windows()
VkExtent2D Size() const
(Getter) WindowPtr Size
Definition foray_window.hpp:45
virtual void Create()
Creates the OS level window based on the parameters of the window object.
static const int32_t WINDOWPOS_AUTO
Definition foray_window.hpp:17
virtual void HandleEvent_Resized(const EventWindowResized *event)
void Position(const VkOffset2D pos)
(Setter) Window Position
const std::string & Title() const
(Getter) WindowPtr Title
Definition foray_window.hpp:39
SDL_threadID mOwningThreadID
Definition foray_window.hpp:81
uint32_t mId
Definition foray_window.hpp:72
VkOffset2D Position() const
(Getter) Window Position
Definition foray_window.hpp:50
virtual void Destroy()
Destroys the OS side of the window.
void Title(const std::string &title)
(Setter) WindowPtr Title
std::string mTitle
Definition foray_window.hpp:74
EDisplayMode DisplayMode() const
(Getter) Display Mode
Definition foray_window.hpp:56
Window(const Window &&other)=delete
virtual std::vector< const char * > GetVkSurfaceExtensions() const
void DisplayMode(EDisplayMode mode, bool preserveSize=false)
(Setter) Display Mode
Definition foray_env.hpp:7
EDisplayMode
Supported modes of window display.
Definition foray_helpers.hpp:380
@ WindowedResizable
An OS window with default borders etc. and resizing enabled.