载入中...
搜索中...
未找到
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
15class Window final : public eve::window::Window {
16public:
17 Window();
18 ~Window();
19
20 void setSize(int width, int height) override;
21 int getWidth() const override;
22 int getHeight() const override;
23
24 bool setWindowSettings(WindowSettings settings) override;
26
27 void close() override;
28
29 bool setFullscreenDesktop(bool fullscreen) override;
30 bool setFullscreenExclusive(bool fullscreen) override;
31
32 bool isOpen() const override;
33
34 void setWindowTitle(const std::string& title) override;
35 const std::string& getWindowTitle() const override;
36 void setPosition(int x, int y, int display) override;
37 void getPosition(int& x, int& y, int& display) override;
38 void minimize() override;
39 void maximize() override;
40 void restore() override;
41 bool isMaximized() const override;
42 bool isMinimized() const override;
43 bool hasFocus() const override;
44 bool hasMouseFocus() const override;
45 bool isVisible() const override;
46 void setVSync(int vsync) override;
47 int getVSync() const override;
48
49 int getPixelWidth() const override;
50 int getPixelHeight() const override;
51 double getDPIScale() const override;
52 double getNativeDPIScale() const override;
53 void windowToPixelCoords(double* x, double* y) const override;
54 void pixelToWindowCoords(double* x, double* y) const override;
55 void windowToDPICoords(double* x, double* y) const override;
56 void DPIToWindowCoords(double* x, double* y) const override;
57 double toPixels(double x) const override;
58 double fromPixels(double x) const override;
59 void toPixelsXY(double wx, double wy, double& px, double& py) const override;
60 void fromPixelsXY(double px, double py, double& wx, double& wy) const override;
61
62 void *getHandle() const override { return window; }
63
64 int getDisplayCount() const override;
65 std::string getDisplayName(int display) const override;
66 std::string getDisplayOrientation(int display) const override;
67 std::vector<WindowSize> getFullscreenSizes(int display) const override;
68 void getDesktopDimensions(int display, int& width, int& height) const override;
69
70 bool showMessageBox(const std::string& title, const std::string& message,
71 const std::string& type, bool attachToWindow) override;
72 int showMessageBoxData(const MessageBoxData& data) override;
73 void requestAttention(bool continuous) override;
74
75 bool setIconRGBA(const uint8_t* rgba, int width, int height) override;
76
78 void updateSettings(const WindowSettings &newsettings, bool updateGraphicsViewport);
79
80private:
81 bool setFullscreenInternal(bool fullscreen, bool desktop_mode);
82
83 int width = 800, height = 600;
84
85 WindowSettings settings;
86
87 std::string title;
88
89 std::vector<uint8_t> iconRgba;
90 int iconWidth = 0;
91 int iconHeight = 0;
92
93 int windowWidth = 800;
94 int windowHeight = 600;
95 int pixelWidth = 800;
96 int pixelHeight = 600;
97
98 bool open;
99 bool mouseGrabbed;
100 bool displayedWindowError;
101
102 SDL_Window *window = nullptr;
103
104 bool createWindowAndContext(int x, int y, int w, int h, Uint32 windowflags, int msaa, bool stencil, int depth);
105 void close(bool allowExceptions);
106
107}; // Window
108
109} // namespace sdl
110} // namespace window
111} // namespace eve
std::string type
std::string title
int y
Definition Grass.cpp:135
float height
Definition Grass.cpp:235
int x
Definition Grass.cpp:135
int h
int w
std::vector< Colorf > px
float depth
int width
Platform window interface (SDL implementation on desktop/mobile). Script: win <- eve....
Definition Window.h:46
void * getHandle() const override
Native window handle (SDL_Window* on SDL backend).
Definition Window.h:62
bool hasMouseFocus() const override
True when the window has mouse focus.
Definition Window.cpp:323
bool setFullscreenExclusive(bool fullscreen) override
Switches between exclusive fullscreen and windowed mode.
Definition Window.cpp:210
bool isMaximized() const override
Definition Window.cpp:314
bool isVisible() const override
Definition Window.cpp:326
void maximize() override
Definition Window.cpp:311
void setVSync(int vsync) override
Enables/disables vertical sync (0 = off, 1 = on).
Definition Window.cpp:331
int getVSync() const override
Definition Window.cpp:335
int showMessageBoxData(const MessageBoxData &data) override
Shows a configurable message box; returns the pressed button index.
Definition Window.cpp:453
int getHeight() const override
Definition Window.cpp:68
void setSize(int width, int height) override
Requests a new logical window size.
Definition Window.cpp:58
void restore() override
Definition Window.cpp:312
double getDPIScale() const override
Current UI/logical DPI scale (1.0 on non-retina displays).
Definition Window.cpp:346
int getPixelHeight() const override
Definition Window.cpp:339
std::string getDisplayOrientation(int display) const override
Display orientation string (e.g. "landscape").
Definition Window.cpp:410
bool hasFocus() const override
True when the window has keyboard focus.
Definition Window.cpp:320
double fromPixels(double x) const override
Definition Window.cpp:384
int getWidth() const override
Definition Window.cpp:66
bool isMinimized() const override
Definition Window.cpp:317
bool setWindowSettings(WindowSettings settings) override
Applies a full WindowSettings struct (recreates the window when needed).
Definition Window.cpp:70
void setWindowTitle(const std::string &title) override
Sets the window title shown in the OS title bar.
Definition Window.cpp:273
void fromPixelsXY(double px, double py, double &wx, double &wy) const override
Definition Window.cpp:394
void requestAttention(bool continuous) override
Requests OS attention (flashing taskbar); continuous repeats until focused.
Definition Window.cpp:476
bool showMessageBox(const std::string &title, const std::string &message, const std::string &type, bool attachToWindow) override
Shows a modal message box ("info", "warning", or "error").
Definition Window.cpp:447
std::vector< WindowSize > getFullscreenSizes(int display) const override
Fullscreen sizes supported by a display.
Definition Window.cpp:421
void updateSettings(const WindowSettings &newsettings, bool updateGraphicsViewport)
Used by event backend on resize to refresh drawable size / viewport.
Definition Window.cpp:573
void windowToDPICoords(double *x, double *y) const override
Converts window logical coordinates to UI-DPI coordinates.
Definition Window.cpp:367
double getNativeDPIScale() const override
Native DPI scale reported by the OS for this window.
Definition Window.cpp:341
void pixelToWindowCoords(double *x, double *y) const override
Converts framebuffer pixel coordinates to window logical coordinates.
Definition Window.cpp:359
int getPixelWidth() const override
Framebuffer (pixel) dimensions of the window.
Definition Window.cpp:337
bool isOpen() const override
Definition Window.cpp:271
double toPixels(double x) const override
Scales a logical length to UI pixels (and back).
Definition Window.cpp:382
int getDisplayCount() const override
Number of displays attached to the system.
Definition Window.cpp:399
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:280
bool setFullscreenDesktop(bool fullscreen) override
Switches between desktop fullscreen and windowed mode.
Definition Window.cpp:206
void toPixelsXY(double wx, double wy, double &px, double &py) const override
Vector variants of the coordinate conversions above.
Definition Window.cpp:389
bool setIconRGBA(const uint8_t *rgba, int width, int height) override
Sets the window icon from tightly packed RGBA8 pixels (w*h*4 bytes).
Definition Window.cpp:487
std::string getDisplayName(int display) const override
Human-readable display name for a display index.
Definition Window.cpp:404
void getPosition(int &x, int &y, int &display) override
Reads the current window position and display index.
Definition Window.cpp:293
void DPIToWindowCoords(double *x, double *y) const override
Converts UI-DPI coordinates to window logical coordinates.
Definition Window.cpp:375
void windowToPixelCoords(double *x, double *y) const override
Converts window logical coordinates to framebuffer pixel coordinates.
Definition Window.cpp:352
WindowSettings getWindowSettings() override
Definition Window.cpp:204
void getDesktopDimensions(int display, int &width, int &height) const override
Desktop resolution of a display.
Definition Window.cpp:437
void close() override
Closes and destroys the underlying window.
Definition Window.cpp:552
void minimize() override
Minimizes / maximizes / restores the window.
Definition Window.cpp:310
const std::string & getWindowTitle() const override
Definition Window.cpp:278
WidgetDesc window(std::string title, std::vector< WidgetDesc > children, std::string id)
Top-level window widget with a title bar.
Definition Widget.cpp:225
Definition Build.cpp:11
Display settings for window creation/resize. width/height == 0 selects the desktop display mode size.
Definition Window.h:17