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 /// initializes the window 44 public void initialize() { 45 // create the window 46 raylib.InitWindow(_width, _height, ""); 47 // set options 48 raylib.SetTargetFPS(Core.target_fps); 49 // // get properties 50 // _scale_dpi = get_display_dpi_scale(); 51 update_window(); 52 } 53 54 public static float get_display_dpi_scale() { 55 auto scale_dpi_vec = raylib.GetWindowScaleDPI(); 56 return max(scale_dpi_vec.x, scale_dpi_vec.y); 57 } 58 59 public void set_title(string title) { 60 raylib.SetWindowTitle(toStringz(title)); 61 } 62 63 public void resize(int width, int height) { 64 raylib.SetWindowSize(width, height); 65 update_window(); 66 } 67 68 private void update_window() { 69 _width = raylib.GetScreenWidth(); 70 _height = raylib.GetScreenHeight(); 71 _scale_dpi = get_display_dpi_scale(); 72 } 73 74 public void destroy() { 75 raylib.CloseWindow(); 76 } 77 }