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"
1116 using HapticBase::HapticBase;
1132 :
Haptic(other.release())
1220 auto data = SDL_GetHaptics(&count);
1240 return SDL_GetHapticNameForID(instance_id);
1269 :
Haptic(SDL_OpenHaptic(instance_id))
1289 return {
CheckError(SDL_GetHapticFromID(instance_id))};
1321 return SDL_GetHapticName(haptic);
1350 return Haptic(SDL_OpenHapticFromMouse());
1367 return SDL_IsJoystickHaptic(joystick);
1426 return SDL_GetMaxHapticEffects(haptic);
1450 return SDL_GetMaxHapticEffectsPlaying(haptic);
1473 return CheckError(SDL_GetHapticFeatures(haptic));
1495 return CheckError(SDL_GetNumHapticAxes(haptic));
1514 return SDL_HapticEffectSupported(haptic, &effect);
1540 return CheckError(SDL_CreateHapticEffect(haptic, &effect));
1571 CheckError(SDL_UpdateHapticEffect(haptic, effect, &data));
1604 CheckError(SDL_RunHapticEffect(haptic, effect, iterations));
1626 CheckError(SDL_StopHapticEffect(haptic, effect));
1649 SDL_DestroyHapticEffect(haptic, effect);
1673 return SDL_GetHapticEffectStatus(haptic, effect);
1724 CheckError(SDL_SetHapticAutocenter(haptic, autocenter));
1804 return SDL_HapticRumbleSupported(haptic);
1846 CheckError(SDL_PlayHapticRumble(haptic, strength, length));
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:57
friend constexpr void swap(ResourceBaseT &lhs, ResourceBaseT &rhs) noexcept
Definition SDL3pp_resource.h:65
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:54
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
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:515
SDL_Haptic * HapticRaw
Alias to raw representation for Haptic.
Definition SDL3pp_haptic.h:114
void RunEffect(HapticEffectID effect, Uint32 iterations)
Run the haptic effect on its associated haptic device.
Definition SDL3pp_haptic.h:1607
constexpr HapticEffectType HAPTIC_FRICTION
Friction effect supported - uses axes movement.
Definition SDL3pp_haptic.h:263
void SetHapticAutocenter(HapticRef haptic, int autocenter)
Set the global autocenter of the device.
Definition SDL3pp_haptic.h:1722
SDL_HapticConstant HapticConstant
A structure containing a template for a Constant effect.
Definition SDL3pp_haptic.h:530
Haptic OpenHaptic(HapticID instance_id)
Open a haptic device for use.
Definition SDL3pp_haptic.h:1266
bool HapticRumbleSupported(HapticRef haptic)
Check whether rumble is supported on a haptic device.
Definition SDL3pp_haptic.h:1802
constexpr HapticEffectType HAPTIC_GAIN
Device can set global gain.
Definition SDL3pp_haptic.h:315
void InitHapticRumble(HapticRef haptic)
Initialize a haptic device for simple rumble playback.
Definition SDL3pp_haptic.h:1824
bool GetEffectStatus(HapticEffectID effect)
Get the status of the current effect on the specified haptic device.
Definition SDL3pp_haptic.h:1676
SDL_HapticLeftRight HapticLeftRight
A structure containing a template for a Left/Right effect.
Definition SDL3pp_haptic.h:655
constexpr HapticEffectType HAPTIC_SINE
Sine wave effect supported.
Definition SDL3pp_haptic.h:160
void StopHapticEffects(HapticRef haptic)
Stop all the currently playing effects on a haptic device.
Definition SDL3pp_haptic.h:1785
int GetMaxHapticEffectsPlaying(HapticRef haptic)
Get the number of effects a haptic device can play at the same time.
Definition SDL3pp_haptic.h:1448
constexpr Uint32 HAPTIC_INFINITY
Used to play a device an infinite number of times.
Definition SDL3pp_haptic.h:409
void Resume()
Resume a haptic device.
Definition SDL3pp_haptic.h:1772
constexpr HapticEffectType HAPTIC_DAMPER
Damper effect supported - uses axes velocity.
Definition SDL3pp_haptic.h:239
void DestroyHapticEffect(HapticRef haptic, HapticEffectID effect)
Destroy a haptic effect on the device.
Definition SDL3pp_haptic.h:1647
int GetNumHapticAxes(HapticRef haptic)
Get the number of haptic axes the device has.
Definition SDL3pp_haptic.h:1493
void StopHapticRumble(HapticRef haptic)
Stop the simple rumble on a haptic device.
Definition SDL3pp_haptic.h:1864
void RunHapticEffect(HapticRef haptic, HapticEffectID effect, Uint32 iterations)
Run the haptic effect on its associated haptic device.
Definition SDL3pp_haptic.h:1600
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:760
Uint8 HapticDirectionType
Type of coordinates used for haptic direction.
Definition SDL3pp_haptic.h:359
void ResumeHaptic(HapticRef haptic)
Resume a haptic device.
Definition SDL3pp_haptic.h:1767
int GetMaxEffects()
Get the number of effects a haptic device can store.
Definition SDL3pp_haptic.h:1429
constexpr HapticEffectType HAPTIC_RESERVED3
Reserved for future use.
Definition SDL3pp_haptic.h:295
int HapticEffectID
ID for haptic effects.
Definition SDL3pp_haptic.h:135
HapticID GetHapticID(HapticRef haptic)
Get the instance ID of an opened haptic device.
Definition SDL3pp_haptic.h:1301
constexpr HapticEffectType HAPTIC_INERTIA
Inertia effect supported - uses axes acceleration.
Definition SDL3pp_haptic.h:251
ResourceRefT< HapticBase > HapticRef
Reference for Haptic.
Definition SDL3pp_haptic.h:121
bool GetHapticEffectStatus(HapticRef haptic, HapticEffectID effect)
Get the status of the current effect on the specified haptic device.
Definition SDL3pp_haptic.h:1671
constexpr HapticEffectType HAPTIC_SPRING
Spring effect supported - uses axes position.
Definition SDL3pp_haptic.h:227
constexpr HapticEffectType HAPTIC_LEFTRIGHT
Left/Right effect supported.
Definition SDL3pp_haptic.h:274
const char * GetHapticNameForID(HapticID instance_id)
Get the implementation dependent name of a haptic device.
Definition SDL3pp_haptic.h:1238
SDL_HapticCondition HapticCondition
A structure containing a template for a Condition effect.
Definition SDL3pp_haptic.h:622
HapticEffectID CreateHapticEffect(HapticRef haptic, const HapticEffect &effect)
Create a new haptic effect on a specified device.
Definition SDL3pp_haptic.h:1537
void StopEffect(HapticEffectID effect)
Stop the haptic effect on its associated haptic device.
Definition SDL3pp_haptic.h:1629
void SetAutocenter(int autocenter)
Set the global autocenter of the device.
Definition SDL3pp_haptic.h:1727
constexpr HapticEffectType HAPTIC_CUSTOM
Custom effect is supported.
Definition SDL3pp_haptic.h:304
void StopRumble()
Stop the simple rumble on a haptic device.
Definition SDL3pp_haptic.h:1869
Haptic OpenHapticFromMouse()
Try to open a haptic device from the current mouse.
Definition SDL3pp_haptic.h:1348
Uint32 HapticEffectType
Type of haptic effect.
Definition SDL3pp_haptic.h:138
constexpr HapticDirectionType HAPTIC_STEERING_AXIS
Use this value to play an effect on the steering wheel axis.
Definition SDL3pp_haptic.h:398
bool IsMouseHaptic()
Query whether or not the current mouse has haptic capabilities.
Definition SDL3pp_haptic.h:1335
void UpdateEffect(HapticEffectID effect, const HapticEffect &data)
Update the properties of an effect.
Definition SDL3pp_haptic.h:1574
bool HapticEffectSupported(HapticRef haptic, const HapticEffect &effect)
Check to see if an effect is supported by a haptic device.
Definition SDL3pp_haptic.h:1512
int GetMaxEffectsPlaying()
Get the number of effects a haptic device can play at the same time.
Definition SDL3pp_haptic.h:1453
Haptic OpenHapticFromJoystick(JoystickRef joystick)
Open a haptic device for use from a joystick device.
Definition SDL3pp_haptic.h:1390
void Close()
Close a haptic device previously opened with OpenHaptic().
Definition SDL3pp_haptic.h:1406
SDL_HapticRamp HapticRamp
A structure containing a template for a Ramp effect.
Definition SDL3pp_haptic.h:639
constexpr HapticEffectType HAPTIC_PAUSE
Device can be paused.
Definition SDL3pp_haptic.h:349
constexpr HapticEffectType HAPTIC_SQUARE
Square wave effect supported.
Definition SDL3pp_haptic.h:171
void PlayHapticRumble(HapticRef haptic, float strength, Uint32 length)
Run a simple rumble effect on a haptic device.
Definition SDL3pp_haptic.h:1844
int GetMaxHapticEffects(HapticRef haptic)
Get the number of effects a haptic device can store.
Definition SDL3pp_haptic.h:1424
constexpr HapticEffectType HAPTIC_TRIANGLE
Triangle wave effect supported.
Definition SDL3pp_haptic.h:182
void PauseHaptic(HapticRef haptic)
Pause a haptic device.
Definition SDL3pp_haptic.h:1748
void DestroyEffect(HapticEffectID effect)
Destroy a haptic effect on the device.
Definition SDL3pp_haptic.h:1652
void SetHapticGain(HapticRef haptic, int gain)
Set the global gain of the specified haptic device.
Definition SDL3pp_haptic.h:1699
const char * GetName()
Get the implementation dependent name of a haptic device.
Definition SDL3pp_haptic.h:1324
void UpdateHapticEffect(HapticRef haptic, HapticEffectID effect, const HapticEffect &data)
Update the properties of an effect.
Definition SDL3pp_haptic.h:1567
constexpr HapticEffectType HAPTIC_RESERVED1
Reserved for future use.
Definition SDL3pp_haptic.h:281
void CloseHaptic(HapticRaw haptic)
Close a haptic device previously opened with OpenHaptic().
Definition SDL3pp_haptic.h:1404
constexpr HapticDirectionType HAPTIC_SPHERICAL
Uses spherical coordinates for the direction.
Definition SDL3pp_haptic.h:386
HapticEffectID CreateEffect(const HapticEffect &effect)
Create a new haptic effect on a specified device.
Definition SDL3pp_haptic.h:1543
HapticID GetID()
Get the instance ID of an opened haptic device.
Definition SDL3pp_haptic.h:1306
constexpr HapticEffectType HAPTIC_AUTOCENTER
Device can set autocenter.
Definition SDL3pp_haptic.h:326
bool RumbleSupported()
Check whether rumble is supported on a haptic device.
Definition SDL3pp_haptic.h:1807
static Haptic OpenFromMouse()
Try to open a haptic device from the current mouse.
Definition SDL3pp_haptic.h:1353
constexpr HapticEffectType HAPTIC_SAWTOOTHDOWN
Sawtoothdown wave effect supported.
Definition SDL3pp_haptic.h:204
constexpr HapticDirectionType HAPTIC_CARTESIAN
Uses cartesian coordinates for the direction.
Definition SDL3pp_haptic.h:377
void InitRumble()
Initialize a haptic device for simple rumble playback.
Definition SDL3pp_haptic.h:1829
Uint32 GetHapticFeatures(HapticRef haptic)
Get the haptic device's supported features in bitwise manner.
Definition SDL3pp_haptic.h:1471
SDL_HapticEffect HapticEffect
The generic template for any haptic effect.
Definition SDL3pp_haptic.h:748
const char * GetHapticName(HapticRef haptic)
Get the implementation dependent name of a haptic device.
Definition SDL3pp_haptic.h:1319
constexpr HapticDirectionType HAPTIC_POLAR
Uses polar coordinates for the direction.
Definition SDL3pp_haptic.h:368
bool IsJoystickHaptic(JoystickRef joystick)
Query if a joystick has haptic features.
Definition SDL3pp_haptic.h:1365
constexpr HapticEffectType HAPTIC_CONSTANT
Constant effect supported.
Definition SDL3pp_haptic.h:149
SDL_HapticCustom HapticCustom
A structure containing a template for the HAPTIC_CUSTOM effect.
Definition SDL3pp_haptic.h:674
constexpr HapticEffectType HAPTIC_RESERVED2
Reserved for future use.
Definition SDL3pp_haptic.h:288
HapticRef GetHapticFromID(HapticID instance_id)
Get the Haptic associated with an instance ID, if it has been opened.
Definition SDL3pp_haptic.h:1287
constexpr HapticEffectType HAPTIC_STATUS
Device can be queried for effect status.
Definition SDL3pp_haptic.h:337
void PlayRumble(float strength, Uint32 length)
Run a simple rumble effect on a haptic device.
Definition SDL3pp_haptic.h:1849
int GetNumAxes()
Get the number of haptic axes the device has.
Definition SDL3pp_haptic.h:1498
void Pause()
Pause a haptic device.
Definition SDL3pp_haptic.h:1753
Uint32 GetFeatures()
Get the haptic device's supported features in bitwise manner.
Definition SDL3pp_haptic.h:1476
OwnArray< HapticID > GetHaptics()
Get a list of currently connected haptic devices.
Definition SDL3pp_haptic.h:1217
constexpr HapticEffectType HAPTIC_SAWTOOTHUP
Sawtoothup wave effect supported.
Definition SDL3pp_haptic.h:193
void StopHapticEffect(HapticRef haptic, HapticEffectID effect)
Stop the haptic effect on its associated haptic device.
Definition SDL3pp_haptic.h:1624
SDL_HapticPeriodic HapticPeriodic
A structure containing a template for a Periodic effect.
Definition SDL3pp_haptic.h:594
void StopEffects()
Stop all the currently playing effects on a haptic device.
Definition SDL3pp_haptic.h:1790
bool EffectSupported(const HapticEffect &effect)
Check to see if an effect is supported by a haptic device.
Definition SDL3pp_haptic.h:1517
void SetGain(int gain)
Set the global gain of the specified haptic device.
Definition SDL3pp_haptic.h:1704
constexpr HapticEffectType HAPTIC_RAMP
Ramp effect supported.
Definition SDL3pp_haptic.h:215
ResourceRefT< JoystickBase > JoystickRef
Reference for Joystick.
Definition SDL3pp_joystick.h:71
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition SDL3pp_stdinc.h:296
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition SDL3pp_stdinc.h:244
Main include header for the SDL3pp library.
Base class to Haptic.
Definition SDL3pp_haptic.h:768
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
The haptic structure used to identify an SDL haptic.
Definition SDL3pp_haptic.h:1115
constexpr Haptic(HapticRaw resource) noexcept
Constructs from raw Haptic.
Definition SDL3pp_haptic.h:1125
constexpr Haptic & operator=(Haptic &&other) noexcept
Assignment operator.
Definition SDL3pp_haptic.h:1200
constexpr Haptic(Haptic &&other) noexcept
Move constructor.
Definition SDL3pp_haptic.h:1131
~Haptic()
Destructor.
Definition SDL3pp_haptic.h:1197
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93