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"
134 constexpr explicit operator bool()
const {
return !!
value; }
799 constexpr Haptic(std::nullptr_t =
nullptr) noexcept
812 : m_resource(resource)
855 : m_resource(SDL_OpenHaptic(instance_id))
880 : m_resource(
CheckError(SDL_OpenHapticFromJoystick(joystick)))
903 std::swap(m_resource, other.m_resource);
919 m_resource =
nullptr;
927 constexpr explicit operator bool() const noexcept {
return !!m_resource; }
930 constexpr operator HapticParam() const noexcept {
return {m_resource}; }
1312 auto data = SDL_GetHaptics(&count);
1332 return SDL_GetHapticNameForID(instance_id);
1371 return {
CheckError(SDL_GetHapticFromID(instance_id))};
1403 return SDL_GetHapticName(haptic);
1432 return Haptic(SDL_OpenHapticFromMouse());
1449 return SDL_IsJoystickHaptic(joystick);
1508 return SDL_GetMaxHapticEffects(haptic);
1532 return SDL_GetMaxHapticEffectsPlaying(haptic);
1554 return SDL_GetHapticFeatures(haptic);
1576 return CheckError(SDL_GetNumHapticAxes(haptic));
1596 return SDL_HapticEffectSupported(haptic, &effect);
1622 return CheckError(SDL_CreateHapticEffect(haptic, &effect));
1653 CheckError(SDL_UpdateHapticEffect(haptic, effect, &data));
1686 CheckError(SDL_RunHapticEffect(haptic, effect, iterations));
1708 CheckError(SDL_StopHapticEffect(haptic, effect));
1731 SDL_DestroyHapticEffect(haptic, effect);
1755 return SDL_GetHapticEffectStatus(haptic, effect);
1806 CheckError(SDL_SetHapticAutocenter(haptic, autocenter));
1886 return SDL_HapticRumbleSupported(haptic);
1928 CheckError(SDL_PlayHapticRumble(haptic, strength, length));
The haptic structure used to identify an SDL haptic.
Definition: SDL3pp_haptic.h:794
constexpr auto operator<=>(const Haptic &other) const noexcept=default
Comparison.
constexpr HapticRaw get() const noexcept
Retrieves underlying HapticRaw.
Definition: SDL3pp_haptic.h:913
constexpr Haptic & operator=(Haptic &&other) noexcept
Assignment operator.
Definition: SDL3pp_haptic.h:901
constexpr Haptic(Haptic &&other) noexcept
Move constructor.
Definition: SDL3pp_haptic.h:822
Haptic(JoystickParam joystick)
Open a haptic device for use from a joystick device.
Definition: SDL3pp_haptic.h:879
constexpr Haptic(const Haptic &other) noexcept=default
Copy constructor.
~Haptic()
Destructor.
Definition: SDL3pp_haptic.h:898
Haptic(HapticID instance_id)
Open a haptic device for use.
Definition: SDL3pp_haptic.h:854
constexpr Haptic & operator=(const Haptic &other) noexcept=default
Assignment operator.
constexpr HapticRaw release() noexcept
Retrieves underlying HapticRaw and clear this.
Definition: SDL3pp_haptic.h:916
constexpr Haptic(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_haptic.h:799
constexpr Haptic(const HapticRaw resource) noexcept
Constructs from HapticParam.
Definition: SDL3pp_haptic.h:811
Base class for SDL memory allocated array wrap.
Definition: SDL3pp_ownPtr.h:44
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:197
void StopHapticEffects(HapticParam haptic)
Stop all the currently playing effects on a haptic device.
Definition: SDL3pp_haptic.h:1867
void RunEffect(HapticEffectID effect, Uint32 iterations)
Run the haptic effect on its associated haptic device.
Definition: SDL3pp_haptic.h:1689
constexpr HapticEffectType HAPTIC_FRICTION
Friction effect supported - uses axes movement.
Definition: SDL3pp_haptic.h:283
Haptic OpenHaptic(HapticID instance_id)
Open a haptic device for use.
Definition: SDL3pp_haptic.h:1358
void StopHapticRumble(HapticParam haptic)
Stop the simple rumble on a haptic device.
Definition: SDL3pp_haptic.h:1946
int GetMaxHapticEffectsPlaying(HapticParam haptic)
Get the number of effects a haptic device can play at the same time.
Definition: SDL3pp_haptic.h:1530
void Pause()
Pause a haptic device.
Definition: SDL3pp_haptic.h:1835
void SetHapticAutocenter(HapticParam haptic, int autocenter)
Set the global autocenter of the device.
Definition: SDL3pp_haptic.h:1804
constexpr HapticEffectType HAPTIC_GAIN
Device can set global gain.
Definition: SDL3pp_haptic.h:335
bool IsJoystickHaptic(JoystickParam joystick)
Query if a joystick has haptic features.
Definition: SDL3pp_haptic.h:1447
void SetGain(int gain)
Set the global gain of the specified haptic device.
Definition: SDL3pp_haptic.h:1786
SDL_HapticDirection HapticDirection
Structure that represents a haptic direction.
Definition: SDL3pp_haptic.h:535
int GetMaxEffectsPlaying()
Get the number of effects a haptic device can play at the same time.
Definition: SDL3pp_haptic.h:1535
HapticID GetHapticID(HapticParam haptic)
Get the instance ID of an opened haptic device.
Definition: SDL3pp_haptic.h:1383
constexpr HapticEffectType HAPTIC_SINE
Sine wave effect supported.
Definition: SDL3pp_haptic.h:180
Haptic OpenHapticFromJoystick(JoystickParam joystick)
Open a haptic device for use from a joystick device.
Definition: SDL3pp_haptic.h:1472
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:780
void SetHapticGain(HapticParam haptic, int gain)
Set the global gain of the specified haptic device.
Definition: SDL3pp_haptic.h:1781
constexpr Uint32 HAPTIC_INFINITY
Used to play a device an infinite number of times.
Definition: SDL3pp_haptic.h:429
constexpr HapticEffectType HAPTIC_DAMPER
Damper effect supported - uses axes velocity.
Definition: SDL3pp_haptic.h:259
bool HapticEffectSupported(HapticParam haptic, const HapticEffect &effect)
Check to see if an effect is supported by a haptic device.
Definition: SDL3pp_haptic.h:1593
void StopEffect(HapticEffectID effect)
Stop the haptic effect on its associated haptic device.
Definition: SDL3pp_haptic.h:1711
HapticEffectID CreateEffect(const HapticEffect &effect)
Create a new haptic effect on a specified device.
Definition: SDL3pp_haptic.h:1625
Uint8 HapticDirectionType
Type of coordinates used for haptic direction.
Definition: SDL3pp_haptic.h:379
void PlayHapticRumble(HapticParam haptic, float strength, Uint32 length)
Run a simple rumble effect on a haptic device.
Definition: SDL3pp_haptic.h:1926
int GetNumHapticAxes(HapticParam haptic)
Get the number of haptic axes the device has.
Definition: SDL3pp_haptic.h:1574
void InitHapticRumble(HapticParam haptic)
Initialize a haptic device for simple rumble playback.
Definition: SDL3pp_haptic.h:1906
void Resume()
Resume a haptic device.
Definition: SDL3pp_haptic.h:1854
constexpr HapticEffectType HAPTIC_RESERVED3
Reserved for future use.
Definition: SDL3pp_haptic.h:315
const char * GetHapticName(HapticParam haptic)
Get the implementation dependent name of a haptic device.
Definition: SDL3pp_haptic.h:1401
constexpr HapticEffectType HAPTIC_INERTIA
Inertia effect supported - uses axes acceleration.
Definition: SDL3pp_haptic.h:271
constexpr HapticEffectType HAPTIC_SPRING
Spring effect supported - uses axes position.
Definition: SDL3pp_haptic.h:247
void RunHapticEffect(HapticParam haptic, HapticEffectID effect, Uint32 iterations)
Run the haptic effect on its associated haptic device.
Definition: SDL3pp_haptic.h:1682
constexpr HapticEffectType HAPTIC_LEFTRIGHT
Left/Right effect supported.
Definition: SDL3pp_haptic.h:294
SDL_HapticCondition HapticCondition
A structure containing a template for a Condition effect.
Definition: SDL3pp_haptic.h:642
const char * GetHapticNameForID(HapticID instance_id)
Get the implementation dependent name of a haptic device.
Definition: SDL3pp_haptic.h:1330
void UpdateHapticEffect(HapticParam haptic, HapticEffectID effect, const HapticEffect &data)
Update the properties of an effect.
Definition: SDL3pp_haptic.h:1649
constexpr HapticEffectType HAPTIC_CUSTOM
Custom effect is supported.
Definition: SDL3pp_haptic.h:324
void InitRumble()
Initialize a haptic device for simple rumble playback.
Definition: SDL3pp_haptic.h:1911
void StopRumble()
Stop the simple rumble on a haptic device.
Definition: SDL3pp_haptic.h:1951
void SetAutocenter(int autocenter)
Set the global autocenter of the device.
Definition: SDL3pp_haptic.h:1809
Haptic OpenHapticFromMouse()
Try to open a haptic device from the current mouse.
Definition: SDL3pp_haptic.h:1430
constexpr HapticDirectionType HAPTIC_STEERING_AXIS
Use this value to play an effect on the steering wheel axis.
Definition: SDL3pp_haptic.h:418
bool IsMouseHaptic()
Query whether or not the current mouse has haptic capabilities.
Definition: SDL3pp_haptic.h:1417
bool GetEffectStatus(HapticEffectID effect)
Get the status of the current effect on the specified haptic device.
Definition: SDL3pp_haptic.h:1758
void UpdateEffect(HapticEffectID effect, const HapticEffect &data)
Update the properties of an effect.
Definition: SDL3pp_haptic.h:1656
SDL_HapticConstant HapticConstant
A structure containing a template for a Constant effect.
Definition: SDL3pp_haptic.h:550
int GetNumAxes()
Get the number of haptic axes the device has.
Definition: SDL3pp_haptic.h:1579
SDL_HapticRamp HapticRamp
A structure containing a template for a Ramp effect.
Definition: SDL3pp_haptic.h:659
void PlayRumble(float strength, Uint32 length)
Run a simple rumble effect on a haptic device.
Definition: SDL3pp_haptic.h:1931
bool RumbleSupported()
Check whether rumble is supported on a haptic device.
Definition: SDL3pp_haptic.h:1889
constexpr HapticEffectType HAPTIC_PAUSE
Device can be paused.
Definition: SDL3pp_haptic.h:369
constexpr HapticEffectType HAPTIC_SQUARE
Square wave effect supported.
Definition: SDL3pp_haptic.h:191
SDL_Haptic * HapticRaw
Alias to raw representation for Haptic.
Definition: SDL3pp_haptic.h:111
constexpr HapticEffectType HAPTIC_TRIANGLE
Triangle wave effect supported.
Definition: SDL3pp_haptic.h:202
bool EffectSupported(const HapticEffect &effect)
Check to see if an effect is supported by a haptic device.
Definition: SDL3pp_haptic.h:1599
SDL_HapticPeriodic HapticPeriodic
A structure containing a template for a Periodic effect.
Definition: SDL3pp_haptic.h:614
int HapticEffectID
ID for haptic effects.
Definition: SDL3pp_haptic.h:155
Uint32 GetHapticFeatures(HapticParam haptic)
Get the haptic device's supported features in bitwise manner.
Definition: SDL3pp_haptic.h:1552
constexpr HapticEffectType HAPTIC_RESERVED1
Reserved for future use.
Definition: SDL3pp_haptic.h:301
void CloseHaptic(HapticRaw haptic)
Close a haptic device previously opened with Haptic.Haptic().
Definition: SDL3pp_haptic.h:1486
constexpr HapticDirectionType HAPTIC_SPHERICAL
Uses spherical coordinates for the direction.
Definition: SDL3pp_haptic.h:406
constexpr HapticEffectType HAPTIC_AUTOCENTER
Device can set autocenter.
Definition: SDL3pp_haptic.h:346
void ResumeHaptic(HapticParam haptic)
Resume a haptic device.
Definition: SDL3pp_haptic.h:1849
static Haptic OpenFromMouse()
Try to open a haptic device from the current mouse.
Definition: SDL3pp_haptic.h:1435
HapticID GetID()
Get the instance ID of an opened haptic device.
Definition: SDL3pp_haptic.h:1388
HapticEffectID CreateHapticEffect(HapticParam haptic, const HapticEffect &effect)
Create a new haptic effect on a specified device.
Definition: SDL3pp_haptic.h:1619
constexpr HapticEffectType HAPTIC_SAWTOOTHDOWN
Sawtoothdown wave effect supported.
Definition: SDL3pp_haptic.h:224
constexpr HapticDirectionType HAPTIC_CARTESIAN
Uses cartesian coordinates for the direction.
Definition: SDL3pp_haptic.h:397
bool HapticRumbleSupported(HapticParam haptic)
Check whether rumble is supported on a haptic device.
Definition: SDL3pp_haptic.h:1884
int GetMaxEffects()
Get the number of effects a haptic device can store.
Definition: SDL3pp_haptic.h:1511
void StopHapticEffect(HapticParam haptic, HapticEffectID effect)
Stop the haptic effect on its associated haptic device.
Definition: SDL3pp_haptic.h:1706
constexpr HapticDirectionType HAPTIC_POLAR
Uses polar coordinates for the direction.
Definition: SDL3pp_haptic.h:388
void DestroyEffect(HapticEffectID effect)
Destroy a haptic effect on the device.
Definition: SDL3pp_haptic.h:1734
constexpr HapticEffectType HAPTIC_CONSTANT
Constant effect supported.
Definition: SDL3pp_haptic.h:169
int GetMaxHapticEffects(HapticParam haptic)
Get the number of effects a haptic device can store.
Definition: SDL3pp_haptic.h:1506
Uint32 HapticEffectType
Type of haptic effect.
Definition: SDL3pp_haptic.h:158
constexpr HapticEffectType HAPTIC_RESERVED2
Reserved for future use.
Definition: SDL3pp_haptic.h:308
HapticRef GetHapticFromID(HapticID instance_id)
Get the Haptic associated with an instance ID, if it has been opened.
Definition: SDL3pp_haptic.h:1369
const char * GetName()
Get the implementation dependent name of a haptic device.
Definition: SDL3pp_haptic.h:1406
constexpr HapticEffectType HAPTIC_STATUS
Device can be queried for effect status.
Definition: SDL3pp_haptic.h:357
SDL_HapticCustom HapticCustom
A structure containing a template for the HAPTIC_CUSTOM effect.
Definition: SDL3pp_haptic.h:694
OwnArray< HapticID > GetHaptics()
Get a list of currently connected haptic devices.
Definition: SDL3pp_haptic.h:1309
Uint32 GetFeatures()
Get the haptic device's supported features in bitwise manner.
Definition: SDL3pp_haptic.h:1557
void PauseHaptic(HapticParam haptic)
Pause a haptic device.
Definition: SDL3pp_haptic.h:1830
constexpr HapticEffectType HAPTIC_SAWTOOTHUP
Sawtoothup wave effect supported.
Definition: SDL3pp_haptic.h:213
SDL_HapticEffect HapticEffect
The generic template for any haptic effect.
Definition: SDL3pp_haptic.h:768
void StopEffects()
Stop all the currently playing effects on a haptic device.
Definition: SDL3pp_haptic.h:1872
SDL_HapticLeftRight HapticLeftRight
A structure containing a template for a Left/Right effect.
Definition: SDL3pp_haptic.h:675
bool GetHapticEffectStatus(HapticParam haptic, HapticEffectID effect)
Get the status of the current effect on the specified haptic device.
Definition: SDL3pp_haptic.h:1753
constexpr HapticEffectType HAPTIC_RAMP
Ramp effect supported.
Definition: SDL3pp_haptic.h:235
void Close()
Close a haptic device previously opened with Haptic.Haptic().
Definition: SDL3pp_haptic.h:1488
void DestroyHapticEffect(HapticParam haptic, HapticEffectID effect)
Destroy a haptic effect on the device.
Definition: SDL3pp_haptic.h:1729
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:341
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition: SDL3pp_stdinc.h:289
Main include header for the SDL3pp library.
Safely wrap Haptic for non owning parameters.
Definition: SDL3pp_haptic.h:118
constexpr HapticParam(HapticRaw value)
Constructs from HapticRaw.
Definition: SDL3pp_haptic.h:122
constexpr HapticParam(std::nullptr_t=nullptr)
Constructs null/invalid.
Definition: SDL3pp_haptic.h:128
constexpr auto operator<=>(const HapticParam &other) const =default
Comparison.
HapticRaw value
parameter's HapticRaw
Definition: SDL3pp_haptic.h:119
Semi-safe reference for Haptic.
Definition: SDL3pp_haptic.h:1265
HapticRef(HapticParam resource) noexcept
Constructs from HapticParam.
Definition: SDL3pp_haptic.h:1275
~HapticRef()
Destructor.
Definition: SDL3pp_haptic.h:1296
HapticRef(HapticRaw resource) noexcept
Constructs from HapticParam.
Definition: SDL3pp_haptic.h:1287
constexpr HapticRef(const HapticRef &other) noexcept=default
Copy constructor.
Safely wrap Joystick for non owning parameters.
Definition: SDL3pp_joystick.h:68