@@ -201,24 +201,29 @@ func (h *Haptic) cptr() *C.SDL_Haptic {
201
201
202
202
// NumHaptics returns the number of haptic devices attached to the system.
203
203
// (https://wiki.libsdl.org/SDL_NumHaptics)
204
- func NumHaptics () int {
205
- return int (C .SDL_NumHaptics ())
204
+ func NumHaptics () (int , error ) {
205
+ i := int (C .SDL_NumHaptics ())
206
+ return i , errorFromInt (i )
206
207
}
207
208
208
209
// HapticName returns the implementation dependent name of a haptic device.
209
210
// (https://wiki.libsdl.org/SDL_HapticName)
210
- func HapticName (index int ) string {
211
- return (C .GoString )(C .SDL_HapticName (C .int (index )))
211
+ func HapticName (index int ) (string , error ) {
212
+ name := C .SDL_HapticName (C .int (index ))
213
+ if name == nil {
214
+ return "" , GetError ()
215
+ }
216
+ return C .GoString (name ), nil
212
217
}
213
218
214
219
// HapticOpen opens a haptic device for use.
215
220
// (https://wiki.libsdl.org/SDL_HapticOpen)
216
221
func HapticOpen (index int ) (* Haptic , error ) {
217
222
haptic := (* Haptic )(unsafe .Pointer (C .SDL_HapticOpen (C .int (index ))))
218
- if haptic ! = nil {
219
- return haptic , nil
223
+ if haptic = = nil {
224
+ return nil , GetError ()
220
225
}
221
- return nil , GetError ()
226
+ return haptic , nil
222
227
}
223
228
224
229
// HapticOpened reports whether the haptic device at the designated index has been opened.
@@ -233,8 +238,9 @@ func HapticOpened(index int) (bool, error) {
233
238
234
239
// HapticIndex returns the index of a haptic device.
235
240
// (https://wiki.libsdl.org/SDL_HapticIndex)
236
- func HapticIndex (h * Haptic ) int {
237
- return int (C .SDL_HapticIndex (h .cptr ()))
241
+ func HapticIndex (h * Haptic ) (int , error ) {
242
+ i := int (C .SDL_HapticIndex (h .cptr ()))
243
+ return i , errorFromInt (i )
238
244
}
239
245
240
246
// MouseIsHaptic reports whether or not the current mouse has haptic capabilities.
@@ -248,10 +254,10 @@ func MouseIsHaptic() (bool, error) {
248
254
// (https://wiki.libsdl.org/SDL_HapticOpenFromMouse)
249
255
func HapticOpenFromMouse () (* Haptic , error ) {
250
256
haptic := (* Haptic )(unsafe .Pointer (C .SDL_HapticOpenFromMouse ()))
251
- if haptic ! = nil {
252
- return haptic , nil
257
+ if haptic = = nil {
258
+ return nil , GetError ()
253
259
}
254
- return nil , GetError ()
260
+ return haptic , nil
255
261
}
256
262
257
263
// JoystickIsHaptic reports whether a joystick has haptic features.
@@ -263,8 +269,12 @@ func JoystickIsHaptic(joy *Joystick) (bool, error) {
263
269
264
270
// HapticOpenFromJoystick opens a haptic device for use from a joystick device.
265
271
// (https://wiki.libsdl.org/SDL_HapticOpenFromJoystick)
266
- func HapticOpenFromJoystick (joy * Joystick ) * Haptic {
267
- return (* Haptic )(unsafe .Pointer (C .SDL_HapticOpenFromJoystick (joy .cptr ())))
272
+ func HapticOpenFromJoystick (joy * Joystick ) (* Haptic , error ) {
273
+ haptic := (* Haptic )(unsafe .Pointer (C .SDL_HapticOpenFromJoystick (joy .cptr ())))
274
+ if haptic == nil {
275
+ return nil , GetError ()
276
+ }
277
+ return haptic , nil
268
278
}
269
279
270
280
// Close closes a haptic device previously opened with HapticOpen().
@@ -275,61 +285,78 @@ func (h *Haptic) Close() {
275
285
276
286
// NumAxes returns the number of haptic axes the device has.
277
287
// (https://wiki.libsdl.org/SDL_HapticNumAxes)
278
- func (h * Haptic ) NumAxes () int {
279
- return int (C .SDL_HapticNumAxes (h .cptr ()))
288
+ func (h * Haptic ) NumAxes () (int , error ) {
289
+ i := int (C .SDL_HapticNumAxes (h .cptr ()))
290
+ return i , errorFromInt (i )
280
291
}
281
292
282
293
// NumEffects returns the number of effects a haptic device can store.
283
294
// (https://wiki.libsdl.org/SDL_HapticNumEffects)
284
- func (h * Haptic ) NumEffects () int {
285
- return int (C .SDL_HapticNumEffects (h .cptr ()))
295
+ func (h * Haptic ) NumEffects () (int , error ) {
296
+ i := int (C .SDL_HapticNumEffects (h .cptr ()))
297
+ return i , errorFromInt (i )
286
298
}
287
299
288
300
// NumEffectsPlaying reutrns the number of effects a haptic device can play at the same time.
289
301
// (https://wiki.libsdl.org/SDL_HapticNumEffectsPlaying)
290
- func (h * Haptic ) NumEffectsPlaying () int {
291
- return int (C .SDL_HapticNumEffectsPlaying (h .cptr ()))
302
+ func (h * Haptic ) NumEffectsPlaying () (int , error ) {
303
+ i := int (C .SDL_HapticNumEffectsPlaying (h .cptr ()))
304
+ return i , errorFromInt (i )
292
305
}
293
306
294
307
// Query returns haptic device's supported features in bitwise manner.
295
308
// (https://wiki.libsdl.org/SDL_HapticQuery)
296
- func (h * Haptic ) Query () uint {
297
- return uint (C .SDL_HapticQuery (h .cptr ()))
309
+ func (h * Haptic ) Query () (uint32 , error ) {
310
+ i := uint32 (C .SDL_HapticQuery (h .cptr ()))
311
+ if i == 0 {
312
+ return 0 , GetError ()
313
+ }
314
+ return i , nil
298
315
}
299
316
300
317
// EffectSupported reports whether an effect is supported by a haptic device.
301
318
// (https://wiki.libsdl.org/SDL_HapticEffectSupported)
302
319
func (h * Haptic ) EffectSupported (he * HapticEffect ) (bool , error ) {
303
- _he := (* C .SDL_HapticEffect )(unsafe .Pointer (he ))
304
- ret := int (C .SDL_HapticEffectSupported (h .cptr (), _he ))
320
+ ret := int (C .SDL_HapticEffectSupported (
321
+ h .cptr (),
322
+ (* C .SDL_HapticEffect )(unsafe .Pointer (he ))))
305
323
return ret == C .SDL_TRUE , errorFromInt (ret )
306
324
}
307
325
308
326
// NewEffect creates a new haptic effect on a specified device.
309
327
// (https://wiki.libsdl.org/SDL_HapticNewEffect)
310
328
func (h * Haptic ) NewEffect (he * HapticEffect ) (int , error ) {
311
- _he := (* C .SDL_HapticEffect )(unsafe .Pointer (he ))
312
- ret := int (C .SDL_HapticNewEffect (h .cptr (), _he ))
329
+ ret := int (C .SDL_HapticNewEffect (
330
+ h .cptr (),
331
+ (* C .SDL_HapticEffect )(unsafe .Pointer (he ))))
313
332
return ret , errorFromInt (ret )
314
333
}
315
334
316
335
// UpdateEffect updates the properties of an effect.
317
336
// (https://wiki.libsdl.org/SDL_HapticUpdateEffect)
318
337
func (h * Haptic ) UpdateEffect (effect int , data * HapticEffect ) error {
319
- _data := (* C .SDL_HapticEffect )(unsafe .Pointer (data ))
320
- return errorFromInt (int (C .SDL_HapticUpdateEffect (h .cptr (), C .int (effect ), _data )))
338
+ return errorFromInt (int (
339
+ C .SDL_HapticUpdateEffect (
340
+ h .cptr (),
341
+ C .int (effect ),
342
+ (* C .SDL_HapticEffect )(unsafe .Pointer (data )))))
321
343
}
322
344
323
345
// RunEffect runs the haptic effect on its associated haptic device.
324
346
// (https://wiki.libsdl.org/SDL_HapticRunEffect)
325
347
func (h * Haptic ) RunEffect (effect int , iterations uint32 ) error {
326
- return errorFromInt (int (C .SDL_HapticRunEffect (h .cptr (), C .int (effect ), C .Uint32 (iterations ))))
348
+ return errorFromInt (int (
349
+ C .SDL_HapticRunEffect (
350
+ h .cptr (),
351
+ C .int (effect ),
352
+ C .Uint32 (iterations ))))
327
353
}
328
354
329
355
// StopEffect stops the haptic effect on its associated haptic device.
330
356
// (https://wiki.libsdl.org/SDL_HapticStopEffect)
331
357
func (h * Haptic ) StopEffect (effect int ) error {
332
- return errorFromInt (int (C .SDL_HapticStopEffect (h .cptr (), C .int (effect ))))
358
+ return errorFromInt (int (
359
+ C .SDL_HapticStopEffect (h .cptr (), C .int (effect ))))
333
360
}
334
361
335
362
// DestroyEffect destroys a haptic effect on the device.
@@ -340,61 +367,71 @@ func (h *Haptic) DestroyEffect(effect int) {
340
367
341
368
// GetEffectStatus returns the status of the current effect on the specified haptic device.
342
369
// (https://wiki.libsdl.org/SDL_HapticGetEffectStatus)
343
- func (h * Haptic ) GetEffectStatus (effect int ) int {
344
- return int (C .SDL_HapticGetEffectStatus (h .cptr (), C .int (effect )))
370
+ func (h * Haptic ) GetEffectStatus (effect int ) (int , error ) {
371
+ i := int (C .SDL_HapticGetEffectStatus (h .cptr (), C .int (effect )))
372
+ return i , errorFromInt (i )
373
+
345
374
}
346
375
347
376
// SetGain sets the global gain of the specified haptic device.
348
377
// (https://wiki.libsdl.org/SDL_HapticSetGain)
349
378
func (h * Haptic ) SetGain (gain int ) error {
350
- return errorFromInt (int (C .SDL_HapticSetGain (h .cptr (), C .int (gain ))))
379
+ return errorFromInt (int (
380
+ C .SDL_HapticSetGain (h .cptr (), C .int (gain ))))
351
381
}
352
382
353
383
// SetAutocenter sets the global autocenter of the device.
354
384
// (https://wiki.libsdl.org/SDL_HapticSetAutocenter)
355
385
func (h * Haptic ) SetAutocenter (autocenter int ) error {
356
- return errorFromInt (int (C .SDL_HapticSetAutocenter (h .cptr (), C .int (autocenter ))))
386
+ return errorFromInt (int (
387
+ C .SDL_HapticSetAutocenter (h .cptr (), C .int (autocenter ))))
357
388
}
358
389
359
390
// Pause pauses a haptic device.
360
391
// (https://wiki.libsdl.org/SDL_HapticPause)
361
392
func (h * Haptic ) Pause () error {
362
- return errorFromInt (int (C .SDL_HapticPause (h .cptr ())))
393
+ return errorFromInt (int (
394
+ C .SDL_HapticPause (h .cptr ())))
363
395
}
364
396
365
397
// Unpause unpauses a haptic device.
366
398
// (https://wiki.libsdl.org/SDL_HapticUnpause)
367
399
func (h * Haptic ) Unpause () error {
368
- return errorFromInt (int (C .SDL_HapticUnpause (h .cptr ())))
400
+ return errorFromInt (int (
401
+ C .SDL_HapticUnpause (h .cptr ())))
369
402
}
370
403
371
404
// StopAll stops all the currently playing effects on a haptic device.
372
405
// (https://wiki.libsdl.org/SDL_HapticStopAll)
373
406
func (h * Haptic ) StopAll () error {
374
- return errorFromInt (int (C .SDL_HapticStopAll (h .cptr ())))
407
+ return errorFromInt (int (
408
+ C .SDL_HapticStopAll (h .cptr ())))
375
409
}
376
410
377
411
// RumbleSupported reports whether rumble is supported on a haptic device.
378
412
// (https://wiki.libsdl.org/SDL_HapticRumbleSupported)
379
- func (h * Haptic ) RumbleSupported () (ok bool , err error ) {
413
+ func (h * Haptic ) RumbleSupported () (bool , error ) {
380
414
ret := int (C .SDL_HapticRumbleSupported (h .cptr ()))
381
415
return ret == C .SDL_TRUE , errorFromInt (ret )
382
416
}
383
417
384
418
// RumbleInit initializes the haptic device for simple rumble playback.
385
419
// (https://wiki.libsdl.org/SDL_HapticRumbleInit)
386
420
func (h * Haptic ) RumbleInit () error {
387
- return errorFromInt (int (C .SDL_HapticRumbleInit (h .cptr ())))
421
+ return errorFromInt (int (
422
+ C .SDL_HapticRumbleInit (h .cptr ())))
388
423
}
389
424
390
425
// RumblePlay runs a simple rumble effect on a haptic device.
391
426
// (https://wiki.libsdl.org/SDL_HapticRumblePlay)
392
427
func (h * Haptic ) RumblePlay (strength float32 , length uint32 ) error {
393
- return errorFromInt (int (C .SDL_HapticRumblePlay (h .cptr (), C .float (strength ), C .Uint32 (length ))))
428
+ return errorFromInt (int (
429
+ C .SDL_HapticRumblePlay (h .cptr (), C .float (strength ), C .Uint32 (length ))))
394
430
}
395
431
396
432
// RumbleStop stops the simple rumble on a haptic device.
397
433
// (https://wiki.libsdl.org/SDL_HapticRumbleStop)
398
434
func (h * Haptic ) RumbleStop () error {
399
- return errorFromInt (int (C .SDL_HapticRumbleStop (h .cptr ())))
435
+ return errorFromInt (int (
436
+ C .SDL_HapticRumbleStop (h .cptr ())))
400
437
}
0 commit comments