1#ifndef SDL3PP_HAPTIC_H_
2#define SDL3PP_HAPTIC_H_
4#include <SDL3/SDL_haptic.h>
5#include "SDL3pp_error.h"
6#include "SDL3pp_joystick.h"
7#include "SDL3pp_stdinc.h"
1217 auto data = SDL_GetHaptics(&count);
1237 return SDL_GetHapticNameForID(instance_id);
1266 :
Haptic(SDL_OpenHaptic(instance_id))
1286 return {
CheckError(SDL_GetHapticFromID(instance_id))};
1318 return SDL_GetHapticName(haptic);
1347 return Haptic(SDL_OpenHapticFromMouse());
1364 return SDL_IsJoystickHaptic(joystick);
1423 return SDL_GetMaxHapticEffects(haptic);
1444 return SDL_GetMaxHapticEffectsPlaying(haptic);
1467 return CheckError(SDL_GetHapticFeatures(haptic));
1486 return CheckError(SDL_GetNumHapticAxes(haptic));
1505 return SDL_HapticEffectSupported(haptic, &effect);
1531 return CheckError(SDL_CreateHapticEffect(haptic, &effect));
1562 CheckError(SDL_UpdateHapticEffect(haptic, effect, &data));
1595 CheckError(SDL_RunHapticEffect(haptic, effect, iterations));
1617 CheckError(SDL_StopHapticEffect(haptic, effect));
1640 SDL_DestroyHapticEffect(haptic, effect);
1664 return SDL_GetHapticEffectStatus(haptic, effect);
1715 CheckError(SDL_SetHapticAutocenter(haptic, autocenter));
1795 return SDL_HapticRumbleSupported(haptic);
1837 CheckError(SDL_PlayHapticRumble(haptic, strength, length));
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:53
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:56
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
SDL_HapticDirection HapticDirection
Structure that represents a haptic direction.
Definition SDL3pp_haptic.h:512
SDL_Haptic * HapticRaw
Alias to raw representation for Haptic.
Definition SDL3pp_haptic.h:111
void RunEffect(HapticEffectID effect, Uint32 iterations)
Run the haptic effect on its associated haptic device.
Definition SDL3pp_haptic.h:1598
constexpr HapticEffectType HAPTIC_FRICTION
Friction effect supported - uses axes movement.
Definition SDL3pp_haptic.h:260
void SetHapticAutocenter(HapticRef haptic, int autocenter)
Set the global autocenter of the device.
Definition SDL3pp_haptic.h:1713
SDL_HapticConstant HapticConstant
A structure containing a template for a Constant effect.
Definition SDL3pp_haptic.h:527
Haptic OpenHaptic(HapticID instance_id)
Open a haptic device for use.
Definition SDL3pp_haptic.h:1263
bool HapticRumbleSupported(HapticRef haptic)
Check whether rumble is supported on a haptic device.
Definition SDL3pp_haptic.h:1793
void Pause()
Pause a haptic device.
Definition SDL3pp_haptic.h:1744
constexpr HapticEffectType HAPTIC_GAIN
Device can set global gain.
Definition SDL3pp_haptic.h:312
void InitHapticRumble(HapticRef haptic)
Initialize a haptic device for simple rumble playback.
Definition SDL3pp_haptic.h:1815
ResourceRef< Haptic > HapticRef
Reference for Haptic.
Definition SDL3pp_haptic.h:118
SDL_HapticLeftRight HapticLeftRight
A structure containing a template for a Left/Right effect.
Definition SDL3pp_haptic.h:652
void SetGain(int gain)
Set the global gain of the specified haptic device.
Definition SDL3pp_haptic.h:1695
int GetMaxEffectsPlaying()
Get the number of effects a haptic device can play at the same time.
Definition SDL3pp_haptic.h:1447
constexpr HapticEffectType HAPTIC_SINE
Sine wave effect supported.
Definition SDL3pp_haptic.h:157
void StopHapticEffects(HapticRef haptic)
Stop all the currently playing effects on a haptic device.
Definition SDL3pp_haptic.h:1776
int GetMaxHapticEffectsPlaying(HapticRef haptic)
Get the number of effects a haptic device can play at the same time.
Definition SDL3pp_haptic.h:1442
constexpr Uint32 HAPTIC_INFINITY
Used to play a device an infinite number of times.
Definition SDL3pp_haptic.h:406
constexpr HapticEffectType HAPTIC_DAMPER
Damper effect supported - uses axes velocity.
Definition SDL3pp_haptic.h:236
void DestroyHapticEffect(HapticRef haptic, HapticEffectID effect)
Destroy a haptic effect on the device.
Definition SDL3pp_haptic.h:1638
void StopEffect(HapticEffectID effect)
Stop the haptic effect on its associated haptic device.
Definition SDL3pp_haptic.h:1620
int GetNumHapticAxes(HapticRef haptic)
Get the number of haptic axes the device has.
Definition SDL3pp_haptic.h:1484
void StopHapticRumble(HapticRef haptic)
Stop the simple rumble on a haptic device.
Definition SDL3pp_haptic.h:1855
void RunHapticEffect(HapticRef haptic, HapticEffectID effect, Uint32 iterations)
Run the haptic effect on its associated haptic device.
Definition SDL3pp_haptic.h:1591
HapticEffectID CreateEffect(const HapticEffect &effect)
Create a new haptic effect on a specified device.
Definition SDL3pp_haptic.h:1534
SDL_HapticID HapticID
This is a unique ID for a haptic device for the time it is connected to the system,...
Definition SDL3pp_haptic.h:757
Uint8 HapticDirectionType
Type of coordinates used for haptic direction.
Definition SDL3pp_haptic.h:356
void Resume()
Resume a haptic device.
Definition SDL3pp_haptic.h:1763
void ResumeHaptic(HapticRef haptic)
Resume a haptic device.
Definition SDL3pp_haptic.h:1758
constexpr HapticEffectType HAPTIC_RESERVED3
Reserved for future use.
Definition SDL3pp_haptic.h:292
int HapticEffectID
ID for haptic effects.
Definition SDL3pp_haptic.h:132
HapticID GetHapticID(HapticRef haptic)
Get the instance ID of an opened haptic device.
Definition SDL3pp_haptic.h:1298
constexpr HapticEffectType HAPTIC_INERTIA
Inertia effect supported - uses axes acceleration.
Definition SDL3pp_haptic.h:248
bool GetHapticEffectStatus(HapticRef haptic, HapticEffectID effect)
Get the status of the current effect on the specified haptic device.
Definition SDL3pp_haptic.h:1662
constexpr HapticEffectType HAPTIC_SPRING
Spring effect supported - uses axes position.
Definition SDL3pp_haptic.h:224
constexpr HapticEffectType HAPTIC_LEFTRIGHT
Left/Right effect supported.
Definition SDL3pp_haptic.h:271
const char * GetHapticNameForID(HapticID instance_id)
Get the implementation dependent name of a haptic device.
Definition SDL3pp_haptic.h:1235
SDL_HapticCondition HapticCondition
A structure containing a template for a Condition effect.
Definition SDL3pp_haptic.h:619
HapticEffectID CreateHapticEffect(HapticRef haptic, const HapticEffect &effect)
Create a new haptic effect on a specified device.
Definition SDL3pp_haptic.h:1528
constexpr HapticEffectType HAPTIC_CUSTOM
Custom effect is supported.
Definition SDL3pp_haptic.h:301
void InitRumble()
Initialize a haptic device for simple rumble playback.
Definition SDL3pp_haptic.h:1820
void StopRumble()
Stop the simple rumble on a haptic device.
Definition SDL3pp_haptic.h:1860
void SetAutocenter(int autocenter)
Set the global autocenter of the device.
Definition SDL3pp_haptic.h:1718
Haptic OpenHapticFromMouse()
Try to open a haptic device from the current mouse.
Definition SDL3pp_haptic.h:1345
Uint32 HapticEffectType
Type of haptic effect.
Definition SDL3pp_haptic.h:135
constexpr HapticDirectionType HAPTIC_STEERING_AXIS
Use this value to play an effect on the steering wheel axis.
Definition SDL3pp_haptic.h:395
bool IsMouseHaptic()
Query whether or not the current mouse has haptic capabilities.
Definition SDL3pp_haptic.h:1332
bool GetEffectStatus(HapticEffectID effect)
Get the status of the current effect on the specified haptic device.
Definition SDL3pp_haptic.h:1667
void UpdateEffect(HapticEffectID effect, const HapticEffect &data)
Update the properties of an effect.
Definition SDL3pp_haptic.h:1565
int GetNumAxes()
Get the number of haptic axes the device has.
Definition SDL3pp_haptic.h:1489
bool HapticEffectSupported(HapticRef haptic, const HapticEffect &effect)
Check to see if an effect is supported by a haptic device.
Definition SDL3pp_haptic.h:1503
void PlayRumble(float strength, Uint32 length)
Run a simple rumble effect on a haptic device.
Definition SDL3pp_haptic.h:1840
bool RumbleSupported()
Check whether rumble is supported on a haptic device.
Definition SDL3pp_haptic.h:1798
Haptic OpenHapticFromJoystick(JoystickRef joystick)
Open a haptic device for use from a joystick device.
Definition SDL3pp_haptic.h:1387
SDL_HapticRamp HapticRamp
A structure containing a template for a Ramp effect.
Definition SDL3pp_haptic.h:636
constexpr HapticEffectType HAPTIC_PAUSE
Device can be paused.
Definition SDL3pp_haptic.h:346
constexpr HapticEffectType HAPTIC_SQUARE
Square wave effect supported.
Definition SDL3pp_haptic.h:168
void PlayHapticRumble(HapticRef haptic, float strength, Uint32 length)
Run a simple rumble effect on a haptic device.
Definition SDL3pp_haptic.h:1835
int GetMaxHapticEffects(HapticRef haptic)
Get the number of effects a haptic device can store.
Definition SDL3pp_haptic.h:1421
constexpr HapticEffectType HAPTIC_TRIANGLE
Triangle wave effect supported.
Definition SDL3pp_haptic.h:179
void PauseHaptic(HapticRef haptic)
Pause a haptic device.
Definition SDL3pp_haptic.h:1739
bool EffectSupported(const HapticEffect &effect)
Check to see if an effect is supported by a haptic device.
Definition SDL3pp_haptic.h:1508
void SetHapticGain(HapticRef haptic, int gain)
Set the global gain of the specified haptic device.
Definition SDL3pp_haptic.h:1690
void UpdateHapticEffect(HapticRef haptic, HapticEffectID effect, const HapticEffect &data)
Update the properties of an effect.
Definition SDL3pp_haptic.h:1558
constexpr HapticEffectType HAPTIC_RESERVED1
Reserved for future use.
Definition SDL3pp_haptic.h:278
void CloseHaptic(HapticRaw haptic)
Close a haptic device previously opened with OpenHaptic().
Definition SDL3pp_haptic.h:1401
constexpr HapticDirectionType HAPTIC_SPHERICAL
Uses spherical coordinates for the direction.
Definition SDL3pp_haptic.h:383
constexpr HapticEffectType HAPTIC_AUTOCENTER
Device can set autocenter.
Definition SDL3pp_haptic.h:323
static Haptic OpenFromMouse()
Try to open a haptic device from the current mouse.
Definition SDL3pp_haptic.h:1350
HapticID GetID()
Get the instance ID of an opened haptic device.
Definition SDL3pp_haptic.h:1303
constexpr HapticEffectType HAPTIC_SAWTOOTHDOWN
Sawtoothdown wave effect supported.
Definition SDL3pp_haptic.h:201
constexpr HapticDirectionType HAPTIC_CARTESIAN
Uses cartesian coordinates for the direction.
Definition SDL3pp_haptic.h:374
int GetMaxEffects()
Get the number of effects a haptic device can store.
Definition SDL3pp_haptic.h:1426
Uint32 GetHapticFeatures(HapticRef haptic)
Get the haptic device's supported features in bitwise manner.
Definition SDL3pp_haptic.h:1465
SDL_HapticEffect HapticEffect
The generic template for any haptic effect.
Definition SDL3pp_haptic.h:745
const char * GetHapticName(HapticRef haptic)
Get the implementation dependent name of a haptic device.
Definition SDL3pp_haptic.h:1316
constexpr HapticDirectionType HAPTIC_POLAR
Uses polar coordinates for the direction.
Definition SDL3pp_haptic.h:365
bool IsJoystickHaptic(JoystickRef joystick)
Query if a joystick has haptic features.
Definition SDL3pp_haptic.h:1362
void DestroyEffect(HapticEffectID effect)
Destroy a haptic effect on the device.
Definition SDL3pp_haptic.h:1643
constexpr HapticEffectType HAPTIC_CONSTANT
Constant effect supported.
Definition SDL3pp_haptic.h:146
SDL_HapticCustom HapticCustom
A structure containing a template for the HAPTIC_CUSTOM effect.
Definition SDL3pp_haptic.h:671
constexpr HapticEffectType HAPTIC_RESERVED2
Reserved for future use.
Definition SDL3pp_haptic.h:285
HapticRef GetHapticFromID(HapticID instance_id)
Get the Haptic associated with an instance ID, if it has been opened.
Definition SDL3pp_haptic.h:1284
const char * GetName()
Get the implementation dependent name of a haptic device.
Definition SDL3pp_haptic.h:1321
constexpr HapticEffectType HAPTIC_STATUS
Device can be queried for effect status.
Definition SDL3pp_haptic.h:334
OwnArray< HapticID > GetHaptics()
Get a list of currently connected haptic devices.
Definition SDL3pp_haptic.h:1214
Uint32 GetFeatures()
Get the haptic device's supported features in bitwise manner.
Definition SDL3pp_haptic.h:1470
constexpr HapticEffectType HAPTIC_SAWTOOTHUP
Sawtoothup wave effect supported.
Definition SDL3pp_haptic.h:190
void StopHapticEffect(HapticRef haptic, HapticEffectID effect)
Stop the haptic effect on its associated haptic device.
Definition SDL3pp_haptic.h:1615
SDL_HapticPeriodic HapticPeriodic
A structure containing a template for a Periodic effect.
Definition SDL3pp_haptic.h:591
void StopEffects()
Stop all the currently playing effects on a haptic device.
Definition SDL3pp_haptic.h:1781
constexpr HapticEffectType HAPTIC_RAMP
Ramp effect supported.
Definition SDL3pp_haptic.h:212
void Close()
Close a haptic device previously opened with OpenHaptic().
Definition SDL3pp_haptic.h:1403
ResourceRef< Joystick > JoystickRef
Reference for Joystick.
Definition SDL3pp_joystick.h:68
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition SDL3pp_stdinc.h:290
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition SDL3pp_stdinc.h:238
Main include header for the SDL3pp library.
The haptic structure used to identify an SDL haptic.
Definition SDL3pp_haptic.h:771
Haptic & operator=(const Haptic &other)=delete
Assignment operator.
constexpr Haptic(HapticRaw resource) noexcept
Constructs from raw Haptic.
Definition SDL3pp_haptic.h:781
constexpr Haptic & operator=(Haptic &&other) noexcept
Assignment operator.
Definition SDL3pp_haptic.h:863
constexpr Haptic(Haptic &&other) noexcept
Move constructor.
Definition SDL3pp_haptic.h:790
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
constexpr Haptic(const Haptic &other)=delete
Copy constructor.
~Haptic()
Destructor.
Definition SDL3pp_haptic.h:860
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:156