1 module allegro5.haptic;
2 
3 import allegro5.display;
4 import allegro5.mouse;
5 import allegro5.joystick;
6 import allegro5.keyboard;
7 import allegro5.touch_input;
8 
9 version (ALLEGRO_UNSTABLE)
10 	version = AllegroHapticUnstable;
11 version (ALLEGRO_INTERNAL_UNSTABLE)
12 	version = AllegroHapticUnstable;
13 version (ALLEGRO_SRC)
14 	version = AllegroHapticUnstable;
15 
16 version (AllegroHapticUnstable):
17 enum ALLEGRO_HAPTIC_CONSTANTS
18 {
19 	ALLEGRO_HAPTIC_RUMBLE = 1 << 0,
20 	ALLEGRO_HAPTIC_PERIODIC = 1 << 1,
21 	ALLEGRO_HAPTIC_CONSTANT = 1 << 2,
22 	ALLEGRO_HAPTIC_SPRING = 1 << 3,
23 	ALLEGRO_HAPTIC_FRICTION = 1 << 4,
24 	ALLEGRO_HAPTIC_DAMPER = 1 << 5,
25 	ALLEGRO_HAPTIC_INERTIA = 1 << 6,
26 	ALLEGRO_HAPTIC_RAMP = 1 << 7,
27 	ALLEGRO_HAPTIC_SQUARE = 1 << 8,
28 	ALLEGRO_HAPTIC_TRIANGLE = 1 << 9,
29 	ALLEGRO_HAPTIC_SINE = 1 << 10,
30 	ALLEGRO_HAPTIC_SAW_UP = 1 << 11,
31 	ALLEGRO_HAPTIC_SAW_DOWN = 1 << 12,
32 	ALLEGRO_HAPTIC_CUSTOM = 1 << 13,
33 	ALLEGRO_HAPTIC_GAIN = 1 << 14,
34 	ALLEGRO_HAPTIC_ANGLE = 1 << 15,
35 	ALLEGRO_HAPTIC_RADIUS = 1 << 16,
36 	ALLEGRO_HAPTIC_AZIMUTH = 1 << 17,
37 	ALLEGRO_HAPTIC_AUTOCENTER = 1 << 18,
38 }
39 
40 struct ALLEGRO_HAPTIC {}
41 
42 struct ALLEGRO_HAPTIC_DIRECTION
43 {
44 	double angle;
45 	double radius;
46 	double azimuth;
47 }
48 
49 struct ALLEGRO_HAPTIC_REPLAY
50 {
51 	double length;
52 	double delay;
53 }
54 
55 struct ALLEGRO_HAPTIC_ENVELOPE
56 {
57 	double attack_length;
58 	double attack_level;
59 	double fade_length;
60 	double fade_level;
61 }
62 
63 struct ALLEGRO_HAPTIC_CONSTANT_EFFECT
64 {
65 	double level;
66 	ALLEGRO_HAPTIC_ENVELOPE envelope;
67 }
68 
69 struct ALLEGRO_HAPTIC_RAMP_EFFECT
70 {
71 	double start_level;
72 	double end_level;
73 	ALLEGRO_HAPTIC_ENVELOPE envelope;
74 }
75 
76 struct ALLEGRO_HAPTIC_CONDITION_EFFECT
77 {
78 	double right_saturation;
79 	double left_saturation;
80 	double right_coeff;
81 	double left_coeff;
82 	double deadband;
83 	double center;
84 }
85 
86 struct ALLEGRO_HAPTIC_PERIODIC_EFFECT
87 {
88 	int waveform;
89 	double period;
90 	double magnitude;
91 	double offset;
92 	double phase;
93 
94 	ALLEGRO_HAPTIC_ENVELOPE envelope;
95 	int custom_len;
96 	double *custom_data;
97 }
98 
99 struct ALLEGRO_HAPTIC_RUMBLE_EFFECT
100 {
101 	double strong_magnitude;
102 	double weak_magnitude;
103 }
104 
105 union ALLEGRO_HAPTIC_EFFECT_UNION
106 {
107 	ALLEGRO_HAPTIC_CONSTANT_EFFECT constant;
108 	ALLEGRO_HAPTIC_RAMP_EFFECT ramp;
109 	ALLEGRO_HAPTIC_PERIODIC_EFFECT periodic;
110 	ALLEGRO_HAPTIC_CONDITION_EFFECT condition;
111 	ALLEGRO_HAPTIC_RUMBLE_EFFECT rumble;
112 }
113 
114 struct ALLEGRO_HAPTIC_EFFECT
115 {
116 	int type;
117 	ALLEGRO_HAPTIC_DIRECTION direction;
118 	ALLEGRO_HAPTIC_REPLAY replay;
119 	ALLEGRO_HAPTIC_EFFECT_UNION data;
120 }
121 
122 struct ALLEGRO_HAPTIC_EFFECT_ID
123 {
124 	ALLEGRO_HAPTIC* _haptic;
125 	int _id;
126 	int _handle;
127 	void* _pointer;
128 	double _effect_duration;
129 	bool _playing;
130 	double _start_time;
131 	double _end_time;
132 	void* driver;
133 }
134 
135 extern(C)
136 {
137    bool al_install_haptic();
138    void al_uninstall_haptic();
139    bool al_is_haptic_installed();
140 
141    bool al_is_mouse_haptic(ALLEGRO_MOUSE*);
142    bool al_is_joystick_haptic(ALLEGRO_JOYSTICK*);
143    bool al_is_keyboard_haptic(ALLEGRO_KEYBOARD*);
144    bool al_is_display_haptic(ALLEGRO_DISPLAY*);
145    bool al_is_touch_input_haptic(ALLEGRO_TOUCH_INPUT*);
146 
147    ALLEGRO_HAPTIC*  al_get_haptic_from_mouse(ALLEGRO_MOUSE*);
148    ALLEGRO_HAPTIC*  al_get_haptic_from_joystick(ALLEGRO_JOYSTICK*);
149    ALLEGRO_HAPTIC*  al_get_haptic_from_keyboard(ALLEGRO_KEYBOARD*);
150    ALLEGRO_HAPTIC*  al_get_haptic_from_display(ALLEGRO_DISPLAY*);
151    ALLEGRO_HAPTIC*  al_get_haptic_from_touch_input(ALLEGRO_TOUCH_INPUT*);
152 
153    bool al_release_haptic(ALLEGRO_HAPTIC*);
154 
155    bool al_is_haptic_active(ALLEGRO_HAPTIC*);
156    int al_get_haptic_capabilities(ALLEGRO_HAPTIC*);
157    bool al_is_haptic_capable(ALLEGRO_HAPTIC*, int);
158 
159    bool al_set_haptic_gain(ALLEGRO_HAPTIC*, double gain);
160    double al_get_haptic_gain(ALLEGRO_HAPTIC*);
161 
162    int al_get_max_haptic_effects(ALLEGRO_HAPTIC*);
163    bool al_is_haptic_effect_ok(ALLEGRO_HAPTIC*, ALLEGRO_HAPTIC_EFFECT*);
164    bool al_upload_haptic_effect(ALLEGRO_HAPTIC*, ALLEGRO_HAPTIC_EFFECT*, ALLEGRO_HAPTIC_EFFECT_ID* play_id);
165    bool al_play_haptic_effect(ALLEGRO_HAPTIC_EFFECT_ID*, int loop);
166    bool al_upload_and_play_haptic_effect(ALLEGRO_HAPTIC*, ALLEGRO_HAPTIC_EFFECT*, int loop, ALLEGRO_HAPTIC_EFFECT_ID* play_id);
167    bool al_stop_haptic_effect(ALLEGRO_HAPTIC_EFFECT_ID*);
168    bool al_is_haptic_effect_playing(ALLEGRO_HAPTIC_EFFECT_ID*);
169    bool al_release_haptic_effect(ALLEGRO_HAPTIC_EFFECT_ID*);
170    double al_get_haptic_effect_duration(ALLEGRO_HAPTIC_EFFECT *);
171    bool al_rumble_haptic(ALLEGRO_HAPTIC*, double intensity, double duration, ALLEGRO_HAPTIC_EFFECT_ID*);
172 }