1 /**
2 *	Joysticks, keyboard and mouse.
3 */
4 module glfw3d.Input;
5 
6 import glfw3d.glfw3;
7 import glfw3d.Main;
8 import std.string : fromStringz;
9 
10 /**
11 *	Params:
12 *		key = GLFW_KEY_*
13 *		scancode = platform-specific scancode
14 *	Returns: localized name of the specified printable key
15 */
16 string glfw3dGetKeyName(int key, int scancode) {
17 	return glfwGetKeyName(key, scancode).fromStringz.idup;
18 }
19 
20 /**
21 *	Main joystick class
22 */
23 class Joystick {
24 	private int joy;
25 
26 	/**
27 	*	Params:
28 	*		j = GLFW_JOYSTICK_*
29 	*/
30 	this(int j) {
31 		this.joy = j;
32 	}
33 
34 	/**
35 	*	Returns: true if current joystick is present
36 	*/
37 	bool isPresent() {
38 		if(glfwJoystickPresent(this.joy) == GLFW_TRUE) {
39 			return true;
40 		} else {
41 			return false;
42 		}
43 	}
44 
45 	/**
46 	*	Returns: axes of current joystick
47 	*/
48 	float[] getAxes() {
49 		int count;
50 		const(float)* o = glfwGetJoystickAxes(this.joy, &count);
51 		if(!o || count == 0)
52 			throw new glfw3dException("Cannot get joystick axes");
53 		float[] output;
54 		for(size_t i = 0; i < count; i++)
55 			output ~= o[i];
56 		return output;
57 	}
58 
59 	/**
60 	*	Returns: buttons of current joystick
61 	*/
62 	ubyte[] getButtons() {
63 		int count;
64 		const(ubyte)* o = glfwGetJoystickButtons(this.joy, &count);
65 		if(!o || count == 0)
66 			throw new glfw3dException("Cannot get joystick buttons");
67 		ubyte[] output;
68 		for(size_t i = 0; i < count; i++)
69 			output ~= o[i];
70 		return output;
71 	}
72 
73 	/**
74 	*	Returns: name of curent joystick
75 	*/
76 	string getName() {
77 		return glfwGetJoystickName(this.joy).fromStringz.idup;
78 	}
79 }
80