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