1 module nudsfml.window.videomode; 2 3 import bindbc.sfml.window; 4 5 struct VideoMode { 6 ///Video mode width, in pixels. 7 uint width; 8 ///Video mode height, in pixels. 9 uint height; 10 11 ///Video mode pixel depth, in bits per pixels. 12 uint bitsPerPixel; 13 14 /** 15 * Construct the video mode with its attributes. 16 * 17 * Params: 18 * modeWidth = Width in pixels 19 * modeHeight = Height in pixels 20 * modeBitsPerPixel = Pixel depths in bits per pixel 21 */ 22 this(uint modeWidth, uint modeHeight, uint modeBitsPerPixel= 32) { 23 width = modeWidth; 24 height = modeHeight; 25 bitsPerPixel = modeBitsPerPixel; 26 } 27 28 /** 29 * Get the current desktop video mode. 30 * 31 * Returns: Current desktop video mode. 32 */ 33 static VideoMode getDesktopMode() { 34 VideoMode temp = cast(VideoMode) sfVideoMode_getDesktopMode(); 35 return temp; 36 } 37 38 /** 39 * Retrieve all the video modes supported in fullscreen mode. 40 * 41 * When creating a fullscreen window, the video mode is restricted to be 42 * compatible with what the graphics driver and monitor support. This 43 * function returns the complete list of all video modes that can be used in 44 * fullscreen mode. The returned array is sorted from best to worst, so that 45 * the first element will always give the best mode (higher width, height 46 * and bits-per-pixel). 47 * 48 * Returns: Array containing all the supported fullscreen modes. 49 */ 50 static VideoMode[] getFullscreenModes() { 51 //stores all video modes after the first call 52 static VideoMode[] videoModes; 53 54 //if getFullscreenModes hasn't been called yet 55 if(videoModes.length == 0) { 56 size_t counts; 57 const(sfVideoMode) * modes = sfVideoMode_getFullscreenModes(&counts);; 58 59 //calculate real length 60 videoModes.length = counts/3; 61 62 //populate videoModes 63 int videoModeIndex = 0; 64 for(uint i = 0; i < counts; i+=3) { 65 VideoMode temp = VideoMode(modes[i].width, modes[i].height, modes[i].bitsPerPixel); 66 67 videoModes[videoModeIndex] = temp; 68 ++videoModeIndex; 69 } 70 } 71 72 return videoModes; 73 } 74 75 /** 76 * Tell whether or not the video mode is valid. 77 * 78 * The validity of video modes is only relevant when using fullscreen 79 * windows; otherwise any video mode can be used with no restriction. 80 * 81 * Returns: true if the video mode is valid for fullscreen mode. 82 */ 83 bool isValid() const { 84 sfVideoMode mode = cast(sfVideoMode) this; 85 return sfVideoMode_isValid(mode)>0; 86 } 87 88 ///Returns a string representation of the video mode. 89 string toString() const { 90 import std.conv: text; 91 return "Width: " ~ text(width) ~ " Height: " ~ text(height) ~ " Bits per pixel: " ~ text(bitsPerPixel); 92 } 93 }