FreeRDP
Loading...
Searching...
No Matches
SDL3/sdl_window.hpp
1
20#pragma once
21
22#include <string>
23#include <vector>
24
25#include <SDL3/SDL.h>
26
27#include <freerdp/settings_types.h>
28
29class SdlWindow
30{
31 public:
32 [[nodiscard]] static SdlWindow create(SDL_DisplayID id, const std::string& title, Uint32 flags,
33 Uint32 width = 0, Uint32 height = 0);
34 [[nodiscard]] static rdpMonitor query(SDL_DisplayID id, bool forceAsPrimary = false);
35
36 SdlWindow(SdlWindow&& other) noexcept;
37 SdlWindow(const SdlWindow& other) = delete;
38 virtual ~SdlWindow();
39
40 SdlWindow& operator=(const SdlWindow& other) = delete;
41 SdlWindow& operator=(SdlWindow&& other) = delete;
42
43 [[nodiscard]] SDL_WindowID id() const;
44 [[nodiscard]] SDL_DisplayID displayIndex() const;
45 [[nodiscard]] SDL_Rect rect() const;
46 [[nodiscard]] SDL_Rect bounds() const;
47 [[nodiscard]] SDL_Window* window() const;
48
49 [[nodiscard]] Sint32 offsetX() const;
50 void setOffsetX(Sint32 x);
51
52 void setOffsetY(Sint32 y);
53 [[nodiscard]] Sint32 offsetY() const;
54
55 [[nodiscard]] rdpMonitor monitor(bool isPrimary) const;
56 void setMonitor(rdpMonitor monitor);
57
58 [[nodiscard]] float scale() const;
59 [[nodiscard]] SDL_DisplayOrientation orientation() const;
60
61 [[nodiscard]] bool grabKeyboard(bool enable);
62 [[nodiscard]] bool grabMouse(bool enable);
63 void setBordered(bool bordered);
64 void raise();
65 void resizeable(bool use);
66 void fullscreen(bool enter, bool forceOriginalDisplay);
67 void minimize();
68
69 [[nodiscard]] bool resize(const SDL_Point& size);
70
71 [[nodiscard]] bool drawRect(SDL_Surface* surface, SDL_Point offset, const SDL_Rect& srcRect);
72 [[nodiscard]] bool drawRects(SDL_Surface* surface, SDL_Point offset,
73 const std::vector<SDL_Rect>& rects = {});
74 [[nodiscard]] bool drawScaledRect(SDL_Surface* surface, const SDL_FPoint& scale,
75 const SDL_Rect& srcRect);
76
77 [[nodiscard]] bool drawScaledRects(SDL_Surface* surface, const SDL_FPoint& scale,
78 const std::vector<SDL_Rect>& rects = {});
79
80 [[nodiscard]] bool fill(Uint8 r = 0x00, Uint8 g = 0x00, Uint8 b = 0x00, Uint8 a = 0xff);
81 [[nodiscard]] bool blit(SDL_Surface* surface, const SDL_Rect& src, SDL_Rect& dst);
82 void updateSurface();
83
84 protected:
85 SdlWindow(SDL_DisplayID id, const std::string& title, const SDL_Rect& rect, Uint32 flags);
86
87 [[nodiscard]] static bool fill(SDL_Window* window, Uint8 r = 0x00, Uint8 g = 0x00,
88 Uint8 b = 0x00, Uint8 a = 0xff);
89 [[nodiscard]] static rdpMonitor query(SDL_Window* window, SDL_DisplayID id,
90 bool forceAsPrimary = false);
91 [[nodiscard]] static SDL_Rect rect(SDL_Window* window, bool forceAsPrimary = false);
92 [[nodiscard]] static SDL_Rect rect(SDL_DisplayID id, bool forceAsPrimary = false);
93
94 enum HighDPIMode
95 {
96 MODE_INVALID,
97 MODE_NONE,
98 MODE_WINDOWS,
99 MODE_MACOS
100 };
101
102 [[nodiscard]] static enum HighDPIMode isHighDPIWindowsMode(SDL_Window* window);
103
104 private:
105 SDL_Window* _window = nullptr;
106 SDL_DisplayID _displayID = 0;
107 Sint32 _offset_x = 0;
108 Sint32 _offset_y = 0;
109 rdpMonitor _monitor{};
110};