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 /* Create at an explicit position+size (RAIL windows: server-driven geometry). */
35 [[nodiscard]] static SdlWindow create(SDL_DisplayID id, const std::string& title, Uint32 flags,
36 const SDL_Rect& rect);
37 /* Popup: no taskbar entry, no keyboard focus, Wayland-positionable (xdg_popup). */
38 [[nodiscard]] static SdlWindow createPopup(SDL_Window* parent, const SDL_Rect& rect,
39 bool transparent, bool tooltip = false);
40 [[nodiscard]] static rdpMonitor query(SDL_DisplayID id, bool forceAsPrimary = false);
41
42 SdlWindow(SdlWindow&& other) noexcept;
43 SdlWindow(const SdlWindow& other) = delete;
44 virtual ~SdlWindow();
45
46 SdlWindow& operator=(const SdlWindow& other) = delete;
47 SdlWindow& operator=(SdlWindow&& other) = delete;
48
49 [[nodiscard]] SDL_WindowID id() const;
50 [[nodiscard]] SDL_DisplayID displayIndex() const;
51 [[nodiscard]] SDL_Rect rect() const;
52 [[nodiscard]] SDL_Rect bounds() const;
53 [[nodiscard]] SDL_Window* window() const;
54 [[nodiscard]] SDL_Renderer* renderer() const;
55
56 [[nodiscard]] Sint32 offsetX() const;
57 void setOffsetX(Sint32 x);
58
59 void setOffsetY(Sint32 y);
60 [[nodiscard]] Sint32 offsetY() const;
61
62 [[nodiscard]] rdpMonitor monitor(bool isPrimary) const;
63 void setMonitor(rdpMonitor monitor);
64
65 [[nodiscard]] float scale() const;
66 [[nodiscard]] SDL_DisplayOrientation orientation() const;
67
68 [[nodiscard]] bool grabKeyboard(bool enable);
69 [[nodiscard]] bool grabMouse(bool enable);
70 void setBordered(bool bordered);
71 void raise();
72 void resizeable(bool use);
73 void fullscreen(bool enter, bool forceOriginalDisplay);
74 void minimize();
75
76 [[nodiscard]] bool resizeToScale();
77 [[nodiscard]] bool resize(const SDL_Point& size);
78
79 [[nodiscard]] bool drawRect(SDL_Surface* surface, SDL_Point offset, const SDL_Rect& srcRect);
80 [[nodiscard]] bool drawRects(SDL_Surface* surface, SDL_Point offset,
81 const std::vector<SDL_Rect>& rects = {});
82 [[nodiscard]] bool drawScaledRect(SDL_Surface* surface, const SDL_FPoint& scale,
83 const SDL_Rect& srcRect);
84
85 [[nodiscard]] bool drawScaledRects(SDL_Surface* surface, const SDL_FPoint& scale,
86 const std::vector<SDL_Rect>& rects = {});
87
88 [[nodiscard]] bool fill(Uint8 r = 0x00, Uint8 g = 0x00, Uint8 b = 0x00, Uint8 a = 0xff);
89
90 [[nodiscard]] bool blit(SDL_Surface* surface, const SDL_Rect& src, SDL_Rect& dst);
91 /* Render interactive resize feedback overlay. */
92 bool paintResizeFrame(SDL_Surface* surface, SDL_Point off, bool contentChanged,
93 const SDL_Rect& inset = { 0, 0, 0, 0 }, bool fillRevealed = true,
94 bool dashedBorder = true);
95 void updateSurface();
96
97 protected:
98 SdlWindow(SDL_DisplayID id, const std::string& title, const SDL_Rect& rect, Uint32 flags);
99 SdlWindow(SDL_Window* parent, const SDL_Rect& rect, bool transparent, bool tooltip);
100
101 [[nodiscard]] static bool fill(SDL_Window* window, Uint8 r = 0x00, Uint8 g = 0x00,
102 Uint8 b = 0x00, Uint8 a = 0xff);
103 [[nodiscard]] static rdpMonitor query(SDL_Window* window, SDL_DisplayID id,
104 bool forceAsPrimary = false);
105 [[nodiscard]] static SDL_Rect rect(SDL_Window* window, bool forceAsPrimary = false);
106 [[nodiscard]] static SDL_Rect rect(SDL_DisplayID id, bool forceAsPrimary = false);
107
108 [[nodiscard]] static bool tryFallback(bool isFullscreen);
109
110 enum HighDPIMode
111 {
112 MODE_INVALID,
113 MODE_NONE,
114 MODE_WINDOWS,
115 MODE_MACOS
116 };
117
118 [[nodiscard]] static enum HighDPIMode isHighDPIWindowsMode(SDL_Window* window);
119
120 private:
121 void ensureRenderTarget();
122 bool ensureGdiTexture(SDL_Surface* surface);
123
124 SDL_Window* _window = nullptr;
125 SDL_Renderer* _renderer = nullptr;
126 SDL_Texture* _renderTarget = nullptr;
127 SDL_Texture* _gdiTexture = nullptr;
128 int _gdiTextureW = 0;
129 int _gdiTextureH = 0;
130 int _initialW = 0;
131 int _initialH = 0;
132 SDL_DisplayID _displayID = 0;
133 Sint32 _offset_x = 0;
134 Sint32 _offset_y = 0;
135 rdpMonitor _monitor{};
136};