载入中...
搜索中...
未找到
Window.h
浏览该文件的文档.
1#pragma once
2
3#include <SDL2/SDL.h>
4
5#include <cstdint>
6#include <string>
7#include <vector>
8
9#include "window/Window.h"
10
11namespace eve {
12namespace window {
13namespace sdl {
14
16class Window final : public eve::window::Window {
17public:
19 Window();
21 ~Window();
22
24 void setSize(int w, int h) override;
26 int getWidth() const override;
28 int getHeight() const override;
29
31 bool setWindowSettings(WindowSettings settings) override;
34
36 void close() override;
37
39 bool setFullscreenDesktop(bool fullscreen) override;
41 bool setFullscreenExclusive(bool fullscreen) override;
42
44 bool isOpen() const override;
45
47 void setWindowTitle(const std::string& title) override;
49 const std::string& getWindowTitle() const override;
51 void setPosition(int x, int y, int display) override;
53 void getPosition(int& x, int& y, int& display) override;
55 void minimize() override;
57 void maximize() override;
59 void restore() override;
61 bool isMaximized() const override;
63 bool isMinimized() const override;
65 bool hasFocus() const override;
67 bool hasMouseFocus() const override;
69 bool isVisible() const override;
71 void setVSync(int vsync) override;
73 int getVSync() const override;
74
76 int getPixelWidth() const override;
78 int getPixelHeight() const override;
80 double getDPIScale() const override;
82 double getNativeDPIScale() const override;
84 void windowToPixelCoords(double* x, double* y) const override;
86 void pixelToWindowCoords(double* x, double* y) const override;
88 void windowToDPICoords(double* x, double* y) const override;
90 void DPIToWindowCoords(double* x, double* y) const override;
92 double toPixels(double x) const override;
94 double fromPixels(double x) const override;
96 void toPixelsXY(double wx, double wy, double& px, double& py) const override;
98 void fromPixelsXY(double px, double py, double& wx, double& wy) const override;
99
101 void *getHandle() const override { return window; }
102
104 int getDisplayCount() const override;
106 std::string getDisplayName(int display) const override;
108 std::string getDisplayOrientation(int display) const override;
110 std::vector<WindowSize> getFullscreenSizes(int display) const override;
112 void getDesktopDimensions(int display, int& outWidth, int& outHeight) const override;
113
115 bool showMessageBox(const std::string& caption, const std::string& message,
116 const std::string& type, bool attachToWindow) override;
118 int showMessageBoxData(const MessageBoxData& data) override;
120 void requestAttention(bool continuous) override;
121
123 bool setIconRGBA(const uint8_t* rgba, int w, int h) override;
124
126 void updateSettings(const WindowSettings &newsettings, bool updateGraphicsViewport);
127
128private:
129 bool setFullscreenInternal(bool fullscreen, bool desktop_mode);
130
131 int width = 800, height = 600;
132
134
135 std::string title;
136
137 std::vector<uint8_t> iconRgba;
138 int iconWidth = 0;
139 int iconHeight = 0;
140
141 int windowWidth = 800;
142 int windowHeight = 600;
143 int pixelWidth = 800;
144 int pixelHeight = 600;
145
146 bool open;
147 bool mouseGrabbed;
148 bool displayedWindowError;
149
150 SDL_Window *window = nullptr;
151
152 bool createWindowAndContext(int x, int y, int w, int h, Uint32 windowflags, int msaa, bool stencil, int depth);
153 void close(bool allowExceptions);
154
155}; // Window
156
157} // namespace sdl
158} // namespace window
159} // namespace eve
float w
Definition AnimClip.cpp:738
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float py
std::string title
std::string message
int h
std::vector< Colorf > px
TerrainThermalSettings settings
std::uint32_t depth
float wx
float wy
Platform window interface (SDL implementation on desktop/mobile). Script: win <- eve....
Definition Window.h:47
SDL2 desktop/mobile implementation of eve::window::Window.
Definition Window.h:16
void * getHandle() const override
Native window handle (SDL_Window* on SDL backend).
Definition Window.h:101
void getDesktopDimensions(int display, int &outWidth, int &outHeight) const override
Desktop resolution of a display.
Definition Window.cpp:448
bool hasMouseFocus() const override
True when the window has mouse focus.
Definition Window.cpp:334
bool setFullscreenExclusive(bool fullscreen) override
Switches between exclusive fullscreen and windowed mode.
Definition Window.cpp:221
bool isMaximized() const override
True when the window is maximized.
Definition Window.cpp:325
bool isVisible() const override
True when the window is visible (not hidden).
Definition Window.cpp:337
void maximize() override
Maximizes the window.
Definition Window.cpp:322
bool setIconRGBA(const uint8_t *rgba, int w, int h) override
Sets the window icon from tightly packed RGBA8 pixels (w*h*4 bytes).
Definition Window.cpp:498
void setVSync(int vsync) override
Enables/disables vertical sync (0 = off, 1 = on).
Definition Window.cpp:342
int getVSync() const override
Current vsync setting (0 = off, 1 = on).
Definition Window.cpp:346
int showMessageBoxData(const MessageBoxData &data) override
Shows a configurable message box; returns the pressed button index.
Definition Window.cpp:464
int getHeight() const override
Current logical window height.
Definition Window.cpp:79
void restore() override
Restores from minimized/maximized state.
Definition Window.cpp:323
double getDPIScale() const override
Current UI/logical DPI scale (1.0 on non-retina displays).
Definition Window.cpp:357
int getPixelHeight() const override
Framebuffer (pixel) height of the window.
Definition Window.cpp:350
std::string getDisplayOrientation(int display) const override
Display orientation string (e.g. "landscape").
Definition Window.cpp:421
bool hasFocus() const override
True when the window has keyboard focus.
Definition Window.cpp:331
double fromPixels(double x) const override
Scales a UI-pixel length back to logical units.
Definition Window.cpp:395
int getWidth() const override
Current logical window width.
Definition Window.cpp:77
bool isMinimized() const override
True when the window is minimized.
Definition Window.cpp:328
bool setWindowSettings(WindowSettings settings) override
Applies a full WindowSettings struct (recreates the window when needed).
Definition Window.cpp:81
void setWindowTitle(const std::string &title) override
Sets the window title shown in the OS title bar.
Definition Window.cpp:284
void fromPixelsXY(double px, double py, double &wx, double &wy) const override
Converts a framebuffer pixel XY pair to logical coordinates.
Definition Window.cpp:405
void requestAttention(bool continuous) override
Requests OS attention (flashing taskbar); continuous repeats until focused.
Definition Window.cpp:487
std::vector< WindowSize > getFullscreenSizes(int display) const override
Fullscreen sizes supported by a display.
Definition Window.cpp:432
void updateSettings(const WindowSettings &newsettings, bool updateGraphicsViewport)
Used by event backend on resize to refresh drawable size / viewport.
Definition Window.cpp:583
void windowToDPICoords(double *x, double *y) const override
Converts window logical coordinates to UI-DPI coordinates.
Definition Window.cpp:378
double getNativeDPIScale() const override
Native DPI scale reported by the OS for this window.
Definition Window.cpp:352
void pixelToWindowCoords(double *x, double *y) const override
Converts framebuffer pixel coordinates to window logical coordinates.
Definition Window.cpp:370
int getPixelWidth() const override
Framebuffer (pixel) width of the window.
Definition Window.cpp:348
bool isOpen() const override
True while the native window exists and has not been closed.
Definition Window.cpp:282
double toPixels(double x) const override
Scales a logical length to UI pixels.
Definition Window.cpp:393
int getDisplayCount() const override
Number of displays attached to the system.
Definition Window.cpp:410
void setPosition(int x, int y, int display) override
Moves the window to a position in logical units on the given display.
Definition Window.cpp:291
bool setFullscreenDesktop(bool fullscreen) override
Switches between desktop fullscreen and windowed mode.
Definition Window.cpp:217
void toPixelsXY(double wx, double wy, double &px, double &py) const override
Converts a logical XY pair to framebuffer pixels.
Definition Window.cpp:400
std::string getDisplayName(int display) const override
Human-readable display name for a display index.
Definition Window.cpp:415
void getPosition(int &x, int &y, int &display) override
Reads the current window position and display index.
Definition Window.cpp:304
void DPIToWindowCoords(double *x, double *y) const override
Converts UI-DPI coordinates to window logical coordinates.
Definition Window.cpp:386
void windowToPixelCoords(double *x, double *y) const override
Converts window logical coordinates to framebuffer pixel coordinates.
Definition Window.cpp:363
WindowSettings getWindowSettings() override
Returns the settings last applied to this window.
Definition Window.cpp:215
void close() override
Closes and destroys the underlying window.
Definition Window.cpp:562
void minimize() override
Minimizes the window.
Definition Window.cpp:321
Window()
Constructs an unopened window module; call setWindowSettings to create.
Definition Window.cpp:52
const std::string & getWindowTitle() const override
Current title string.
Definition Window.cpp:289
void setSize(int w, int h) override
Requests a new logical window size.
Definition Window.cpp:69
bool showMessageBox(const std::string &caption, const std::string &message, const std::string &type, bool attachToWindow) override
Shows a modal message box ("info", "warning", or "error").
Definition Window.cpp:458
~Window()
Destroys the SDL_Window if still open.
Definition Window.cpp:64
WidgetDesc window(std::string title, std::vector< WidgetDesc > children, std::string id)
Top-level window widget with a title bar.
Definition Widget.cpp:292
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
Display settings for window creation/resize. width/height == 0 selects the desktop display mode size.
Definition Window.h:18