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