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 [[nodiscard]] SDL_Renderer* renderer() const;
49
50 [[nodiscard]] Sint32 offsetX() const;
51 void setOffsetX(Sint32 x);
52
53 void setOffsetY(Sint32 y);
54 [[nodiscard]] Sint32 offsetY() const;
55
56 [[nodiscard]] rdpMonitor monitor(bool isPrimary) const;
57 void setMonitor(rdpMonitor monitor);
58
59 [[nodiscard]] float scale() const;
60 [[nodiscard]] SDL_DisplayOrientation orientation() const;
61
62 [[nodiscard]] bool grabKeyboard(bool enable);
63 [[nodiscard]] bool grabMouse(bool enable);
64 void setBordered(bool bordered);
65 void raise();
66 void resizeable(bool use);
67 void fullscreen(bool enter, bool forceOriginalDisplay);
68 void minimize();
69
70 [[nodiscard]] bool resizeToScale();
71 [[nodiscard]] bool resize(const SDL_Point& size);
72
73 [[nodiscard]] bool drawRect(SDL_Surface* surface, SDL_Point offset, const SDL_Rect& srcRect);
74 [[nodiscard]] bool drawRects(SDL_Surface* surface, SDL_Point offset,
75 const std::vector<SDL_Rect>& rects = {});
76 [[nodiscard]] bool drawScaledRect(SDL_Surface* surface, const SDL_FPoint& scale,
77 const SDL_Rect& srcRect);
78
79 [[nodiscard]] bool drawScaledRects(SDL_Surface* surface, const SDL_FPoint& scale,
80 const std::vector<SDL_Rect>& rects = {});
81
82 [[nodiscard]] bool fill(Uint8 r = 0x00, Uint8 g = 0x00, Uint8 b = 0x00, Uint8 a = 0xff);
83 [[nodiscard]] bool blit(SDL_Surface* surface, const SDL_Rect& src, SDL_Rect& dst);
84 void updateSurface();
85
86 protected:
87 SdlWindow(SDL_DisplayID id, const std::string& title, const SDL_Rect& rect, Uint32 flags);
88
89 [[nodiscard]] static bool fill(SDL_Window* window, Uint8 r = 0x00, Uint8 g = 0x00,
90 Uint8 b = 0x00, Uint8 a = 0xff);
91 [[nodiscard]] static rdpMonitor query(SDL_Window* window, SDL_DisplayID id,
92 bool forceAsPrimary = false);
93 [[nodiscard]] static SDL_Rect rect(SDL_Window* window, bool forceAsPrimary = false);
94 [[nodiscard]] static SDL_Rect rect(SDL_DisplayID id, bool forceAsPrimary = false);
95
96 [[nodiscard]] static bool tryFallback(bool isFullscreen);
97
98 enum HighDPIMode
99 {
100 MODE_INVALID,
101 MODE_NONE,
102 MODE_WINDOWS,
103 MODE_MACOS
104 };
105
106 [[nodiscard]] static enum HighDPIMode isHighDPIWindowsMode(SDL_Window* window);
107
108 private:
109 void ensureRenderTarget();
110
111 SDL_Window* _window = nullptr;
112 SDL_Renderer* _renderer = nullptr;
113 SDL_Texture* _renderTarget = nullptr;
114 SDL_Texture* _gdiTexture = nullptr;
115 int _gdiTextureW = 0;
116 int _gdiTextureH = 0;
117 int _initialW = 0;
118 int _initialH = 0;
119 SDL_DisplayID _displayID = 0;
120 Sint32 _offset_x = 0;
121 Sint32 _offset_y = 0;
122 rdpMonitor _monitor{};
123};