1 /**
2 *	Monitors.
3 */
4 module glfw3d.Monitor;
5 
6 import glfw3d.glfw3;
7 import glfw3d.Main;
8 import std.string : fromStringz;
9 
10 /**
11 *	Utility structs.
12 */
13 struct MonitorPosition {
14 	int x, y;
15 }
16 /// ditto
17 struct MonitorSize {
18 	int widthMM, heightMM;
19 }
20 /// ditto
21 struct VideoMode {
22 	int width;
23 	int height;
24 	int redBits;
25 	int greenBits;
26 	int blueBits;
27 	int refreshRate;
28 }
29 /// ditto
30 struct GammaRamp {
31 	ushort* red;
32 	ushort* green;
33 	ushort* blue;
34 	uint size;
35 }
36 
37 /**
38 *	Returns: All aviable monitors.
39 */
40 Monitor[] glfw3dGetMonitors() {
41 	int k;
42 	GLFWmonitor** output = glfwGetMonitors(&k);
43 	if(!output || k == 0)
44 		throw new glfw3dException("No monitors found");
45 	Monitor[] o;
46 	for(int i; i < k; i++)
47 		o ~= new Monitor(output[i]);
48 	return o;
49 }
50 
51 /**
52 *	Represents GLFWmonitor struct.
53 */
54 class Monitor {
55 	private {
56 		GLFWmonitor* monitor;
57 	}
58 
59 	/**
60 	*	It can be used to direct access to glfw3 functions.
61 	*	Returns: pointer to GLFWmonitor
62 	*/
63 	GLFWmonitor* ptr() {
64 		return this.monitor;
65 	}
66 
67 	/**
68 	*	Primary monitor
69 	*/
70 	this() {
71 		this(glfwGetPrimaryMonitor());
72 	}
73 
74 	this(GLFWmonitor* m) {
75 		this.monitor = m;
76 	}
77 
78 	/**
79 	*	Returns: position of the monitor
80 	*/
81 	MonitorPosition getPosition() {
82 		int x, y;
83 		glfwGetMonitorPos(this.monitor, &x, &y);
84 		return MonitorPosition(x, y);
85 	}
86 
87 	/**
88 	*	Returns: physical size of the monitor
89 	*/
90 	MonitorSize getSize() {
91 		int w, h;
92 		glfwGetMonitorPhysicalSize(this.monitor, &w, &h);
93 		return MonitorSize(w, h);
94 	}
95 
96 	/**
97 	*	Returns: name of the monitor
98 	*/
99 	string getName() {
100 		return glfwGetMonitorName(this.monitor).fromStringz.idup;
101 	}
102 
103 	/**
104 	*	Returns: current videomode of the monitor
105 	*/
106 	VideoMode getVideoMode() {
107 		return cast(VideoMode) glfwGetVideoMode(this.monitor)[0];
108 	}
109 
110 	/**
111 	*	Returns: all aviable videomodes for monitor
112 	*/
113 	VideoMode[] getAllVideoModes() {
114 		int k;
115 		const(GLFWvidmode)* output = glfwGetVideoModes(this.monitor, &k);
116 		if(!output || k == 0)
117 			throw new glfw3dException("Cannot read video modes");
118 		VideoMode[] o;
119 		for(int i; i < k; i++)
120 			o ~= cast(VideoMode) output[i];
121 		return o;
122 	}
123 }
124