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; }
803 : m_resource(resource)
844 : m_resource(SDL_OpenHaptic(instance_id))
869 : m_resource(
CheckError(SDL_OpenHapticFromJoystick(joystick)))
892 std::swap(m_resource, other.m_resource);
903 m_resource =
nullptr;
911 constexpr bool operator==(std::nullptr_t _)
const {
return !m_resource; }
914 constexpr explicit operator bool()
const {
return !!m_resource; }
1288 auto data = SDL_GetHaptics(&count);
1308 return SDL_GetHapticNameForID(instance_id);
1347 return {
CheckError(SDL_GetHapticFromID(instance_id))};
1379 return SDL_GetHapticName(haptic);
1408 return Haptic(SDL_OpenHapticFromMouse());
1425 return SDL_IsJoystickHaptic(joystick);
1484 return SDL_GetMaxHapticEffects(haptic);
1508 return SDL_GetMaxHapticEffectsPlaying(haptic);
1530 return SDL_GetHapticFeatures(haptic);
1552 return CheckError(SDL_GetNumHapticAxes(haptic));
1572 return SDL_HapticEffectSupported(haptic, &effect);
1597 return CheckError(SDL_CreateHapticEffect(haptic, &effect));
1628 CheckError(SDL_UpdateHapticEffect(haptic, effect, &data));
1658 CheckError(SDL_RunHapticEffect(haptic, effect, iterations));
1680 CheckError(SDL_StopHapticEffect(haptic, effect));
1703 SDL_DestroyHapticEffect(haptic, effect);
1727 return SDL_GetHapticEffectStatus(haptic, effect);
1778 CheckError(SDL_SetHapticAutocenter(haptic, autocenter));
1858 return SDL_HapticRumbleSupported(haptic);
1900 CheckError(SDL_PlayHapticRumble(haptic, strength, length));
The haptic structure used to identify an SDL haptic.
Definition: SDL3pp_haptic.h:788
constexpr Haptic(Haptic &&other)
Move constructor.
Definition: SDL3pp_haptic.h:811
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_haptic.h:911
Haptic & operator=(Haptic other)
Assignment operator.
Definition: SDL3pp_haptic.h:890
constexpr HapticRaw release()
Retrieves underlying HapticRaw and clear this.
Definition: SDL3pp_haptic.h:900
constexpr HapticRaw get() const
Retrieves underlying HapticRaw.
Definition: SDL3pp_haptic.h:897
Haptic(JoystickParam joystick)
Open a haptic device for use from a joystick device.
Definition: SDL3pp_haptic.h:868
constexpr Haptic(const Haptic &other)=delete
Copy constructor.
constexpr Haptic()=default
Default ctor.
~Haptic()
Destructor.
Definition: SDL3pp_haptic.h:887
Haptic(HapticID instance_id)
Open a haptic device for use.
Definition: SDL3pp_haptic.h:843
constexpr Haptic(const HapticRaw resource)
Constructs from HapticParam.
Definition: SDL3pp_haptic.h:802
constexpr auto operator<=>(const Haptic &other) const =default
Comparison.
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 RunHapticEffect(HapticParam haptic, int effect, Uint32 iterations)
Run the haptic effect on its associated haptic device.
Definition: SDL3pp_haptic.h:1656
void StopHapticEffects(HapticParam haptic)
Stop all the currently playing effects on a haptic device.
Definition: SDL3pp_haptic.h:1839
constexpr HapticEffectType HAPTIC_FRICTION
Friction effect supported - uses axes movement.
Definition: SDL3pp_haptic.h:277
Haptic OpenHaptic(HapticID instance_id)
Open a haptic device for use.
Definition: SDL3pp_haptic.h:1334
void StopHapticRumble(HapticParam haptic)
Stop the simple rumble on a haptic device.
Definition: SDL3pp_haptic.h:1918
int GetMaxHapticEffectsPlaying(HapticParam haptic)
Get the number of effects a haptic device can play at the same time.
Definition: SDL3pp_haptic.h:1506
void Pause()
Pause a haptic device.
Definition: SDL3pp_haptic.h:1807
void SetHapticAutocenter(HapticParam haptic, int autocenter)
Set the global autocenter of the device.
Definition: SDL3pp_haptic.h:1776
constexpr HapticEffectType HAPTIC_GAIN
Device can set global gain.
Definition: SDL3pp_haptic.h:329
bool IsJoystickHaptic(JoystickParam joystick)
Query if a joystick has haptic features.
Definition: SDL3pp_haptic.h:1423
void SetGain(int gain)
Set the global gain of the specified haptic device.
Definition: SDL3pp_haptic.h:1758
SDL_HapticDirection HapticDirection
Structure that represents a haptic direction.
Definition: SDL3pp_haptic.h:529
void StopHapticEffect(HapticParam haptic, int effect)
Stop the haptic effect on its associated haptic device.
Definition: SDL3pp_haptic.h:1678
int GetMaxEffectsPlaying()
Get the number of effects a haptic device can play at the same time.
Definition: SDL3pp_haptic.h:1511
HapticID GetHapticID(HapticParam haptic)
Get the instance ID of an opened haptic device.
Definition: SDL3pp_haptic.h:1359
constexpr HapticEffectType HAPTIC_SINE
Sine wave effect supported.
Definition: SDL3pp_haptic.h:174
void StopEffect(int effect)
Stop the haptic effect on its associated haptic device.
Definition: SDL3pp_haptic.h:1683
Haptic OpenHapticFromJoystick(JoystickParam joystick)
Open a haptic device for use from a joystick device.
Definition: SDL3pp_haptic.h:1448
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:774
void SetHapticGain(HapticParam haptic, int gain)
Set the global gain of the specified haptic device.
Definition: SDL3pp_haptic.h:1753
constexpr Uint32 HAPTIC_INFINITY
Used to play a device an infinite number of times.
Definition: SDL3pp_haptic.h:423
constexpr HapticEffectType HAPTIC_DAMPER
Damper effect supported - uses axes velocity.
Definition: SDL3pp_haptic.h:253
void UpdateEffect(int effect, const HapticEffect &data)
Update the properties of an effect.
Definition: SDL3pp_haptic.h:1631
bool HapticEffectSupported(HapticParam haptic, const HapticEffect &effect)
Check to see if an effect is supported by a haptic device.
Definition: SDL3pp_haptic.h:1569
Uint8 HapticDirectionType
Direction encoding.
Definition: SDL3pp_haptic.h:373
void PlayHapticRumble(HapticParam haptic, float strength, Uint32 length)
Run a simple rumble effect on a haptic device.
Definition: SDL3pp_haptic.h:1898
int GetNumHapticAxes(HapticParam haptic)
Get the number of haptic axes the device has.
Definition: SDL3pp_haptic.h:1550
void InitHapticRumble(HapticParam haptic)
Initialize a haptic device for simple rumble playback.
Definition: SDL3pp_haptic.h:1878
void Resume()
Resume a haptic device.
Definition: SDL3pp_haptic.h:1826
constexpr HapticEffectType HAPTIC_RESERVED3
Reserved for future use.
Definition: SDL3pp_haptic.h:309
const char * GetHapticName(HapticParam haptic)
Get the implementation dependent name of a haptic device.
Definition: SDL3pp_haptic.h:1377
constexpr HapticEffectType HAPTIC_INERTIA
Inertia effect supported - uses axes acceleration.
Definition: SDL3pp_haptic.h:265
constexpr HapticEffectType HAPTIC_SPRING
Spring effect supported - uses axes position.
Definition: SDL3pp_haptic.h:241
constexpr HapticEffectType HAPTIC_LEFTRIGHT
Left/Right effect supported.
Definition: SDL3pp_haptic.h:288
SDL_HapticCondition HapticCondition
A structure containing a template for a Condition effect.
Definition: SDL3pp_haptic.h:636
int CreateEffect(const HapticEffect &effect)
Create a new haptic effect on a specified device.
Definition: SDL3pp_haptic.h:1600
const char * GetHapticNameForID(HapticID instance_id)
Get the implementation dependent name of a haptic device.
Definition: SDL3pp_haptic.h:1306
constexpr HapticEffectType HAPTIC_CUSTOM
Custom effect is supported.
Definition: SDL3pp_haptic.h:318
void InitRumble()
Initialize a haptic device for simple rumble playback.
Definition: SDL3pp_haptic.h:1883
bool GetHapticEffectStatus(HapticParam haptic, int effect)
Get the status of the current effect on the specified haptic device.
Definition: SDL3pp_haptic.h:1725
void StopRumble()
Stop the simple rumble on a haptic device.
Definition: SDL3pp_haptic.h:1923
void SetAutocenter(int autocenter)
Set the global autocenter of the device.
Definition: SDL3pp_haptic.h:1781
Haptic OpenHapticFromMouse()
Try to open a haptic device from the current mouse.
Definition: SDL3pp_haptic.h:1406
constexpr HapticDirectionType HAPTIC_STEERING_AXIS
Use this value to play an effect on the steering wheel axis.
Definition: SDL3pp_haptic.h:412
bool IsMouseHaptic()
Query whether or not the current mouse has haptic capabilities.
Definition: SDL3pp_haptic.h:1393
SDL_HapticConstant HapticConstant
A structure containing a template for a Constant effect.
Definition: SDL3pp_haptic.h:544
int GetNumAxes()
Get the number of haptic axes the device has.
Definition: SDL3pp_haptic.h:1555
SDL_HapticRamp HapticRamp
A structure containing a template for a Ramp effect.
Definition: SDL3pp_haptic.h:653
void PlayRumble(float strength, Uint32 length)
Run a simple rumble effect on a haptic device.
Definition: SDL3pp_haptic.h:1903
bool RumbleSupported()
Check whether rumble is supported on a haptic device.
Definition: SDL3pp_haptic.h:1861
constexpr HapticEffectType HAPTIC_PAUSE
Device can be paused.
Definition: SDL3pp_haptic.h:363
constexpr HapticEffectType HAPTIC_SQUARE
Square wave effect supported.
Definition: SDL3pp_haptic.h:185
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:196
bool EffectSupported(const HapticEffect &effect)
Check to see if an effect is supported by a haptic device.
Definition: SDL3pp_haptic.h:1575
SDL_HapticPeriodic HapticPeriodic
A structure containing a template for a Periodic effect.
Definition: SDL3pp_haptic.h:608
void DestroyEffect(int effect)
Destroy a haptic effect on the device.
Definition: SDL3pp_haptic.h:1706
bool GetEffectStatus(int effect)
Get the status of the current effect on the specified haptic device.
Definition: SDL3pp_haptic.h:1730
void DestroyHapticEffect(HapticParam haptic, int effect)
Destroy a haptic effect on the device.
Definition: SDL3pp_haptic.h:1701
Uint32 GetHapticFeatures(HapticParam haptic)
Get the haptic device's supported features in bitwise manner.
Definition: SDL3pp_haptic.h:1528
constexpr HapticEffectType HAPTIC_RESERVED1
Reserved for future use.
Definition: SDL3pp_haptic.h:295
void RunEffect(int effect, Uint32 iterations)
Run the haptic effect on its associated haptic device.
Definition: SDL3pp_haptic.h:1661
void CloseHaptic(HapticRaw haptic)
Close a haptic device previously opened with Haptic.Haptic().
Definition: SDL3pp_haptic.h:1462
constexpr HapticDirectionType HAPTIC_SPHERICAL
Uses spherical coordinates for the direction.
Definition: SDL3pp_haptic.h:400
constexpr HapticEffectType HAPTIC_AUTOCENTER
Device can set autocenter.
Definition: SDL3pp_haptic.h:340
void ResumeHaptic(HapticParam haptic)
Resume a haptic device.
Definition: SDL3pp_haptic.h:1821
static Haptic OpenFromMouse()
Try to open a haptic device from the current mouse.
Definition: SDL3pp_haptic.h:1411
HapticID GetID()
Get the instance ID of an opened haptic device.
Definition: SDL3pp_haptic.h:1364
constexpr HapticEffectType HAPTIC_SAWTOOTHDOWN
Sawtoothdown wave effect supported.
Definition: SDL3pp_haptic.h:218
constexpr HapticDirectionType HAPTIC_CARTESIAN
Uses cartesian coordinates for the direction.
Definition: SDL3pp_haptic.h:391
bool HapticRumbleSupported(HapticParam haptic)
Check whether rumble is supported on a haptic device.
Definition: SDL3pp_haptic.h:1856
int GetMaxEffects()
Get the number of effects a haptic device can store.
Definition: SDL3pp_haptic.h:1487
constexpr HapticDirectionType HAPTIC_POLAR
Uses polar coordinates for the direction.
Definition: SDL3pp_haptic.h:382
constexpr HapticEffectType HAPTIC_CONSTANT
Constant effect supported.
Definition: SDL3pp_haptic.h:163
int GetMaxHapticEffects(HapticParam haptic)
Get the number of effects a haptic device can store.
Definition: SDL3pp_haptic.h:1482
Uint32 HapticEffectType
Haptic effects flag constants.
Definition: SDL3pp_haptic.h:152
constexpr HapticEffectType HAPTIC_RESERVED2
Reserved for future use.
Definition: SDL3pp_haptic.h:302
HapticRef GetHapticFromID(HapticID instance_id)
Get the Haptic associated with an instance ID, if it has been opened.
Definition: SDL3pp_haptic.h:1345
const char * GetName()
Get the implementation dependent name of a haptic device.
Definition: SDL3pp_haptic.h:1382
constexpr HapticEffectType HAPTIC_STATUS
Device can be queried for effect status.
Definition: SDL3pp_haptic.h:351
SDL_HapticCustom HapticCustom
A structure containing a template for the HAPTIC_CUSTOM effect.
Definition: SDL3pp_haptic.h:688
OwnArray< HapticID > GetHaptics()
Get a list of currently connected haptic devices.
Definition: SDL3pp_haptic.h:1285
int CreateHapticEffect(HapticParam haptic, const HapticEffect &effect)
Create a new haptic effect on a specified device.
Definition: SDL3pp_haptic.h:1595
Uint32 GetFeatures()
Get the haptic device's supported features in bitwise manner.
Definition: SDL3pp_haptic.h:1533
void PauseHaptic(HapticParam haptic)
Pause a haptic device.
Definition: SDL3pp_haptic.h:1802
constexpr HapticEffectType HAPTIC_SAWTOOTHUP
Sawtoothup wave effect supported.
Definition: SDL3pp_haptic.h:207
SDL_HapticEffect HapticEffect
The generic template for any haptic effect.
Definition: SDL3pp_haptic.h:762
void StopEffects()
Stop all the currently playing effects on a haptic device.
Definition: SDL3pp_haptic.h:1844
SDL_HapticLeftRight HapticLeftRight
A structure containing a template for a Left/Right effect.
Definition: SDL3pp_haptic.h:669
void UpdateHapticEffect(HapticParam haptic, int effect, const HapticEffect &data)
Update the properties of an effect.
Definition: SDL3pp_haptic.h:1624
constexpr HapticEffectType HAPTIC_RAMP
Ramp effect supported.
Definition: SDL3pp_haptic.h:229
void Close()
Close a haptic device previously opened with Haptic.Haptic().
Definition: SDL3pp_haptic.h:1464
::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:1252
~HapticRef()
Destructor.
Definition: SDL3pp_haptic.h:1272
HapticRef(HapticParam resource)
Constructs from HapticParam.
Definition: SDL3pp_haptic.h:1260
HapticRef(const HapticRef &other)
Copy constructor.
Definition: SDL3pp_haptic.h:1266
Safely wrap Joystick for non owning parameters.
Definition: SDL3pp_joystick.h:60