1 module re.gfx.window;
2 
3 import re.core;
4 import re.math;
5 import std.string;
6 import std.algorithm.comparison: max;
7 static import raylib;
8 
9 class Window {
10     // raw window width and height
11     private int _width;
12     private int _height;
13     /// the window dpi scale
14     public float scale_dpi;
15     /// the monitor
16     private int _monitor;
17 
18     /// creates a window instance with the given dimensions
19     this(int width, int height) {
20         _width = width;
21         _height = height;
22     }
23 
24     /// dpi-scaled window width
25     @property int width() {
26         update_window();
27         return cast(int)(_width);
28     }
29 
30     /// dpi-scaled window height
31     @property int height() {
32         update_window();
33         return cast(int)(_height);
34     }
35 
36     /// initializes the window
37     public void initialize() {
38         // create the window
39         raylib.InitWindow(_width, _height, "");
40         // set options
41         raylib.SetTargetFPS(Core.target_fps);
42         // get properties
43         auto scale_dpi_vec = raylib.GetWindowScaleDPI();
44         scale_dpi = max(scale_dpi_vec.x, scale_dpi_vec.y);
45     }
46 
47     public void set_title(string title) {
48         raylib.SetWindowTitle(toStringz(title));
49     }
50 
51     public void resize(int width, int height) {
52         raylib.SetWindowSize(width, height);
53         update_window();
54     }
55 
56     private void update_window() {
57         _width = raylib.GetScreenWidth();
58         _height = raylib.GetScreenHeight();
59     }
60 
61     public void destroy() {
62         raylib.CloseWindow();
63     }
64 }