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; }
804 : m_resource(resource)
845 : m_resource(SDL_OpenHaptic(instance_id))
870 : m_resource(
CheckError(SDL_OpenHapticFromJoystick(joystick)))
893 std::swap(m_resource, other.m_resource);
904 m_resource =
nullptr;
912 constexpr bool operator==(std::nullptr_t _)
const {
return !m_resource; }
915 constexpr explicit operator bool()
const {
return !!m_resource; }
1291 auto data = SDL_GetHaptics(&count);
1312 return SDL_GetHapticNameForID(instance_id);
1351 return {
CheckError(SDL_GetHapticFromID(instance_id))};
1384 return SDL_GetHapticName(haptic);
1413 return Haptic(SDL_OpenHapticFromMouse());
1430 return SDL_IsJoystickHaptic(joystick);
1489 return SDL_GetMaxHapticEffects(haptic);
1513 return SDL_GetMaxHapticEffectsPlaying(haptic);
1535 return SDL_GetHapticFeatures(haptic);
1557 return CheckError(SDL_GetNumHapticAxes(haptic));
1577 return SDL_HapticEffectSupported(haptic, &effect);
1602 return CheckError(SDL_CreateHapticEffect(haptic, &effect));
1633 CheckError(SDL_UpdateHapticEffect(haptic, effect, &data));
1664 CheckError(SDL_RunHapticEffect(haptic, effect, iterations));
1686 CheckError(SDL_StopHapticEffect(haptic, effect));
1709 SDL_DestroyHapticEffect(haptic, effect);
1733 return SDL_GetHapticEffectStatus(haptic, effect);
1785 CheckError(SDL_SetHapticAutocenter(haptic, autocenter));
1865 return SDL_HapticRumbleSupported(haptic);
1907 CheckError(SDL_PlayHapticRumble(haptic, strength, length));
The haptic structure used to identify an SDL haptic.
Definition: SDL3pp_haptic.h:789
constexpr Haptic(Haptic &&other)
Move constructor.
Definition: SDL3pp_haptic.h:812
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_haptic.h:912
Haptic & operator=(Haptic other)
Assignment operator.
Definition: SDL3pp_haptic.h:891
constexpr HapticRaw release()
Retrieves underlying HapticRaw and clear this.
Definition: SDL3pp_haptic.h:901
constexpr HapticRaw get() const
Retrieves underlying HapticRaw.
Definition: SDL3pp_haptic.h:898
Haptic(JoystickParam joystick)
Open a haptic device for use from a joystick device.
Definition: SDL3pp_haptic.h:869
constexpr Haptic(const Haptic &other)=delete
Copy constructor.
constexpr Haptic()=default
Default ctor.
~Haptic()
Destructor.
Definition: SDL3pp_haptic.h:888
Haptic(HapticID instance_id)
Open a haptic device for use.
Definition: SDL3pp_haptic.h:844
constexpr Haptic(const HapticRaw resource)
Constructs from HapticParam.
Definition: SDL3pp_haptic.h:803
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:198
void RunHapticEffect(HapticParam haptic, int effect, Uint32 iterations)
Run the haptic effect on its associated haptic device.
Definition: SDL3pp_haptic.h:1662
void StopHapticEffects(HapticParam haptic)
Stop all the currently playing effects on a haptic device.
Definition: SDL3pp_haptic.h:1846
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:1338
void StopHapticRumble(HapticParam haptic)
Stop the simple rumble on a haptic device.
Definition: SDL3pp_haptic.h:1925
int GetMaxHapticEffectsPlaying(HapticParam haptic)
Get the number of effects a haptic device can play at the same time.
Definition: SDL3pp_haptic.h:1511
void Pause()
Pause a haptic device.
Definition: SDL3pp_haptic.h:1814
void SetHapticAutocenter(HapticParam haptic, int autocenter)
Set the global autocenter of the device.
Definition: SDL3pp_haptic.h:1783
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:1428
void SetGain(int gain)
Set the global gain of the specified haptic device.
Definition: SDL3pp_haptic.h:1765
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:1684
int GetMaxEffectsPlaying()
Get the number of effects a haptic device can play at the same time.
Definition: SDL3pp_haptic.h:1516
HapticID GetHapticID(HapticParam haptic)
Get the instance ID of an opened haptic device.
Definition: SDL3pp_haptic.h:1363
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:1689
Haptic OpenHapticFromJoystick(JoystickParam joystick)
Open a haptic device for use from a joystick device.
Definition: SDL3pp_haptic.h:1453
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:775
void SetHapticGain(HapticParam haptic, int gain)
Set the global gain of the specified haptic device.
Definition: SDL3pp_haptic.h:1760
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:1636
bool HapticEffectSupported(HapticParam haptic, const HapticEffect &effect)
Check to see if an effect is supported by a haptic device.
Definition: SDL3pp_haptic.h:1574
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:1905
int GetNumHapticAxes(HapticParam haptic)
Get the number of haptic axes the device has.
Definition: SDL3pp_haptic.h:1555
void InitHapticRumble(HapticParam haptic)
Initialize a haptic device for simple rumble playback.
Definition: SDL3pp_haptic.h:1885
void Resume()
Resume a haptic device.
Definition: SDL3pp_haptic.h:1833
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:1382
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:637
int CreateEffect(const HapticEffect &effect)
Create a new haptic effect on a specified device.
Definition: SDL3pp_haptic.h:1605
const char * GetHapticNameForID(HapticID instance_id)
Get the implementation dependent name of a haptic device.
Definition: SDL3pp_haptic.h:1310
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:1890
bool GetHapticEffectStatus(HapticParam haptic, int effect)
Get the status of the current effect on the specified haptic device.
Definition: SDL3pp_haptic.h:1731
void StopRumble()
Stop the simple rumble on a haptic device.
Definition: SDL3pp_haptic.h:1930
void SetAutocenter(int autocenter)
Set the global autocenter of the device.
Definition: SDL3pp_haptic.h:1788
Haptic OpenHapticFromMouse()
Try to open a haptic device from the current mouse.
Definition: SDL3pp_haptic.h:1411
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:1398
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:1560
SDL_HapticRamp HapticRamp
A structure containing a template for a Ramp effect.
Definition: SDL3pp_haptic.h:654
void PlayRumble(float strength, Uint32 length)
Run a simple rumble effect on a haptic device.
Definition: SDL3pp_haptic.h:1910
bool RumbleSupported()
Check whether rumble is supported on a haptic device.
Definition: SDL3pp_haptic.h:1868
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:1580
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:1712
bool GetEffectStatus(int effect)
Get the status of the current effect on the specified haptic device.
Definition: SDL3pp_haptic.h:1736
void DestroyHapticEffect(HapticParam haptic, int effect)
Destroy a haptic effect on the device.
Definition: SDL3pp_haptic.h:1707
Uint32 GetHapticFeatures(HapticParam haptic)
Get the haptic device's supported features in bitwise manner.
Definition: SDL3pp_haptic.h:1533
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:1667
void CloseHaptic(HapticRaw haptic)
Close a haptic device previously opened with Haptic.Haptic().
Definition: SDL3pp_haptic.h:1467
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:1828
static Haptic OpenFromMouse()
Try to open a haptic device from the current mouse.
Definition: SDL3pp_haptic.h:1416
HapticID GetID()
Get the instance ID of an opened haptic device.
Definition: SDL3pp_haptic.h:1368
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:1863
int GetMaxEffects()
Get the number of effects a haptic device can store.
Definition: SDL3pp_haptic.h:1492
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:1487
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:1349
const char * GetName()
Get the implementation dependent name of a haptic device.
Definition: SDL3pp_haptic.h:1387
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:689
OwnArray< HapticID > GetHaptics()
Get a list of currently connected haptic devices.
Definition: SDL3pp_haptic.h:1288
int CreateHapticEffect(HapticParam haptic, const HapticEffect &effect)
Create a new haptic effect on a specified device.
Definition: SDL3pp_haptic.h:1600
Uint32 GetFeatures()
Get the haptic device's supported features in bitwise manner.
Definition: SDL3pp_haptic.h:1538
void PauseHaptic(HapticParam haptic)
Pause a haptic device.
Definition: SDL3pp_haptic.h:1809
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:763
void StopEffects()
Stop all the currently playing effects on a haptic device.
Definition: SDL3pp_haptic.h:1851
SDL_HapticLeftRight HapticLeftRight
A structure containing a template for a Left/Right effect.
Definition: SDL3pp_haptic.h:670
void UpdateHapticEffect(HapticParam haptic, int effect, const HapticEffect &data)
Update the properties of an effect.
Definition: SDL3pp_haptic.h:1629
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:1469
Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:325
Uint8 Uint8
An unsigned 8-bit integer type.
Definition: SDL3pp_stdinc.h:257
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:1255
~HapticRef()
Destructor.
Definition: SDL3pp_haptic.h:1275
HapticRef(HapticParam resource)
Constructs from HapticParam.
Definition: SDL3pp_haptic.h:1263
HapticRef(const HapticRef &other)
Copy constructor.
Definition: SDL3pp_haptic.h:1269
Safely wrap Joystick for non owning parameters.
Definition: SDL3pp_joystick.h:60