Advertisement
Kitomas

work for 2024-11-21 (8/10)

Nov 22nd, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 65.53 KB | None | 0 0
  1. /******************************************************************************/
  2. /******************************************************************************/
  3. //"2024-11-21\include\kit\misc.hpp":
  4. //THIS LIBRARY WAS MADE TO USE SDL2 VERSION 2.28.2
  5.  
  6. #ifndef _INC_MISC_HPP
  7. #define _INC_MISC_HPP
  8.  
  9. #include "commondef.hpp"
  10. #include "_misc_memory.hpp"
  11. #include "_misc_Mutex.hpp"
  12. #include "_misc_Thread.hpp"
  13. #include "_misc_func.hpp"
  14. #include "_misc_time.hpp"
  15. #include "_misc_Event.hpp"
  16. #include "_misc_EventWatch.hpp"
  17. #include "_misc_fileio.hpp"
  18.  
  19.  
  20. #endif /* _INC_MISC_HPP */
  21. /******************************************************************************/
  22. /******************************************************************************/
  23. //"2024-11-21\include\kit\video.hpp":
  24. //THIS LIBRARY WAS MADE TO USE SDL2 VERSION 2.28.2
  25.  
  26. #ifndef _INC_VIDEO_HPP
  27. #define _INC_VIDEO_HPP
  28.  
  29. #include "commondef.hpp"
  30. #include "_video_Window.hpp"
  31. #include "_video_PixelFmt.hpp"
  32. #include "_video_Surface.hpp"
  33. #include "_video_BFont_Surface.hpp"
  34.  
  35.  
  36. #endif /* _INC_VIDEO_HPP */
  37. /******************************************************************************/
  38. /******************************************************************************/
  39. //"2024-11-21\include\kit\_audio_AudioData.hpp":
  40. #ifndef _INC__AUDIO_AUDIODATA_HPP
  41. #define _INC__AUDIO_AUDIODATA_HPP
  42.  
  43. #include "commondef.hpp"
  44. #include "_audio_types.hpp"
  45.  
  46.  
  47. namespace kit {
  48.  
  49.  
  50.  
  51.  
  52.  
  53. struct AudioDataHeader;
  54.  
  55. //like Surface, the pointer this returns must have been allocated with
  56.  //memory:alloc specifically (NOT memory::allocSIMD!)
  57. //->samples must not use a separate allocation! samples must be contiguous
  58.  //and on the same memory block as the header itself!
  59.  //(basically, header_ptr->samples = (u8*)header_ptr+header_ptr->headerSize)
  60. typedef AudioDataHeader* (*AudioDataLoaderCallback)(const char* filePath);
  61.  
  62. typedef void (*AudioDataSaverCallback)(const char* filePath, AudioDataHeader& header_in);
  63.  
  64. //(like Surface, when saving OR loading, filePath will never be nullptr by the
  65.  //time the callback is invoked, so you don't need to worry about checking for it)
  66.  
  67.  
  68.  
  69. //(not an actual callback, but rather the lack of one)
  70. #define AudioDataLoadKPM ((AudioDataLoaderCallback)nullptr)
  71. #define AudioDataSaveKPM ((AudioDataSaverCallback)nullptr)
  72.  
  73. AudioDataHeader* AudioDataLoadWAV(const char* filePath);
  74. void             AudioDataSaveWAV(const char* filePath, AudioDataHeader& header_in);
  75.  
  76. AudioDataHeader* AudioDataLoadQOA(const char* filePath);
  77. void             AudioDataSaveQOA(const char* filePath, AudioDataHeader& header_in);
  78.  
  79. AudioDataHeader* AudioDataLoadOGG(const char* filePath);
  80. //(there is no saver callback for ogg currently!)
  81.  
  82.  
  83.  
  84.  
  85.  
  86. #define KIT_MAGIC_KPM (0x4D78506B) // = "kPxM" (no null terminator)
  87.  
  88. struct AudioDataHeader { //72B (0x48B)
  89.   u32        magic; // (0x00) = KIT_MAGIC_KPM = 0x4D78506B = "kPxM"
  90.   u16       format; // (0x04) = one of AudioSampleFormatEnum if fmt_version == 1
  91.   u16   headerSize; // (0x06) = must be >=sizeof(AudioDataHeader)
  92.   u64     dataSize; // (0x08) = size of audio data, in bytes
  93.  
  94.   u64    loopStart; // (0x10) = which sample to loop back to
  95.   u64      loopEnd; // (0x18) = which sample to jump back to loopStart on
  96.  
  97.   u64   numSamples; // (0x20) = # of sample frames in audio data
  98.   u32   sampleRate; // (0x28) = the audio data's sample rate, in Hz
  99.   u32      bitRate; // (0x2C) = the audio's bit rate (per second)
  100.  
  101.   u16    loopCount; // (0x30) = # of times to loop audio (0 = no loop, 0xFFFF = inf loop)
  102.   u16     channels; // (0x32) = # of interlaced channels in the audio data
  103.   u8     _reserved; // (0x34)
  104.   u8   fmt_version; // (0x35) = 0=kit_w32, 1=kit_sdl2
  105.   u8          mode; // (0x36) = 0 for normal PCM or float data types
  106.   u8 metadata_type; // (0x37) = 0 for no metadata
  107.  
  108.   void*    samples; // (0x38) = the audio's sample data (appears as nullptr in file)
  109.   void*   userdata; // (0x40) = user-defined (also appears nullptr in file)
  110.                     // (0x48) = (start of sample data, assuming a .kpm file)
  111.  
  112.   void printHeader(const char* name = nullptr);
  113.  
  114. };
  115.  
  116.  
  117.  
  118.  
  119.  
  120. class AudioData { //24B
  121.   u32          _type;
  122.   bool        _valid = false;
  123.   bool _constructing = true;
  124.   u16     _padding16;
  125.  
  126.  
  127.   //used by both the 'only allocate' constructors
  128.   void _allocate_hdr(u16 headerSize, u64 dataSize,
  129.                      const char* funcName = nullptr);
  130.  
  131.   //used by both of the 'load from file' constructors
  132.   void _construct_file(const char* filePath, AudioDataLoaderCallback callback,
  133.                        const char* funcName = nullptr);
  134.  
  135.  
  136. public:
  137.   //after exiting the constructor, hdr->samples is safe to use with SIMD
  138.    //vector instructions/intriniscs (AudioDataLoaderCallbacks must
  139.    //still use memory::alloc instead of allocSIMD though)!
  140.   AudioDataHeader* hdr;
  141.  
  142.   Stereo_f32 volume = {1.0f, 1.0f};
  143.  
  144.  
  145.  
  146.   //create with everything zeroed out, except headerSize, dataSize, and samples
  147.   AudioData(u16 headerSize, u64 dataSize)
  148.   { _allocate_hdr(headerSize, dataSize); }
  149.  
  150.   //create with zeroed out sample data
  151.   AudioData(AudioSampleFormatEnum format,
  152.             u64 numSamples, u16 channels, u32 sampleRate);
  153.  
  154.   //create from an audio file of a specific file format
  155.    //(may reduce binary size if you only plan to use 1 file type or something)
  156.   AudioData(const char* filePath, AudioDataLoaderCallback callback)
  157.   { _construct_file(filePath, callback); }
  158.  
  159.   //create from an audio file of any supported format (.kpm, .wav, .qoa, .ogg)
  160.   AudioData(const char* filePath);
  161.  
  162.   ~AudioData();
  163.  
  164.  
  165.  
  166.   inline void printHeader(const char* name = nullptr)
  167.   { if(hdr != nullptr) hdr->printHeader(name); }
  168.  
  169.   //(this will overwrite any file named filePath! make sure to check
  170.    //with fileio::exists() unless you intend to overwrite the previous file)
  171.   void saveAudio(const char* filePath, AudioDataSaverCallback callback);
  172.  
  173.   //the conversion method used is slightly inaccurate for a number of reasons.
  174.    //this function only serves as a convenience, where accuracy isn't
  175.    //needed beyond sounding more or less the same.
  176.   void convertFormat(AudioSampleFormatEnum format);
  177.   //(this will return early if hdr->format == format,
  178.    //since no conversion would be necessary)
  179.  
  180. };
  181.  
  182.  
  183.  
  184.  
  185.  
  186. }; /* namespace kit */
  187.  
  188. #endif /* _INC__AUDIO_AUDIODATA_HPP */
  189. /******************************************************************************/
  190. /******************************************************************************/
  191. //"2024-11-21\include\kit\_audio_AudioDevice.hpp":
  192. #ifndef _INC__AUDIO_AUDIODEVICE_HPP
  193. #define _INC__AUDIO_AUDIODEVICE_HPP
  194.  
  195. #include "commondef.hpp"
  196. #include "_audio_types.hpp"
  197.  
  198.  
  199. namespace kit {
  200.  
  201.  
  202.  
  203.  
  204.  
  205. //if disableFadeDelay == false, audio will be muted for 90ms
  206.  //before fading in over the course of 10ms (100ms in total).
  207. //if disableFadeDelay == true, only the 10ms fade-in will occur
  208.  
  209. class AudioDevice { //64B
  210.   u32          _type;
  211.   bool        _valid = false;
  212.   bool _constructing = true;
  213.   u16     _padding16;
  214.   GenOpqPtr     _opq = nullptr;
  215.  
  216.  
  217.   //(device starts in a paused state!)
  218.   void _construct(const char* name,
  219.                   const AudioDeviceInfo& desired,
  220.                   bool disableFadeDelay = false,
  221.                   bool indexed = true);
  222.  
  223.  
  224. public:
  225.  
  226.   const AudioDeviceInfo info;
  227.  
  228.  
  229.   //(internally calls SDL_GetAudioDeviceName to get device's name)
  230.   AudioDevice(s32 index, //-1 to use default device
  231.               const AudioDeviceInfo& desired,
  232.               bool disableFadeDelay = false);
  233.  
  234.   AudioDevice(const char* name, //nullptr to use default device
  235.               const AudioDeviceInfo& desired,
  236.               bool disableFadeDelay = false)
  237.   { _construct(name, desired, disableFadeDelay, false); }
  238.  
  239.   //this will abruptly stop audio playback with no fade-out, so make sure
  240.    //to have the device be completely paused by the time this is called!
  241.    //(it's technically fine to do this without pausing, but it sounds terrible)
  242.   ~AudioDevice();
  243.  
  244.  
  245.   inline bool isValid()       { return _valid;        }
  246.   inline bool isConstructing(){ return _constructing; }
  247.   bool isPlaying(); //'is the user callback actually getting called?'
  248.   bool isActive(); //'is the underlying SDL device actually writing to DAC?'
  249.   //(^^returning true does not necessarily mean
  250.    //that the callback is actually being called!)
  251.  
  252.  
  253.   void setCallback(AudioCallback callback);
  254.   void setUserdata(void* userdata);
  255.   void setPlayback(bool playing);
  256.   //false, true  =  wait 10ms, wait 100ms (or also just 10ms if disableFadeDelay)
  257.   void setPlaybackAndWait(bool playing);
  258.   inline void play() { setPlayback(true ); }
  259.   inline void pause(){ setPlayback(false); }
  260.   inline void playAndWait() { setPlaybackAndWait(true ); }
  261.   inline void pauseAndWait(){ setPlaybackAndWait(false); }
  262.  
  263.  
  264.   void lock(bool locked = true);
  265.   inline void unlock(){ lock(false); }
  266.  
  267. };
  268.  
  269.  
  270.  
  271.  
  272.  
  273. }; /* namespace kit */
  274.  
  275. #endif /* _INC__AUDIO_AUDIODEVICE_HPP */
  276. /******************************************************************************/
  277. /******************************************************************************/
  278. //"2024-11-21\include\kit\_audio_AudioStream.hpp":
  279. #ifndef _INC__AUDIO_AUDIOSTREAM_HPP
  280. #define _INC__AUDIO_AUDIOSTREAM_HPP
  281.  
  282. #include "commondef.hpp"
  283. #include "_audio_types.hpp"
  284.  
  285.  
  286. namespace kit {
  287.  
  288.  
  289.  
  290.  
  291.  
  292. //converts an audio buffer to that of a different type,
  293.  //for example, mono s16 @ 44.1kHz  ->  stereo f32 @ 48kHz
  294. class AudioStream { //112B
  295.   u32          _type;
  296.   bool        _valid = false;
  297.   bool _constructing = true;
  298.   u16     _padding16;
  299.   GenOpqPtr     _opq = nullptr;
  300.  
  301.  
  302. public:
  303.  
  304.   //(only .sampleRate, .sampleFormat, and .numChannels are actually used here)
  305.   const AudioDeviceInfo src; //what will be converted to dst
  306.   const AudioDeviceInfo dst; //what to convert src to
  307.  
  308.  
  309.   AudioStream(const AudioDeviceInfo* src_p, const AudioDeviceInfo* dst_p);
  310.  
  311.   ~AudioStream();
  312.  
  313.  
  314.   inline bool isValid()       { return _valid; }
  315.   inline bool isConstructing(){ return _constructing; }
  316.  
  317.  
  318.   //returns # of converted bytes ready to be read from with a call to get()
  319.    //(if 0 is returned, you can call flush() to make available whatever is
  320.    // left in the buffer. though this might cause audio dropouts if you
  321.    // intend on making additional calls to put() to the stream!)
  322.   u32 getAvailableBytes();
  323.  
  324.  
  325.   //tell the stream that you're done sending data, and anything being
  326.    //buffered should be converted/resampled and made available immediately
  327.   void flush();
  328.  
  329.   //clear any pending data in the stream without converting it
  330.   void clear();
  331.  
  332.  
  333.   //read from converted data into buffer_dst
  334.    //returns number of bytes read from stream (to a max of buffer_size bytes)
  335.   u32 get(void* buffer_dst, u32 buffer_size);
  336.  
  337.   //write samples (from buffer_src) to stream to be converted
  338.    //(buffer_size is also in bytes here)
  339.   void put(void* buffer_src, u32 buffer_size);
  340.  
  341. };
  342.  
  343.  
  344.  
  345.  
  346.  
  347. }; /* namespace kit */
  348.  
  349. #endif /* _INC__AUDIO_AUDIOSTREAM_HPP */
  350. /******************************************************************************/
  351. /******************************************************************************/
  352. //"2024-11-21\include\kit\_audio_func.hpp":
  353. #ifndef _INC__AUDIO_FUNC_HPP
  354. #define _INC__AUDIO_FUNC_HPP
  355.  
  356. #include "commondef.hpp"
  357. #include "_audio_types.hpp"
  358.  
  359.  
  360. namespace kit {
  361.  
  362.  
  363. namespace audiofunc {
  364.  
  365.  
  366.  
  367.  
  368.  
  369. //if name_p != nullptr, *name_p will be filled with the name of the device
  370.  //(memory is allocated here; call memory::free() on it to prevent leaks!)
  371.  //(also, this function can potentially be quite expensive, so don't call it often!)
  372. AudioDeviceInfo getDefaultDevInfo(char** name_p = nullptr, bool isInput = false);
  373.  
  374.  
  375. AudioDeviceInfo getDeviceInfo(s32 index, bool isInput);
  376.  
  377.  
  378. //returns -1 if explicit device list could not be determined
  379.  //(doesn't necessarily mean an error, but call getLastSysError() just in case)
  380. s32 getNumDevices(bool isInput);
  381.  
  382.  
  383. //the returned pointer (utf-8 encoded) is managed internally and should not be freed
  384.  //if you want to reference/store the string long-term, it should be copied, as the returned
  385.  //pointer will become invalid the next time certain SDL functions are called internally
  386. //(also, the returned value and its associated index reflect the latest call to
  387.  //getNumDevices(), so that should be called in order to redetect available hardware)
  388. const char* getDeviceName(u32 index, bool isInput);
  389.  
  390.  
  391. //(only useful in debug build!)
  392. void printAudioDeviceInfo(const AudioDeviceInfo& info);
  393.  
  394.  
  395.  
  396.  
  397.  
  398. }; /* namespace audiofunc */
  399.  
  400. }; /* namespace kit */
  401.  
  402. #endif /* _INC__AUDIO_FUNC_HPP */
  403. /******************************************************************************/
  404. /******************************************************************************/
  405. //"2024-11-21\include\kit\_audio_SoundEngine.hpp":
  406. #ifndef _INC__AUDIO_SOUNDENGINE_HPP
  407. #define _INC__AUDIO_SOUNDENGINE_HPP
  408.  
  409. #include "commondef.hpp"
  410. #include "_audio_types.hpp"
  411.  
  412.  
  413. namespace kit {
  414.  
  415.  
  416.  
  417.  
  418.  
  419. //WARNING: IF A CURRENTLY PLAYING AUDIO CLIP IS DESTROYED BEFORE
  420.  //SOUNDENGINE, AN ACCESS VIOLATION MIGHT OCCUR IF ACTIVELY MIXING!
  421.  
  422. struct _SoundEngineTrack;
  423.  
  424. class SoundEngine { //40B
  425.   u32                  _type;
  426.   bool                _valid = false;
  427.   bool         _constructing = true;
  428.   u16            _tracks_len = 64;
  429.   _SoundEngineTrack* _tracks = nullptr;
  430.   GenOpqPtr            _lock = nullptr;
  431.  
  432.   u16             _padding16;
  433.   u8               _padding8;
  434.  
  435. public:
  436.   //(ALL TRACKS MUST BE FULLY STOPPED BEFORE CHANGING SAMPLERATE,
  437.    //AS SAMPLERATE IS USED TO CALCULATE SOME AUDIO CLIP INFO!)
  438.  
  439.   bool    stopIfVolumeIsZero = true;
  440.   f32             sampleRate = 48000.0f; //the *device's* sample rate, in Hz
  441.   Stereo_f32    volumeMaster = {1.0f, 1.0f};
  442.   //(only the left channel of volumeMaster
  443.    //is used if the source audio is mono)
  444.  
  445.  
  446.  
  447.   SoundEngine(u16 numTracks = 64, f32 _sampleRate = 48000.0f);
  448.  
  449.   ~SoundEngine();
  450.  
  451.  
  452.  
  453.   bool isTrackPlaying(u16 track);
  454.  
  455.   u16        getActiveTracks();
  456.   inline u16 getTrackCount(){ return _tracks_len; }
  457.  
  458.  
  459.  
  460.   //sets the volume multiplier of a given track,
  461.    //or all active tracks if track == 0xFFFF
  462.   //when forced == true, the volume state is set instantly, instead of
  463.    //being interpolated over the course of the next call to mixTracks()
  464.   void setVolume(f32 volumeL, f32 volumeR,
  465.                  u16 track = 0xFFFF, bool forced = false);
  466.  
  467.   //sets the speed multiplier of a given track,
  468.    //or all active tracks if track == 0xFFFF
  469.   //forced has the same behavior as setVolume
  470.   void setSpeed(f64 speedNew,
  471.                 u16 track = 0xFFFF, bool forced = false);
  472.  
  473.   //sets the change in volume over time for a given track.
  474.    //or all active tracks if track == 0xFFFF
  475.   //deltaSeconds is the time it will take for the volume
  476.    //to go from 0.0x -> 1.0x (or vice versa)
  477.   void setVolumeDelta(f32 deltaSecondsL, f32 deltaSecondsR,
  478.                       u16 track = 0xFFFF);
  479.  
  480.   //same behavior as setVolumeDelta, except it's applied to the speed multiplier
  481.   void setSpeedDelta(f64 deltaSeconds,
  482.                      u16 track = 0xFFFF);
  483.  
  484.  
  485.  
  486.   //returns the track the audio was queued into,
  487.    //or 0xFFFF if no empty track was found
  488.   u16 play(const AudioData& audio, //(only f32 or Stereo_f32 samples allowed!)
  489.            f32 volumeL = 1.0f, f32 volumeR = 1.0f, f64 speed = 1.0);
  490.  
  491.   //(make sure to stop all tracks before freeing any instances of AudioData,
  492.    //as to avoid any issues related to dangling pointers and whatnot)
  493.   //(also, unless forced is set to true, this function
  494.    //won't work if stopIfVolumeIsZero is false!)
  495.   void stop(u16 track = 0xFFFF, bool forced = false);
  496.  
  497.  
  498.  
  499.   //returns false if timeout is reached, true otherwise
  500.   //(timeoutMS = 0 to wait indefinitely)
  501.   bool waitForTrack(u64 timeoutMS = 0, u16 track = 0xFFFF);
  502.  
  503.  
  504.  
  505.   //buffer_len is in elements, not bytes
  506.   //returns referenceTimestamp, or 0 on error
  507.    //(call getLastSysError() for error details)
  508.   u64 mixTracks(Stereo_f32* buffer, size_t buffer_len,
  509.                 u64 referenceTimestamp = kit::time::getMS());
  510.  
  511. };
  512.  
  513.  
  514.  
  515.  
  516.  
  517. }; /* namespace kit */
  518.  
  519. #endif /* _INC__AUDIO_SOUNDENGINE_HPP */
  520. /******************************************************************************/
  521. /******************************************************************************/
  522. //"2024-11-21\include\kit\_audio_types.hpp":
  523. #ifndef _INC__AUDIO_TYPES_HPP
  524. #define _INC__AUDIO_TYPES_HPP
  525.  
  526. #include "commondef.hpp"
  527.  
  528.  
  529. namespace kit {
  530.  
  531.  
  532.  
  533.  
  534.  
  535. #define KIT_AUDIO_BITSIZE(x)     (x & (0xFF ))
  536. #define KIT_AUDIO_ISFLOAT(x)     (x & (1<< 8))
  537. #define KIT_AUDIO_ISBIGENDIAN(x) (x & (1<<12))
  538. #define KIT_AUDIO_ISSIGNED(x)    (x & (1<<15))
  539.  
  540. #define KIT_AUDIO_BYTESIZE(x)    (KIT_AUDIO_BITSIZE(x)/8)
  541.  
  542.  
  543.  
  544.  
  545.  
  546. //(big-endian sample formats are not supported currently)
  547.  
  548. enum AudioSampleFormatEnum {
  549.   SMPFMT_U8     = 0x0008,  //unsigned  8-bit samples
  550.   SMPFMT_S8     = 0x8008,  //  signed  8-bit samples
  551.   SMPFMT_U16LSB = 0x0010,  //unsigned 16-bit samples
  552.   SMPFMT_S16LSB = 0x8010,  //  signed 16-bit samples
  553.   SMPFMT_S32LSB = 0x8020,  //  signed 32-bit samples
  554.   SMPFMT_F32LSB = 0x8120,  //32-bit floating point samples
  555.  
  556.   SMPFMT_U16MSB = 0x1010,  //same as LSB, except with big-endian byte order
  557.   SMPFMT_S16MSB = 0x9010,  //same as LSB, except with big-endian byte order
  558.   SMPFMT_S32MSB = 0x9020,  //same as LSB, except with big-endian byte order
  559.   SMPFMT_F32MSB = 0x9120,  //same as LSB, except with big-endian byte order
  560.  
  561.  
  562.   //unsupported by SDL2-based audio devices/streams
  563.    //(as in, what  AudioDevice/AudioStream use),
  564.    //but these can be used with AudioData instances
  565.   SMPFMT_S24LSB = 0x8018,  //  signed 24-bit samples
  566.   SMPFMT_F64LSB = 0x8140,  //64-bit floating point samples
  567.  
  568.   SMPFMT_S24MSB = 0x9018,  //same as LSB, except with big-endian byte order
  569.   SMPFMT_F64MSB = 0x9140,  //same as LSB, except with big-endian byte order
  570.  
  571.  
  572.   //aliases
  573.   SMPFMT_U16    = SMPFMT_U16LSB,
  574.   SMPFMT_S16    = SMPFMT_S16LSB,
  575.   SMPFMT_S24    = SMPFMT_S24LSB,
  576.   SMPFMT_S32    = SMPFMT_S32LSB,
  577.   SMPFMT_F32    = SMPFMT_F32LSB,
  578.   SMPFMT_F64    = SMPFMT_F64LSB,
  579.  
  580.  
  581.   //may also be used as a wildcard
  582.    //(as in this may be associated with a value != 0xFFFF)
  583.   SMPFMT_UKNOWN = 0xFFFF,
  584.  
  585. };
  586.  
  587.  
  588.  
  589.  
  590.  
  591. struct AudioDeviceInfo; //forward declaration
  592.  
  593. //returns:
  594.  //< 0: abort playback (pause without fade-out)
  595.  //= 0: continue playing
  596.  //> 0: pause playback (pause with fade-out)
  597. //(also, _buffer will already be aligned and padded for use
  598.  //with vector operations, like those in SSE and AVX!)
  599. typedef s32 (*AudioCallback)(void* _buffer, const AudioDeviceInfo& info);
  600.  
  601.  
  602.  
  603.  
  604.  
  605. /* (taken from the SDL2 wiki):
  606.  
  607. For multi-channel audio, the default SDL channel mapping is:
  608.  
  609. 2:  FL  FR                          (stereo)
  610. 3:  FL  FR LFE                      (2.1 surround)
  611. 4:  FL  FR  BL  BR                  (quad)
  612. 5:  FL  FR LFE  BL  BR              (4.1 surround)
  613. 6:  FL  FR  FC LFE  SL  SR          (5.1 surround - last two can also be BL BR)
  614. 7:  FL  FR  FC LFE  BC  SL  SR      (6.1 surround)
  615. 8:  FL  FR  FC LFE  BL  BR  SL  SR  (7.1 surround)
  616.  
  617. */
  618.  
  619. struct AudioDeviceInfo { //48B
  620.   u64     timeStartTicks = 0; //timestamp (in ticks) at start of callback (read-only)
  621.   u64        timeStartMS = 0; //timestamp (in ms) at start of callback (read-only)
  622.   u32           deviceID = 0; //(read-only)
  623.   u32         sampleRate = 0; //0 to use device's default (must be <= KIT_S32_MAX)
  624.   u16       sampleFrames = 0; //0 to use device's default (powers of 2 *recommended* when manually setting)
  625.   u16       sampleFormat = SMPFMT_F32; //samples are f32 by default
  626.   u8     sampleFrameSize = 0; //size of a single sample frame, in bytes (read only)
  627.   u8         numChannels = 0; //0 to use device's default
  628.   bool           isInput = false; //is this a recording device? (rendering/output otherwise)
  629.   bool        zeroBuffer = false; //'memset 0 the audio buffer before calling callback?' (output devs only)
  630.   AudioCallback callback = nullptr;
  631.   void*         userdata = nullptr; //optional, unlike callback
  632.  
  633. };
  634.  
  635.  
  636.  
  637.  
  638.  
  639. //(s24 IS NOT INCLUDED HERE)
  640.  
  641. union Mono_smp {
  642.   u8 *  u8_ ;
  643.   s8 *  s8_ ;
  644.   u16*  u16_;
  645.   s16*  s16_;
  646.   s32*  s32_;
  647.   f32*  f32_;
  648.   f64*  f64_;
  649.  
  650.   void* data;
  651.  
  652.   Mono_smp(void* _data) : data(_data) {}
  653.  
  654. };
  655.  
  656.  
  657.  
  658.  
  659.  
  660. //(s24 IS NOT INCLUDED HERE)
  661.  
  662. struct Stereo_u8  {
  663.   u8 l, r;
  664.  
  665.   inline Stereo_u8(){}
  666.   inline Stereo_u8(u8 _v) : l(_v), r(_v) {}
  667.   inline Stereo_u8(u8 _l, u8 _r) : l(_l), r(_r) {}
  668.  
  669. };
  670.  
  671.  
  672. struct Stereo_s8  {
  673.   s8 l, r;
  674.  
  675.   inline Stereo_s8(){}
  676.   inline Stereo_s8(s8 _v) : l(_v), r(_v) {}
  677.   inline Stereo_s8(s8 _l, s8 _r) : l(_l), r(_r) {}
  678.  
  679. };
  680.  
  681.  
  682. struct Stereo_u16 {
  683.   u16 l, r;
  684.  
  685.   inline Stereo_u16(){}
  686.   inline Stereo_u16(u16 _v) : l(_v), r(_v) {}
  687.   inline Stereo_u16(u16 _l, u16 _r) : l(_l), r(_r) {}
  688.  
  689. };
  690.  
  691.  
  692. struct Stereo_s16 {
  693.   s16 l, r;
  694.  
  695.   inline Stereo_s16(){}
  696.   inline Stereo_s16(s16 _v) : l(_v), r(_v) {}
  697.   inline Stereo_s16(s16 _l, s16 _r) : l(_l), r(_r) {}
  698.  
  699. };
  700.  
  701.  
  702. struct Stereo_s32 {
  703.   s32 l, r;
  704.  
  705.   inline Stereo_s32(){}
  706.   inline Stereo_s32(s32 _v) : l(_v), r(_v) {}
  707.   inline Stereo_s32(s32 _l, s32 _r) : l(_l), r(_r) {}
  708.  
  709. };
  710.  
  711.  
  712. struct Stereo_f32 {
  713.   f32 l, r;
  714.  
  715.   inline Stereo_f32(){}
  716.   inline Stereo_f32(f32 _v) : l(_v), r(_v) {}
  717.   inline Stereo_f32(f32 _l, f32 _r) : l(_l), r(_r) {}
  718.  
  719. };
  720.  
  721.  
  722. struct Stereo_f64 {
  723.   f64 l, r;
  724.  
  725.   inline Stereo_f64(){}
  726.   inline Stereo_f64(f64 _v) : l(_v), r(_v) {}
  727.   inline Stereo_f64(f64 _l, f64 _r) : l(_l), r(_r) {}
  728.  
  729. };
  730.  
  731.  
  732. union Stereo_smp {
  733.   Stereo_u8*  u8_ ;
  734.   Stereo_s8*  s8_ ;
  735.   Stereo_u16* u16_;
  736.   Stereo_s16* s16_;
  737.   Stereo_s32* s32_;
  738.   Stereo_f32* f32_;
  739.   Stereo_f64* f64_;
  740.  
  741.   void*       data;
  742.  
  743.   Stereo_smp(void* _data) : data(_data) {}
  744.  
  745. };
  746.  
  747.  
  748.  
  749.  
  750.  
  751. }; /* namespace kit */
  752.  
  753. #endif /* _INC__AUDIO_TYPES_HPP */
  754. /******************************************************************************/
  755. /******************************************************************************/
  756. //"2024-11-21\include\kit\_misc_Event.hpp":
  757. #ifndef _INC__MISC_EVENT_HPP
  758. #define _INC__MISC_EVENT_HPP
  759.  
  760. #include "commondef.hpp"
  761.  
  762.  
  763. namespace kit {
  764.  
  765.  
  766.  
  767.  
  768.  
  769. #define KIT_EVENT_ID(_id) ( (_id) & 0xFFFF0000 )
  770. #define KIT_SUBEVENT_ID(_sub_id) ( (_sub_id) & 0xFFFF )
  771. #define _KIT_INC_ETYPE(_previous_type) ( (_previous_type) + 0x00010000 )
  772.  
  773. enum EventTypesEnum {
  774.   KEVENT_NULL                 = 0x00000000,
  775.  
  776.   //(common is not an actual event that occurs,
  777.    //it just includes what the other events have in common)
  778.   KEVENT_COMMON               = _KIT_INC_ETYPE(KEVENT_NULL), //Event_Common
  779.  
  780.   KEVENT_DISPLAY              = _KIT_INC_ETYPE(KEVENT_COMMON), //Event_Display
  781.   KEVENT_DISPLAY_ORIENTATION  = KEVENT_DISPLAY | 0x0001, //display orientation has changed to data1
  782.   KEVENT_DISPLAY_DISCONNECTED = KEVENT_DISPLAY | 0x0002, //display has been removed from the system
  783.   KEVENT_DISPLAY_CONNECTED    = KEVENT_DISPLAY | 0x0003, //display has been added to the system
  784.   KEVENT_DISPLAY_MOVED        = KEVENT_DISPLAY | 0x0004, //display has changed position
  785.  
  786.   KEVENT_WIN                  = _KIT_INC_ETYPE(KEVENT_DISPLAY), //Event_Window
  787.   KEVENT_WIN_EXPOSED          = KEVENT_WIN | 0x0001, //window has been exposed and should be redrawn
  788.   KEVENT_WIN_HIDDEN           = KEVENT_WIN | 0x0002, //window has been hidden
  789.   KEVENT_WIN_SHOWN            = KEVENT_WIN | 0x0003, //window has been shown
  790.   KEVENT_WIN_MOVED            = KEVENT_WIN | 0x0004, //window has been moved to dataX, dataY
  791.   KEVENT_WIN_RESIZED          = KEVENT_WIN | 0x0005, //window has been resized to dataX, dataY
  792.   KEVENT_WIN_SIZE_CHANGED     = KEVENT_WIN | 0x0006, //window size has changed, via API, system, or user.
  793.   KEVENT_WIN_RESTORED         = KEVENT_WIN | 0x0007, //window has been restored to normal size and position
  794.   KEVENT_WIN_MINIMIZED        = KEVENT_WIN | 0x0008, //window has been minimized
  795.   KEVENT_WIN_MAXIMIZED        = KEVENT_WIN | 0x0009, //window has been maximized
  796.   KEVENT_WIN_MFOCUS_LOST      = KEVENT_WIN | 0x000A, //window has lost mouse focus (mouse left window)
  797.   KEVENT_WIN_MFOCUS_GAINED    = KEVENT_WIN | 0x000B, //window has gained mouse focus (mouse entered window)
  798.   KEVENT_WIN_KFOCUS_LOST      = KEVENT_WIN | 0x000C, //window has lost keyboard focus
  799.   KEVENT_WIN_KFOCUS_GAINED    = KEVENT_WIN | 0x000D, //window has gained keyboard focus
  800.   KEVENT_WIN_CLOSE            = KEVENT_WIN | 0x000E, //window manager requests that the window be closed
  801.   KEVENT_WIN_TAKE_FOCUS       = KEVENT_WIN | 0x000F, //window is being offered a focus (should set window input focus on itself or a subwindow, or ignore)
  802.   KEVENT_WIN_HIT_TEST         = KEVENT_WIN | 0x0010, //window had a hit test that wasn't HITTEST_NORMAL.
  803.   KEVENT_WIN_ICCPROF_CHANGED  = KEVENT_WIN | 0x0011, //the ICC profile of the window's display has changed.
  804.   KEVENT_WIN_DISPLAY_CHANGED  = KEVENT_WIN | 0x0012, //window has been moved to display data1.
  805.  
  806.   KEVENT_KEY                  = _KIT_INC_ETYPE(KEVENT_WIN), //Event_Key
  807.   KEVENT_KEY_DOWN             = KEVENT_KEY | 0x0001,
  808.   KEVENT_KEY_UP               = KEVENT_KEY | 0x0002,
  809.  
  810.   KEVENT_KEYMAPCHANGED        = _KIT_INC_ETYPE(KEVENT_KEY), //(N/A); keymap changed by a input language/layout system event
  811.  
  812.   KEVENT_MOUSE                = _KIT_INC_ETYPE(KEVENT_KEYMAPCHANGED), //Event_Mouse
  813.   KEVENT_MOUSE_MOVED          = KEVENT_MOUSE | 0x0001,
  814.   KEVENT_MOUSE_UP             = KEVENT_MOUSE | 0x0002,
  815.   KEVENT_MOUSE_DOWN           = KEVENT_MOUSE | 0x0003,
  816.   KEVENT_MOUSE_WHEEL          = KEVENT_MOUSE | 0x0004,
  817.  
  818.   KEVENT_JOY                  = _KIT_INC_ETYPE(KEVENT_MOUSE), //Event_Joystick
  819.   KEVENT_JOY_AXIS             = KEVENT_JOY | 0x0001,
  820.   KEVENT_JOY_TRACKBALL        = KEVENT_JOY | 0x0002,
  821.   KEVENT_JOY_HAT              = KEVENT_JOY | 0x0003,
  822.   KEVENT_JOY_BUTTON_UP        = KEVENT_JOY | 0x0004,
  823.   KEVENT_JOY_BUTTON_DOWN      = KEVENT_JOY | 0x0005,
  824.   KEVENT_JOY_DEVICE_REMOVED   = KEVENT_JOY | 0x0006,
  825.   KEVENT_JOY_DEVICE_ADDED     = KEVENT_JOY | 0x0007,
  826.   KEVENT_JOY_BATTERY          = KEVENT_JOY | 0x0008,
  827.  
  828.   KEVENT_CTLR                 = _KIT_INC_ETYPE(KEVENT_JOY), //Event_GameController
  829.   KEVENT_CTLR_AXIS            = KEVENT_CTLR | 0x0001,
  830.   KEVENT_CTLR_BUTTON_UP       = KEVENT_CTLR | 0x0002,
  831.   KEVENT_CTLR_BUTTON_DOWN     = KEVENT_CTLR | 0x0003,
  832.   KEVENT_CTLR_DEVICE_REMOVED  = KEVENT_CTLR | 0x0004,
  833.   KEVENT_CTLR_DEVICE_ADDED    = KEVENT_CTLR | 0x0005,
  834.   KEVENT_CTLR_DEVICE_REMAPPED = KEVENT_CTLR | 0x0006,
  835.   KEVENT_CTLR_TOUCHPAD_UP     = KEVENT_CTLR | 0x0007,
  836.   KEVENT_CTLR_TOUCHPAD_DOWN   = KEVENT_CTLR | 0x0008,
  837.   KEVENT_CTLR_TOUCHPAD_MOVED  = KEVENT_CTLR | 0x0009,
  838.   KEVENT_CTLR_SENSOR          = KEVENT_CTLR | 0x000A,
  839.  
  840.   KEVENT_ADEV                 = _KIT_INC_ETYPE(KEVENT_CTLR), //Event_AudioDevice
  841.   KEVENT_ADEV_ADDED           = KEVENT_ADEV | 0x0001,
  842.   KEVENT_ADEV_REMOVED         = KEVENT_ADEV | 0x0002,
  843.  
  844.   KEVENT_DROP                 = _KIT_INC_ETYPE(KEVENT_ADEV), //Event_Drop
  845.   KEVENT_DROP_FILE            = KEVENT_DROP | 0x0001, //system requests a file to open
  846.   KEVENT_DROP_TEXT            = KEVENT_DROP | 0x0002, //text/plain drag-and-drop event
  847.   KEVENT_DROP_BEGIN           = KEVENT_DROP | 0x0003, //new set of drops beginning (filePath=nullptr)
  848.   KEVENT_DROP_COMPLETE        = KEVENT_DROP | 0x0004, //current set of drops complete (filePath=nullptr)
  849.  
  850.   KEVENT_QUIT                 = _KIT_INC_ETYPE(KEVENT_DROP), //Event_Quit
  851.  
  852.   KEVENT_USER                 = _KIT_INC_ETYPE(KEVENT_QUIT), //Event_User
  853.  
  854.   KEVENT_RENDER               = _KIT_INC_ETYPE(KEVENT_USER), //(N/A)
  855.   KEVENT_RENDER_TARGETS_RESET = KEVENT_RENDER | 0x0001,
  856.   KEVENT_RENDER_DEVICE_RESET  = KEVENT_RENDER | 0x0002,
  857.  
  858.   KEVENT_CLIPBOARDUPDATE      = _KIT_INC_ETYPE(KEVENT_RENDER), //(N/A)
  859.  
  860.  
  861.   KEVENT_UNKNOWN              = 0xFFFFFFFF,
  862.  
  863.   NUM_KEVENT_TYPES            = KEVENT_CLIPBOARDUPDATE >> 16,
  864.  
  865. };
  866.  
  867.  
  868.  
  869.  
  870.  
  871. /*+KEVENT_COMMON+*/
  872.  
  873. struct Event_Common { //8B
  874.   u32 type;
  875.   u32 timestamp; //in milliseconds, same as getMS_32
  876. };
  877.  
  878. /*-KEVENT_COMMON-*/
  879.  
  880.  
  881.  
  882.  
  883.  
  884. /*+KEVENT_DISPLAY+*/
  885.  
  886. struct Event_Display { //16B
  887.   u32 type;
  888.   u32 timestamp;
  889.   u32 id; //index of associated display
  890.   s32 data;
  891. };
  892.  
  893. /*-KEVENT_DISPLAY-*/
  894.  
  895.  
  896.  
  897.  
  898.  
  899. /*+KEVENT_WIN+*/
  900.  
  901. enum Event_Window_HitTestEnum {
  902.   WIN_HITTEST_NORMAL,    // Region is normal. No special properties.
  903.   WIN_HITTEST_DRAGGABLE, // Region can drag entire window.
  904.   WIN_HITTEST_RESIZE_TOPLEFT,
  905.   WIN_HITTEST_RESIZE_TOP,
  906.   WIN_HITTEST_RESIZE_TOPRIGHT,
  907.   WIN_HITTEST_RESIZE_RIGHT,
  908.   WIN_HITTEST_RESIZE_BOTTOMRIGHT,
  909.   WIN_HITTEST_RESIZE_BOTTOM,
  910.   WIN_HITTEST_RESIZE_BOTTOMLEFT,
  911.   WIN_HITTEST_RESIZE_LEFT
  912. };
  913.  
  914. struct Event_Window { //24B
  915.   u32 type;
  916.   u32 timestamp;
  917.   u32 id; //index of associated window
  918.   u32 _padding32;
  919.   union { s32 data1, x; };
  920.   union { s32 data2, y; };
  921. };
  922.  
  923. /*-KEVENT_WIN-*/
  924.  
  925.  
  926.  
  927.  
  928.  
  929. /*+KEVENT_KEY+*/
  930.  
  931. //(these enums are mostly ripped directly from
  932.  //SDL2's header files! please don't sue me! D:)
  933. enum Event_Key_PhysicalEnum { //aka scancodes
  934.     PKEY_UNKNOWN = 0,
  935.  
  936.     /**
  937.      *  \name Usage page 0x07
  938.      *
  939.      *  These values are from usage page 0x07 (USB keyboard page).
  940.      */
  941.     /* @{ */
  942.  
  943.     PKEY_A =  4,
  944.     PKEY_B =  5,
  945.     PKEY_C =  6,
  946.     PKEY_D =  7,
  947.     PKEY_E =  8,
  948.     PKEY_F =  9,
  949.     PKEY_G = 10,
  950.     PKEY_H = 11,
  951.     PKEY_I = 12,
  952.     PKEY_J = 13,
  953.     PKEY_K = 14,
  954.     PKEY_L = 15,
  955.     PKEY_M = 16,
  956.     PKEY_N = 17,
  957.     PKEY_O = 18,
  958.     PKEY_P = 19,
  959.     PKEY_Q = 20,
  960.     PKEY_R = 21,
  961.     PKEY_S = 22,
  962.     PKEY_T = 23,
  963.     PKEY_U = 24,
  964.     PKEY_V = 25,
  965.     PKEY_W = 26,
  966.     PKEY_X = 27,
  967.     PKEY_Y = 28,
  968.     PKEY_Z = 29,
  969.  
  970.     PKEY_1 = 30,
  971.     PKEY_2 = 31,
  972.     PKEY_3 = 32,
  973.     PKEY_4 = 33,
  974.     PKEY_5 = 34,
  975.     PKEY_6 = 35,
  976.     PKEY_7 = 36,
  977.     PKEY_8 = 37,
  978.     PKEY_9 = 38,
  979.     PKEY_0 = 39,
  980.  
  981.     PKEY_RETURN    = 40,
  982.     PKEY_ESCAPE    = 41,
  983.     PKEY_BACKSPACE = 42,
  984.     PKEY_TAB       = 43,
  985.     PKEY_SPACE     = 44,
  986.  
  987.     PKEY_MINUS        = 45,
  988.     PKEY_EQUALS       = 46,
  989.     PKEY_LEFTBRACKET  = 47,
  990.     PKEY_RIGHTBRACKET = 48,
  991.     PKEY_BACKSLASH    = 49, /**< Located at the lower left of the return
  992.                              *   key on ISO keyboards and at the right end
  993.                              *   of the QWERTY row on ANSI keyboards.
  994.                              *   Produces REVERSE SOLIDUS (backslash) and
  995.                              *   VERTICAL LINE in a US layout, REVERSE
  996.                              *   SOLIDUS and VERTICAL LINE in a UK Mac
  997.                              *   layout, NUMBER SIGN and TILDE in a UK
  998.                              *   Windows layout, DOLLAR SIGN and POUND SIGN
  999.                              *   in a Swiss German layout, NUMBER SIGN and
  1000.                              *   APOSTROPHE in a German layout, GRAVE
  1001.                              *   ACCENT and POUND SIGN in a French Mac
  1002.                              *   layout, and ASTERISK and MICRO SIGN in a
  1003.                              *   French Windows layout.
  1004.                              */
  1005.     PKEY_NONUSHASH    = 50, /**< ISO USB keyboards actually use this code
  1006.                              *   instead of 49 for the same key, but all
  1007.                              *   OSes I've seen treat the two codes
  1008.                              *   identically. So, as an implementor, unless
  1009.                              *   your keyboard generates both of those
  1010.                              *   codes and your OS treats them differently,
  1011.                              *   you should generate PKEY_BACKSLASH
  1012.                              *   instead of this code. As a user, you
  1013.                              *   should not rely on this code because SDL
  1014.                              *   will never generate it with most (all?)
  1015.                              *   keyboards.
  1016.                              */
  1017.     PKEY_SEMICOLON    = 51,
  1018.     PKEY_APOSTROPHE   = 52,
  1019.     PKEY_GRAVE        = 53, /**< Located in the top left corner (on both ANSI
  1020.                              *   and ISO keyboards). Produces GRAVE ACCENT and
  1021.                              *   TILDE in a US Windows layout and in US and UK
  1022.                              *   Mac layouts on ANSI keyboards, GRAVE ACCENT
  1023.                              *   and NOT SIGN in a UK Windows layout, SECTION
  1024.                              *   SIGN and PLUS-MINUS SIGN in US and UK Mac
  1025.                              *   layouts on ISO keyboards, SECTION SIGN and
  1026.                              *   DEGREE SIGN in a Swiss German layout (Mac:
  1027.                              *   only on ISO keyboards), CIRCUMFLEX ACCENT and
  1028.                              *   DEGREE SIGN in a German layout (Mac: only on
  1029.                              *   ISO keyboards), SUPERSCRIPT TWO and TILDE in a
  1030.                              *   French Windows layout, COMMERCIAL AT and
  1031.                              *   NUMBER SIGN in a French Mac layout on ISO
  1032.                              *   keyboards, and LESS-THAN SIGN and GREATER-THAN
  1033.                              *   SIGN in a Swiss German, German, or French Mac
  1034.                              *   layout on ANSI keyboards.
  1035.                              */
  1036.     PKEY_COMMA        = 54,
  1037.     PKEY_PERIOD       = 55,
  1038.     PKEY_SLASH        = 56,
  1039.  
  1040.     PKEY_CAPSLOCK = 57,
  1041.  
  1042.     PKEY_F1  = 58,
  1043.     PKEY_F2  = 59,
  1044.     PKEY_F3  = 60,
  1045.     PKEY_F4  = 61,
  1046.     PKEY_F5  = 62,
  1047.     PKEY_F6  = 63,
  1048.     PKEY_F7  = 64,
  1049.     PKEY_F8  = 65,
  1050.     PKEY_F9  = 66,
  1051.     PKEY_F10 = 67,
  1052.     PKEY_F11 = 68,
  1053.     PKEY_F12 = 69,
  1054.  
  1055.     PKEY_PRINTSCREEN = 70,
  1056.     PKEY_SCROLLLOCK  = 71,
  1057.     PKEY_PAUSE       = 72,
  1058.     PKEY_INSERT      = 73, /**< insert on PC, help on some Mac keyboards (but
  1059.                              does send code 73, not 117) */
  1060.     PKEY_HOME        = 74,
  1061.     PKEY_PAGEUP      = 75,
  1062.     PKEY_DELETE      = 76,
  1063.     PKEY_END         = 77,
  1064.     PKEY_PAGEDOWN    = 78,
  1065.     PKEY_RIGHT       = 79,
  1066.     PKEY_LEFT        = 80,
  1067.     PKEY_DOWN        = 81,
  1068.     PKEY_UP          = 82,
  1069.  
  1070.     PKEY_NUMLOCKCLEAR = 83, /**< num lock on PC, clear on Mac keyboards */
  1071.     PKEY_KP_DIVIDE    = 84,
  1072.     PKEY_KP_MULTIPLY  = 85,
  1073.     PKEY_KP_MINUS     = 86,
  1074.     PKEY_KP_PLUS      = 87,
  1075.     PKEY_KP_ENTER     = 88,
  1076.     PKEY_KP_1         = 89,
  1077.     PKEY_KP_2         = 90,
  1078.     PKEY_KP_3         = 91,
  1079.     PKEY_KP_4         = 92,
  1080.     PKEY_KP_5         = 93,
  1081.     PKEY_KP_6         = 94,
  1082.     PKEY_KP_7         = 95,
  1083.     PKEY_KP_8         = 96,
  1084.     PKEY_KP_9         = 97,
  1085.     PKEY_KP_0         = 98,
  1086.     PKEY_KP_PERIOD    = 99,
  1087.  
  1088.     PKEY_NONUSBACKSLASH = 100, /**< This is the additional key that ISO
  1089.                                 *   keyboards have over ANSI ones,
  1090.                                 *   located between left shift and Y.
  1091.                                 *   Produces GRAVE ACCENT and TILDE in a
  1092.                                 *   US or UK Mac layout, REVERSE SOLIDUS
  1093.                                 *   (backslash) and VERTICAL LINE in a
  1094.                                 *   US or UK Windows layout, and
  1095.                                 *   LESS-THAN SIGN and GREATER-THAN SIGN
  1096.                                 *   in a Swiss German, German, or French
  1097.                                 *   layout. */
  1098.     PKEY_APPLICATION    = 101, /**< windows contextual menu, compose */
  1099.     PKEY_POWER          = 102, /**< The USB document says this is a status flag,
  1100.                                 *   not a physical key - but some Mac keyboards
  1101.                                 *   do have a power key. */
  1102.     PKEY_KP_EQUALS      = 103,
  1103.     PKEY_F13            = 104,
  1104.     PKEY_F14            = 105,
  1105.     PKEY_F15            = 106,
  1106.     PKEY_F16            = 107,
  1107.     PKEY_F17            = 108,
  1108.     PKEY_F18            = 109,
  1109.     PKEY_F19            = 110,
  1110.     PKEY_F20            = 111,
  1111.     PKEY_F21            = 112,
  1112.     PKEY_F22            = 113,
  1113.     PKEY_F23            = 114,
  1114.     PKEY_F24            = 115,
  1115.     PKEY_EXECUTE        = 116,
  1116.     PKEY_HELP           = 117, /**< AL Integrated Help Center */
  1117.     PKEY_MENU           = 118, /**< Menu (show menu) */
  1118.     PKEY_SELECT         = 119,
  1119.     PKEY_STOP           = 120, /**< AC Stop */
  1120.     PKEY_AGAIN          = 121, /**< AC Redo/Repeat */
  1121.     PKEY_UNDO           = 122, /**< AC Undo */
  1122.     PKEY_CUT            = 123, /**< AC Cut */
  1123.     PKEY_COPY           = 124, /**< AC Copy */
  1124.     PKEY_PASTE          = 125, /**< AC Paste */
  1125.     PKEY_FIND           = 126, /**< AC Find */
  1126.     PKEY_MUTE           = 127,
  1127.     PKEY_VOLUMEUP       = 128,
  1128.     PKEY_VOLUMEDOWN     = 129,
  1129. /* not sure whether there's a reason to enable these */
  1130. /*  PKEY_LOCKINGCAPSLOCK   = 130, */
  1131. /*  PKEY_LOCKINGNUMLOCK    = 131, */
  1132. /*  PKEY_LOCKINGSCROLLLOCK = 132, */
  1133.     PKEY_KP_COMMA       = 133,
  1134.     PKEY_KP_EQUALSAS400 = 134,
  1135.  
  1136.     PKEY_INTERNATIONAL1 = 135, /**< used on Asian keyboards, see
  1137.                                     footnotes in USB doc */
  1138.     PKEY_INTERNATIONAL2 = 136,
  1139.     PKEY_INTERNATIONAL3 = 137, /**< Yen */
  1140.     PKEY_INTERNATIONAL4 = 138,
  1141.     PKEY_INTERNATIONAL5 = 139,
  1142.     PKEY_INTERNATIONAL6 = 140,
  1143.     PKEY_INTERNATIONAL7 = 141,
  1144.     PKEY_INTERNATIONAL8 = 142,
  1145.     PKEY_INTERNATIONAL9 = 143,
  1146.     PKEY_LANG1          = 144, /**< Hangul/English toggle */
  1147.     PKEY_LANG2          = 145, /**< Hanja conversion */
  1148.     PKEY_LANG3          = 146, /**< Katakana */
  1149.     PKEY_LANG4          = 147, /**< Hiragana */
  1150.     PKEY_LANG5          = 148, /**< Zenkaku/Hankaku */
  1151.     PKEY_LANG6          = 149, /**< reserved */
  1152.     PKEY_LANG7          = 150, /**< reserved */
  1153.     PKEY_LANG8          = 151, /**< reserved */
  1154.     PKEY_LANG9          = 152, /**< reserved */
  1155.  
  1156.     PKEY_ALTERASE   = 153, /**< Erase-Eaze */
  1157.     PKEY_SYSREQ     = 154,
  1158.     PKEY_CANCEL     = 155, /**< AC Cancel */
  1159.     PKEY_CLEAR      = 156,
  1160.     PKEY_PRIOR      = 157,
  1161.     PKEY_RETURN2    = 158,
  1162.     PKEY_SEPARATOR  = 159,
  1163.     PKEY_OUT        = 160,
  1164.     PKEY_OPER       = 161,
  1165.     PKEY_CLEARAGAIN = 162,
  1166.     PKEY_CRSEL      = 163,
  1167.     PKEY_EXSEL      = 164,
  1168.  
  1169.     PKEY_KP_00              = 176,
  1170.     PKEY_KP_000             = 177,
  1171.     PKEY_THOUSANDSSEPARATOR = 178,
  1172.     PKEY_DECIMALSEPARATOR   = 179,
  1173.     PKEY_CURRENCYUNIT       = 180,
  1174.     PKEY_CURRENCYSUBUNIT    = 181,
  1175.     PKEY_KP_LEFTPAREN       = 182,
  1176.     PKEY_KP_RIGHTPAREN      = 183,
  1177.     PKEY_KP_LEFTBRACE       = 184,
  1178.     PKEY_KP_RIGHTBRACE      = 185,
  1179.     PKEY_KP_TAB             = 186,
  1180.     PKEY_KP_BACKSPACE       = 187,
  1181.     PKEY_KP_A               = 188,
  1182.     PKEY_KP_B               = 189,
  1183.     PKEY_KP_C               = 190,
  1184.     PKEY_KP_D               = 191,
  1185.     PKEY_KP_E               = 192,
  1186.     PKEY_KP_F               = 193,
  1187.     PKEY_KP_XOR             = 194,
  1188.     PKEY_KP_POWER           = 195,
  1189.     PKEY_KP_PERCENT         = 196,
  1190.     PKEY_KP_LESS            = 197,
  1191.     PKEY_KP_GREATER         = 198,
  1192.     PKEY_KP_AMPERSAND       = 199,
  1193.     PKEY_KP_DBLAMPERSAND    = 200,
  1194.     PKEY_KP_VERTICALBAR     = 201,
  1195.     PKEY_KP_DBLVERTICALBAR  = 202,
  1196.     PKEY_KP_COLON           = 203,
  1197.     PKEY_KP_HASH            = 204,
  1198.     PKEY_KP_SPACE           = 205,
  1199.     PKEY_KP_AT              = 206,
  1200.     PKEY_KP_EXCLAM          = 207,
  1201.     PKEY_KP_MEMSTORE        = 208,
  1202.     PKEY_KP_MEMRECALL       = 209,
  1203.     PKEY_KP_MEMCLEAR        = 210,
  1204.     PKEY_KP_MEMADD          = 211,
  1205.     PKEY_KP_MEMSUBTRACT     = 212,
  1206.     PKEY_KP_MEMMULTIPLY     = 213,
  1207.     PKEY_KP_MEMDIVIDE       = 214,
  1208.     PKEY_KP_PLUSMINUS       = 215,
  1209.     PKEY_KP_CLEAR           = 216,
  1210.     PKEY_KP_CLEARENTRY      = 217,
  1211.     PKEY_KP_BINARY          = 218,
  1212.     PKEY_KP_OCTAL           = 219,
  1213.     PKEY_KP_DECIMAL         = 220,
  1214.     PKEY_KP_HEXADECIMAL     = 221,
  1215.  
  1216.     PKEY_LCTRL  = 224,
  1217.     PKEY_LSHIFT = 225,
  1218.     PKEY_LALT   = 226, /**< alt, option */
  1219.     PKEY_LGUI   = 227, /**< windows, command (apple), meta */
  1220.     PKEY_RCTRL  = 228,
  1221.     PKEY_RSHIFT = 229,
  1222.     PKEY_RALT   = 230, /**< alt gr, option */
  1223.     PKEY_RGUI   = 231, /**< windows, command (apple), meta */
  1224.  
  1225.     PKEY_MODE   = 257, /**< I'm not sure if this is really not covered
  1226.                         *   by any of the above, but since there's a
  1227.                         *   special KEYMOD_MODE for it I'm adding it here
  1228.                         */
  1229.  
  1230.     /* @} *//* Usage page 0x07 */
  1231.  
  1232.     /**
  1233.      *  \name Usage page 0x0C
  1234.      *
  1235.      *  These values are mapped from usage page 0x0C (USB consumer page).
  1236.      *  See https://usb.org/sites/default/files/hut1_2.pdf
  1237.      *
  1238.      *  There are way more keys in the spec than we can represent in the
  1239.      *  current scancode range, so pick the ones that commonly come up in
  1240.      *  real world usage.
  1241.      */
  1242.     /* @{ */
  1243.  
  1244.     PKEY_AUDIONEXT    = 258,
  1245.     PKEY_AUDIOPREV    = 259,
  1246.     PKEY_AUDIOSTOP    = 260,
  1247.     PKEY_AUDIOPLAY    = 261,
  1248.     PKEY_AUDIOMUTE    = 262,
  1249.     PKEY_MEDIASELECT  = 263,
  1250.     PKEY_WWW          = 264, /**< AL Internet Browser */
  1251.     PKEY_MAIL         = 265,
  1252.     PKEY_CALCULATOR   = 266, /**< AL Calculator */
  1253.     PKEY_COMPUTER     = 267,
  1254.     PKEY_AC_SEARCH    = 268, /**< AC Search */
  1255.     PKEY_AC_HOME      = 269, /**< AC Home */
  1256.     PKEY_AC_BACK      = 270, /**< AC Back */
  1257.     PKEY_AC_FORWARD   = 271, /**< AC Forward */
  1258.     PKEY_AC_STOP      = 272, /**< AC Stop */
  1259.     PKEY_AC_REFRESH   = 273, /**< AC Refresh */
  1260.     PKEY_AC_BOOKMARKS = 274, /**< AC Bookmarks */
  1261.  
  1262.     /* @} *//* Usage page 0x0C */
  1263.  
  1264.     /**
  1265.      *  \name Walther keys
  1266.      *
  1267.      *  These are values that Christian Walther added (for mac keyboard?).
  1268.      */
  1269.     /* @{ */
  1270.  
  1271.     PKEY_BRIGHTNESSDOWN = 275,
  1272.     PKEY_BRIGHTNESSUP   = 276,
  1273.     PKEY_DISPLAYSWITCH  = 277, /**< display mirroring/dual display
  1274.                                     switch, video mode switch */
  1275.     PKEY_KBDILLUMTOGGLE = 278,
  1276.     PKEY_KBDILLUMDOWN   = 279,
  1277.     PKEY_KBDILLUMUP     = 280,
  1278.     PKEY_EJECT          = 281,
  1279.     PKEY_SLEEP          = 282, /**< SC System Sleep */
  1280.  
  1281.     PKEY_APP1 = 283,
  1282.     PKEY_APP2 = 284,
  1283.  
  1284.     /* @} *//* Walther keys */
  1285.  
  1286.     /**
  1287.      *  \name Usage page 0x0C (additional media keys)
  1288.      *
  1289.      *  These values are mapped from usage page 0x0C (USB consumer page).
  1290.      */
  1291.     /* @{ */
  1292.  
  1293.     PKEY_AUDIOREWIND      = 285,
  1294.     PKEY_AUDIOFASTFORWARD = 286,
  1295.  
  1296.     /* @} *//* Usage page 0x0C (additional media keys) */
  1297.  
  1298.     /**
  1299.      *  \name Mobile keys
  1300.      *
  1301.      *  These are values that are often used on mobile phones.
  1302.      */
  1303.     /* @{ */
  1304.  
  1305.     PKEY_SOFTLEFT = 287, /**< Usually situated below the display on phones and
  1306.                               used as a multi-function feature key for selecting
  1307.                               a software defined function shown on the bottom left
  1308.                               of the display. */
  1309.     PKEY_SOFTRIGHT = 288, /**< Usually situated below the display on phones and
  1310.                                used as a multi-function feature key for selecting
  1311.                                a software defined function shown on the bottom right
  1312.                                of the display. */
  1313.     PKEY_CALL    = 289, /**< Used for accepting phone calls. */
  1314.     PKEY_ENDCALL = 290, /**< Used for rejecting phone calls. */
  1315.  
  1316.     /* @} *//* Mobile keys */
  1317.  
  1318.     /* Add any other keys here. */
  1319.  
  1320.     KIT_NUM_PKEYS = 512 /**< not a key, just marks the number of scancodes
  1321.                              for array bounds */
  1322. };
  1323.  
  1324. #define _KIT_PKEY_MASK (1<<30)
  1325. #define KIT_PKEY_TO_VKEY(X)  (X | _KIT_PKEY_MASK)
  1326.  
  1327. enum Event_Key_VirtualEnum {
  1328.   VKEY_UNKNOWN = 0,
  1329.  
  1330.   VKEY_RETURN     = '\r',
  1331.   VKEY_ESCAPE     = '\x1B',
  1332.   VKEY_BACKSPACE  = '\b',
  1333.   VKEY_TAB        = '\t',
  1334.   VKEY_SPACE      = ' ',
  1335.   VKEY_EXCLAIM    = '!',
  1336.   VKEY_QUOTEDBL   = '"',
  1337.   VKEY_HASH       = '#',
  1338.   VKEY_PERCENT    = '%',
  1339.   VKEY_DOLLAR     = '$',
  1340.   VKEY_AMPERSAND  = '&',
  1341.   VKEY_QUOTE      = '\'',
  1342.   VKEY_LEFTPAREN  = '(',
  1343.   VKEY_RIGHTPAREN = ')',
  1344.   VKEY_ASTERISK   = '*',
  1345.   VKEY_PLUS       = '+',
  1346.   VKEY_COMMA      = ',',
  1347.   VKEY_MINUS      = '-',
  1348.   VKEY_PERIOD     = '.',
  1349.   VKEY_SLASH      = '/',
  1350.   VKEY_0          = '0',
  1351.   VKEY_1          = '1',
  1352.   VKEY_2          = '2',
  1353.   VKEY_3          = '3',
  1354.   VKEY_4          = '4',
  1355.   VKEY_5          = '5',
  1356.   VKEY_6          = '6',
  1357.   VKEY_7          = '7',
  1358.   VKEY_8          = '8',
  1359.   VKEY_9          = '9',
  1360.   VKEY_COLON      = ':',
  1361.   VKEY_SEMICOLON  = ';',
  1362.   VKEY_LESS       = '<',
  1363.   VKEY_EQUALS     = '=',
  1364.   VKEY_GREATER    = '>',
  1365.   VKEY_QUESTION   = '?',
  1366.   VKEY_AT         = '@',
  1367.  
  1368.   /*
  1369.      Skip uppercase letters
  1370.    */
  1371.  
  1372.   VKEY_LEFTBRACKET  = '[',
  1373.   VKEY_BACKSLASH    = '\\',
  1374.   VKEY_RIGHTBRACKET = ']',
  1375.   VKEY_CARET        = '^',
  1376.   VKEY_UNDERSCORE   = '_',
  1377.   VKEY_BACKQUOTE    = '`',
  1378.   VKEY_a            = 'a',
  1379.   VKEY_b            = 'b',
  1380.   VKEY_c            = 'c',
  1381.   VKEY_d            = 'd',
  1382.   VKEY_e            = 'e',
  1383.   VKEY_f            = 'f',
  1384.   VKEY_g            = 'g',
  1385.   VKEY_h            = 'h',
  1386.   VKEY_i            = 'i',
  1387.   VKEY_j            = 'j',
  1388.   VKEY_k            = 'k',
  1389.   VKEY_l            = 'l',
  1390.   VKEY_m            = 'm',
  1391.   VKEY_n            = 'n',
  1392.   VKEY_o            = 'o',
  1393.   VKEY_p            = 'p',
  1394.   VKEY_q            = 'q',
  1395.   VKEY_r            = 'r',
  1396.   VKEY_s            = 's',
  1397.   VKEY_t            = 't',
  1398.   VKEY_u            = 'u',
  1399.   VKEY_v            = 'v',
  1400.   VKEY_w            = 'w',
  1401.   VKEY_x            = 'x',
  1402.   VKEY_y            = 'y',
  1403.   VKEY_z            = 'z',
  1404.  
  1405.   VKEY_CAPSLOCK = KIT_PKEY_TO_VKEY(PKEY_CAPSLOCK),
  1406.  
  1407.   VKEY_F1  = KIT_PKEY_TO_VKEY(PKEY_F1),
  1408.   VKEY_F2  = KIT_PKEY_TO_VKEY(PKEY_F2),
  1409.   VKEY_F3  = KIT_PKEY_TO_VKEY(PKEY_F3),
  1410.   VKEY_F4  = KIT_PKEY_TO_VKEY(PKEY_F4),
  1411.   VKEY_F5  = KIT_PKEY_TO_VKEY(PKEY_F5),
  1412.   VKEY_F6  = KIT_PKEY_TO_VKEY(PKEY_F6),
  1413.   VKEY_F7  = KIT_PKEY_TO_VKEY(PKEY_F7),
  1414.   VKEY_F8  = KIT_PKEY_TO_VKEY(PKEY_F8),
  1415.   VKEY_F9  = KIT_PKEY_TO_VKEY(PKEY_F9),
  1416.   VKEY_F10 = KIT_PKEY_TO_VKEY(PKEY_F10),
  1417.   VKEY_F11 = KIT_PKEY_TO_VKEY(PKEY_F11),
  1418.   VKEY_F12 = KIT_PKEY_TO_VKEY(PKEY_F12),
  1419.  
  1420.   VKEY_PRINTSCREEN = KIT_PKEY_TO_VKEY(PKEY_PRINTSCREEN),
  1421.   VKEY_SCROLLLOCK  = KIT_PKEY_TO_VKEY(PKEY_SCROLLLOCK),
  1422.   VKEY_PAUSE       = KIT_PKEY_TO_VKEY(PKEY_PAUSE),
  1423.   VKEY_INSERT      = KIT_PKEY_TO_VKEY(PKEY_INSERT),
  1424.   VKEY_HOME        = KIT_PKEY_TO_VKEY(PKEY_HOME),
  1425.   VKEY_PAGEUP      = KIT_PKEY_TO_VKEY(PKEY_PAGEUP),
  1426.   VKEY_DELETE      = '\x7F',
  1427.   VKEY_END         = KIT_PKEY_TO_VKEY(PKEY_END),
  1428.   VKEY_PAGEDOWN    = KIT_PKEY_TO_VKEY(PKEY_PAGEDOWN),
  1429.   VKEY_RIGHT       = KIT_PKEY_TO_VKEY(PKEY_RIGHT),
  1430.   VKEY_LEFT        = KIT_PKEY_TO_VKEY(PKEY_LEFT),
  1431.   VKEY_DOWN        = KIT_PKEY_TO_VKEY(PKEY_DOWN),
  1432.   VKEY_UP          = KIT_PKEY_TO_VKEY(PKEY_UP),
  1433.  
  1434.   VKEY_NUMLOCKCLEAR = KIT_PKEY_TO_VKEY(PKEY_NUMLOCKCLEAR),
  1435.   VKEY_KP_DIVIDE    = KIT_PKEY_TO_VKEY(PKEY_KP_DIVIDE),
  1436.   VKEY_KP_MULTIPLY  = KIT_PKEY_TO_VKEY(PKEY_KP_MULTIPLY),
  1437.   VKEY_KP_MINUS     = KIT_PKEY_TO_VKEY(PKEY_KP_MINUS),
  1438.   VKEY_KP_PLUS      = KIT_PKEY_TO_VKEY(PKEY_KP_PLUS),
  1439.   VKEY_KP_ENTER     = KIT_PKEY_TO_VKEY(PKEY_KP_ENTER),
  1440.   VKEY_KP_1         = KIT_PKEY_TO_VKEY(PKEY_KP_1),
  1441.   VKEY_KP_2         = KIT_PKEY_TO_VKEY(PKEY_KP_2),
  1442.   VKEY_KP_3         = KIT_PKEY_TO_VKEY(PKEY_KP_3),
  1443.   VKEY_KP_4         = KIT_PKEY_TO_VKEY(PKEY_KP_4),
  1444.   VKEY_KP_5         = KIT_PKEY_TO_VKEY(PKEY_KP_5),
  1445.   VKEY_KP_6         = KIT_PKEY_TO_VKEY(PKEY_KP_6),
  1446.   VKEY_KP_7         = KIT_PKEY_TO_VKEY(PKEY_KP_7),
  1447.   VKEY_KP_8         = KIT_PKEY_TO_VKEY(PKEY_KP_8),
  1448.   VKEY_KP_9         = KIT_PKEY_TO_VKEY(PKEY_KP_9),
  1449.   VKEY_KP_0         = KIT_PKEY_TO_VKEY(PKEY_KP_0),
  1450.   VKEY_KP_PERIOD    = KIT_PKEY_TO_VKEY(PKEY_KP_PERIOD),
  1451.  
  1452.   VKEY_APPLICATION    = KIT_PKEY_TO_VKEY(PKEY_APPLICATION),
  1453.   VKEY_POWER          = KIT_PKEY_TO_VKEY(PKEY_POWER),
  1454.   VKEY_KP_EQUALS      = KIT_PKEY_TO_VKEY(PKEY_KP_EQUALS),
  1455.   VKEY_F13            = KIT_PKEY_TO_VKEY(PKEY_F13),
  1456.   VKEY_F14            = KIT_PKEY_TO_VKEY(PKEY_F14),
  1457.   VKEY_F15            = KIT_PKEY_TO_VKEY(PKEY_F15),
  1458.   VKEY_F16            = KIT_PKEY_TO_VKEY(PKEY_F16),
  1459.   VKEY_F17            = KIT_PKEY_TO_VKEY(PKEY_F17),
  1460.   VKEY_F18            = KIT_PKEY_TO_VKEY(PKEY_F18),
  1461.   VKEY_F19            = KIT_PKEY_TO_VKEY(PKEY_F19),
  1462.   VKEY_F20            = KIT_PKEY_TO_VKEY(PKEY_F20),
  1463.   VKEY_F21            = KIT_PKEY_TO_VKEY(PKEY_F21),
  1464.   VKEY_F22            = KIT_PKEY_TO_VKEY(PKEY_F22),
  1465.   VKEY_F23            = KIT_PKEY_TO_VKEY(PKEY_F23),
  1466.   VKEY_F24            = KIT_PKEY_TO_VKEY(PKEY_F24),
  1467.   VKEY_EXECUTE        = KIT_PKEY_TO_VKEY(PKEY_EXECUTE),
  1468.   VKEY_HELP           = KIT_PKEY_TO_VKEY(PKEY_HELP),
  1469.   VKEY_MENU           = KIT_PKEY_TO_VKEY(PKEY_MENU),
  1470.   VKEY_SELECT         = KIT_PKEY_TO_VKEY(PKEY_SELECT),
  1471.   VKEY_STOP           = KIT_PKEY_TO_VKEY(PKEY_STOP),
  1472.   VKEY_AGAIN          = KIT_PKEY_TO_VKEY(PKEY_AGAIN),
  1473.   VKEY_UNDO           = KIT_PKEY_TO_VKEY(PKEY_UNDO),
  1474.   VKEY_CUT            = KIT_PKEY_TO_VKEY(PKEY_CUT),
  1475.   VKEY_COPY           = KIT_PKEY_TO_VKEY(PKEY_COPY),
  1476.   VKEY_PASTE          = KIT_PKEY_TO_VKEY(PKEY_PASTE),
  1477.   VKEY_FIND           = KIT_PKEY_TO_VKEY(PKEY_FIND),
  1478.   VKEY_MUTE           = KIT_PKEY_TO_VKEY(PKEY_MUTE),
  1479.   VKEY_VOLUMEUP       = KIT_PKEY_TO_VKEY(PKEY_VOLUMEUP),
  1480.   VKEY_VOLUMEDOWN     = KIT_PKEY_TO_VKEY(PKEY_VOLUMEDOWN),
  1481.   VKEY_KP_COMMA       = KIT_PKEY_TO_VKEY(PKEY_KP_COMMA),
  1482.   VKEY_KP_EQUALSAS400 = KIT_PKEY_TO_VKEY(PKEY_KP_EQUALSAS400),
  1483.  
  1484.   VKEY_ALTERASE   = KIT_PKEY_TO_VKEY(PKEY_ALTERASE),
  1485.   VKEY_SYSREQ     = KIT_PKEY_TO_VKEY(PKEY_SYSREQ),
  1486.   VKEY_CANCEL     = KIT_PKEY_TO_VKEY(PKEY_CANCEL),
  1487.   VKEY_CLEAR      = KIT_PKEY_TO_VKEY(PKEY_CLEAR),
  1488.   VKEY_PRIOR      = KIT_PKEY_TO_VKEY(PKEY_PRIOR),
  1489.   VKEY_RETURN2    = KIT_PKEY_TO_VKEY(PKEY_RETURN2),
  1490.   VKEY_SEPARATOR  = KIT_PKEY_TO_VKEY(PKEY_SEPARATOR),
  1491.   VKEY_OUT        = KIT_PKEY_TO_VKEY(PKEY_OUT),
  1492.   VKEY_OPER       = KIT_PKEY_TO_VKEY(PKEY_OPER),
  1493.   VKEY_CLEARAGAIN = KIT_PKEY_TO_VKEY(PKEY_CLEARAGAIN),
  1494.   VKEY_CRSEL      = KIT_PKEY_TO_VKEY(PKEY_CRSEL),
  1495.   VKEY_EXSEL      = KIT_PKEY_TO_VKEY(PKEY_EXSEL),
  1496.  
  1497.   VKEY_KP_00              = KIT_PKEY_TO_VKEY(PKEY_KP_00),
  1498.   VKEY_KP_000             = KIT_PKEY_TO_VKEY(PKEY_KP_000),
  1499.   VKEY_THOUSANDSSEPARATOR = KIT_PKEY_TO_VKEY(PKEY_THOUSANDSSEPARATOR),
  1500.   VKEY_DECIMALSEPARATOR   = KIT_PKEY_TO_VKEY(PKEY_DECIMALSEPARATOR),
  1501.   VKEY_CURRENCYUNIT       = KIT_PKEY_TO_VKEY(PKEY_CURRENCYUNIT),
  1502.   VKEY_CURRENCYSUBUNIT    = KIT_PKEY_TO_VKEY(PKEY_CURRENCYSUBUNIT),
  1503.   VKEY_KP_LEFTPAREN       = KIT_PKEY_TO_VKEY(PKEY_KP_LEFTPAREN),
  1504.   VKEY_KP_RIGHTPAREN      = KIT_PKEY_TO_VKEY(PKEY_KP_RIGHTPAREN),
  1505.   VKEY_KP_LEFTBRACE       = KIT_PKEY_TO_VKEY(PKEY_KP_LEFTBRACE),
  1506.   VKEY_KP_RIGHTBRACE      = KIT_PKEY_TO_VKEY(PKEY_KP_RIGHTBRACE),
  1507.   VKEY_KP_TAB             = KIT_PKEY_TO_VKEY(PKEY_KP_TAB),
  1508.   VKEY_KP_BACKSPACE       = KIT_PKEY_TO_VKEY(PKEY_KP_BACKSPACE),
  1509.   VKEY_KP_A               = KIT_PKEY_TO_VKEY(PKEY_KP_A),
  1510.   VKEY_KP_B               = KIT_PKEY_TO_VKEY(PKEY_KP_B),
  1511.   VKEY_KP_C               = KIT_PKEY_TO_VKEY(PKEY_KP_C),
  1512.   VKEY_KP_D               = KIT_PKEY_TO_VKEY(PKEY_KP_D),
  1513.   VKEY_KP_E               = KIT_PKEY_TO_VKEY(PKEY_KP_E),
  1514.   VKEY_KP_F               = KIT_PKEY_TO_VKEY(PKEY_KP_F),
  1515.   VKEY_KP_XOR             = KIT_PKEY_TO_VKEY(PKEY_KP_XOR),
  1516.   VKEY_KP_POWER           = KIT_PKEY_TO_VKEY(PKEY_KP_POWER),
  1517.   VKEY_KP_PERCENT         = KIT_PKEY_TO_VKEY(PKEY_KP_PERCENT),
  1518.   VKEY_KP_LESS            = KIT_PKEY_TO_VKEY(PKEY_KP_LESS),
  1519.   VKEY_KP_GREATER         = KIT_PKEY_TO_VKEY(PKEY_KP_GREATER),
  1520.   VKEY_KP_AMPERSAND       = KIT_PKEY_TO_VKEY(PKEY_KP_AMPERSAND),
  1521.   VKEY_KP_DBLAMPERSAND    = KIT_PKEY_TO_VKEY(PKEY_KP_DBLAMPERSAND),
  1522.   VKEY_KP_VERTICALBAR     = KIT_PKEY_TO_VKEY(PKEY_KP_VERTICALBAR),
  1523.   VKEY_KP_DBLVERTICALBAR  = KIT_PKEY_TO_VKEY(PKEY_KP_DBLVERTICALBAR),
  1524.   VKEY_KP_COLON           = KIT_PKEY_TO_VKEY(PKEY_KP_COLON),
  1525.   VKEY_KP_HASH            = KIT_PKEY_TO_VKEY(PKEY_KP_HASH),
  1526.   VKEY_KP_SPACE           = KIT_PKEY_TO_VKEY(PKEY_KP_SPACE),
  1527.   VKEY_KP_AT              = KIT_PKEY_TO_VKEY(PKEY_KP_AT),
  1528.   VKEY_KP_EXCLAM          = KIT_PKEY_TO_VKEY(PKEY_KP_EXCLAM),
  1529.   VKEY_KP_MEMSTORE        = KIT_PKEY_TO_VKEY(PKEY_KP_MEMSTORE),
  1530.   VKEY_KP_MEMRECALL       = KIT_PKEY_TO_VKEY(PKEY_KP_MEMRECALL),
  1531.   VKEY_KP_MEMCLEAR        = KIT_PKEY_TO_VKEY(PKEY_KP_MEMCLEAR),
  1532.   VKEY_KP_MEMADD          = KIT_PKEY_TO_VKEY(PKEY_KP_MEMADD),
  1533.   VKEY_KP_MEMSUBTRACT     = KIT_PKEY_TO_VKEY(PKEY_KP_MEMSUBTRACT),
  1534.   VKEY_KP_MEMMULTIPLY     = KIT_PKEY_TO_VKEY(PKEY_KP_MEMMULTIPLY),
  1535.   VKEY_KP_MEMDIVIDE       = KIT_PKEY_TO_VKEY(PKEY_KP_MEMDIVIDE),
  1536.   VKEY_KP_PLUSMINUS       = KIT_PKEY_TO_VKEY(PKEY_KP_PLUSMINUS),
  1537.   VKEY_KP_CLEAR           = KIT_PKEY_TO_VKEY(PKEY_KP_CLEAR),
  1538.   VKEY_KP_CLEARENTRY      = KIT_PKEY_TO_VKEY(PKEY_KP_CLEARENTRY),
  1539.   VKEY_KP_BINARY          = KIT_PKEY_TO_VKEY(PKEY_KP_BINARY),
  1540.   VKEY_KP_OCTAL           = KIT_PKEY_TO_VKEY(PKEY_KP_OCTAL),
  1541.   VKEY_KP_DECIMAL         = KIT_PKEY_TO_VKEY(PKEY_KP_DECIMAL),
  1542.   VKEY_KP_HEXADECIMAL     = KIT_PKEY_TO_VKEY(PKEY_KP_HEXADECIMAL),
  1543.  
  1544.   VKEY_LCTRL  = KIT_PKEY_TO_VKEY(PKEY_LCTRL),
  1545.   VKEY_LSHIFT = KIT_PKEY_TO_VKEY(PKEY_LSHIFT),
  1546.   VKEY_LALT   = KIT_PKEY_TO_VKEY(PKEY_LALT),
  1547.   VKEY_LGUI   = KIT_PKEY_TO_VKEY(PKEY_LGUI),
  1548.   VKEY_RCTRL  = KIT_PKEY_TO_VKEY(PKEY_RCTRL),
  1549.   VKEY_RSHIFT = KIT_PKEY_TO_VKEY(PKEY_RSHIFT),
  1550.   VKEY_RALT   = KIT_PKEY_TO_VKEY(PKEY_RALT),
  1551.   VKEY_RGUI   = KIT_PKEY_TO_VKEY(PKEY_RGUI),
  1552.  
  1553.   VKEY_MODE = KIT_PKEY_TO_VKEY(PKEY_MODE),
  1554.  
  1555.   VKEY_AUDIONEXT    = KIT_PKEY_TO_VKEY(PKEY_AUDIONEXT),
  1556.   VKEY_AUDIOPREV    = KIT_PKEY_TO_VKEY(PKEY_AUDIOPREV),
  1557.   VKEY_AUDIOSTOP    = KIT_PKEY_TO_VKEY(PKEY_AUDIOSTOP),
  1558.   VKEY_AUDIOPLAY    = KIT_PKEY_TO_VKEY(PKEY_AUDIOPLAY),
  1559.   VKEY_AUDIOMUTE    = KIT_PKEY_TO_VKEY(PKEY_AUDIOMUTE),
  1560.   VKEY_MEDIASELECT  = KIT_PKEY_TO_VKEY(PKEY_MEDIASELECT),
  1561.   VKEY_WWW          = KIT_PKEY_TO_VKEY(PKEY_WWW),
  1562.   VKEY_MAIL         = KIT_PKEY_TO_VKEY(PKEY_MAIL),
  1563.   VKEY_CALCULATOR   = KIT_PKEY_TO_VKEY(PKEY_CALCULATOR),
  1564.   VKEY_COMPUTER     = KIT_PKEY_TO_VKEY(PKEY_COMPUTER),
  1565.   VKEY_AC_SEARCH    = KIT_PKEY_TO_VKEY(PKEY_AC_SEARCH),
  1566.   VKEY_AC_HOME      = KIT_PKEY_TO_VKEY(PKEY_AC_HOME),
  1567.   VKEY_AC_BACK      = KIT_PKEY_TO_VKEY(PKEY_AC_BACK),
  1568.   VKEY_AC_FORWARD   = KIT_PKEY_TO_VKEY(PKEY_AC_FORWARD),
  1569.   VKEY_AC_STOP      = KIT_PKEY_TO_VKEY(PKEY_AC_STOP),
  1570.   VKEY_AC_REFRESH   = KIT_PKEY_TO_VKEY(PKEY_AC_REFRESH),
  1571.   VKEY_AC_BOOKMARKS = KIT_PKEY_TO_VKEY(PKEY_AC_BOOKMARKS),
  1572.  
  1573.   VKEY_BRIGHTNESSDOWN = KIT_PKEY_TO_VKEY(PKEY_BRIGHTNESSDOWN),
  1574.   VKEY_BRIGHTNESSUP   = KIT_PKEY_TO_VKEY(PKEY_BRIGHTNESSUP),
  1575.   VKEY_DISPLAYSWITCH  = KIT_PKEY_TO_VKEY(PKEY_DISPLAYSWITCH),
  1576.   VKEY_KBDILLUMTOGGLE = KIT_PKEY_TO_VKEY(PKEY_KBDILLUMTOGGLE),
  1577.   VKEY_KBDILLUMDOWN   = KIT_PKEY_TO_VKEY(PKEY_KBDILLUMDOWN),
  1578.   VKEY_KBDILLUMUP     = KIT_PKEY_TO_VKEY(PKEY_KBDILLUMUP),
  1579.   VKEY_EJECT          = KIT_PKEY_TO_VKEY(PKEY_EJECT),
  1580.   VKEY_SLEEP          = KIT_PKEY_TO_VKEY(PKEY_SLEEP),
  1581.   VKEY_APP1           = KIT_PKEY_TO_VKEY(PKEY_APP1),
  1582.   VKEY_APP2           = KIT_PKEY_TO_VKEY(PKEY_APP2),
  1583.  
  1584.   VKEY_AUDIOREWIND      = KIT_PKEY_TO_VKEY(PKEY_AUDIOREWIND),
  1585.   VKEY_AUDIOFASTFORWARD = KIT_PKEY_TO_VKEY(PKEY_AUDIOFASTFORWARD),
  1586.  
  1587.   VKEY_SOFTLEFT  = KIT_PKEY_TO_VKEY(PKEY_SOFTLEFT),
  1588.   VKEY_SOFTRIGHT = KIT_PKEY_TO_VKEY(PKEY_SOFTRIGHT),
  1589.   VKEY_CALL      = KIT_PKEY_TO_VKEY(PKEY_CALL),
  1590.   VKEY_ENDCALL   = KIT_PKEY_TO_VKEY(PKEY_ENDCALL),
  1591. };
  1592.  
  1593.  
  1594. enum Event_Key_ModifierFlagsEnum {
  1595.   KEYMOD_NONE   = 0x0000,
  1596.   KEYMOD_LSHIFT = 0x0001,
  1597.   KEYMOD_RSHIFT = 0x0002,
  1598.   //(4 bits are skipped here)
  1599.   KEYMOD_LCTRL  = 0x0040,
  1600.   KEYMOD_RCTRL  = 0x0080,
  1601.   KEYMOD_LALT   = 0x0100,
  1602.   KEYMOD_RALT   = 0x0200,
  1603.   KEYMOD_LGUI   = 0x0400,
  1604.   KEYMOD_RGUI   = 0x0800,
  1605.     KEYMOD_LWIN = KEYMOD_LGUI,
  1606.     KEYMOD_RWIN = KEYMOD_RGUI,
  1607.   KEYMOD_NUM    = 0x1000, //num lock
  1608.   KEYMOD_CAPS   = 0x2000, //caps lock
  1609.   KEYMOD_MODE   = 0x4000, //altgraph
  1610.   KEYMOD_SCROLL = 0x8000, //scroll lock
  1611.  
  1612.   KEYMOD_CTRL  = ( KEYMOD_LCTRL  | KEYMOD_RCTRL  ),
  1613.   KEYMOD_SHIFT = ( KEYMOD_LSHIFT | KEYMOD_RSHIFT ),
  1614.   KEYMOD_ALT   = ( KEYMOD_LALT   | KEYMOD_RALT   ),
  1615.   KEYMOD_GUI   = ( KEYMOD_LGUI   | KEYMOD_RGUI   ),
  1616.   KEYMOD_WIN   = ( KEYMOD_LWIN   | KEYMOD_RWIN   ),
  1617. };
  1618.  
  1619.  
  1620. union Event_Key_Mod { //2B
  1621.   struct {
  1622.     //low byte
  1623.     u16 lshift  : 1;
  1624.     u16 rshift  : 1;
  1625.     u16 _unused : 4;
  1626.     u16 lctrl   : 1;
  1627.     u16 rctrl   : 1;
  1628.     //high byte
  1629.     u16 lalt    : 1;
  1630.     u16 ralt    : 1;
  1631.     u16 lgui    : 1;
  1632.     u16 rgui    : 1;
  1633.     u16 num     : 1;
  1634.     u16 caps    : 1;
  1635.     u16 mode    : 1;
  1636.     u16 scroll  : 1;
  1637.   };
  1638.   u16 all;
  1639. };
  1640.  
  1641.  
  1642. struct Event_Key_Sym { //8B
  1643.   s32 vkey; //virtual key code
  1644.   u16 pkey; //physical key code (scancode)
  1645.   union {   //some combination of Event_Key_ModifiersEnum flags (if any)
  1646.     u16 kmods;
  1647.     Event_Key_Mod kmod;
  1648.   };
  1649. };
  1650.  
  1651.  
  1652. struct Event_Key { //24B
  1653.   u32  type;
  1654.   u32  timestamp;
  1655.   u32  window;  //window with keyboard focus, if any
  1656.   bool pressed; //key was released otherwise
  1657.   bool repeat;  //'is this the result of holding a key down?' (useful for text input!)
  1658.   u16 _padding16;
  1659.   union {
  1660.  
  1661.     struct {
  1662.       s32 vkey;  //virtual key code
  1663.       u16 pkey;  //physical key code (scancode)
  1664.       u16 kmods; //some combination of Event_Key_ModifiersEnum flags (if any)
  1665.     };
  1666.  
  1667.     Event_Key_Sym sym;
  1668.  
  1669.   };
  1670. };
  1671.  
  1672. /*-KEVENT_KEY-*/
  1673.  
  1674.  
  1675.  
  1676.  
  1677.  
  1678. /*+KEVENT_MOUSE+*/
  1679.  
  1680. //for KEVENT_MOUSE_MOVED events, multiple of these
  1681.  //flags can be active simultaneously, whereas
  1682.  //for MOUSE_UP/DOWN events, only <=1 can be set
  1683. enum Event_Mouse_ButtonFlagsEnum {
  1684.   MOUSE_BUTTON_LEFT   = 0x01,
  1685.   MOUSE_BUTTON_MIDDLE = 0x02,
  1686.   MOUSE_BUTTON_RIGHT  = 0x04,
  1687.   MOUSE_BUTTON_X1     = 0x08,
  1688.   MOUSE_BUTTON_X2     = 0x10,
  1689. };
  1690.  
  1691.  
  1692. //(internal note: mouse instance IDs are ignored)
  1693. struct Event_Mouse { //40B
  1694.   u32  type;
  1695.   u32  timestamp;
  1696.   u32  window;   //current window with mouse focus, if any
  1697.   u8   button;   //which mouse button(s) are pressed (see Event_Mouse_ButtonFlagsEnum)
  1698.   bool pressed;  //otherwise button was released
  1699.   bool dblClick; //'is double click?' (single click otherwise);
  1700.   bool flipped;  //indicates whether x or y are flipped during mouse wheel events (*=-1 to flip back)
  1701.   s32   x,   y;  //coordinates, relative to window
  1702.   s32  dx,  dy;  //delta x&y (coordinates relative to last recorded position)
  1703.   f32 pdx, pdy;  //precise delta x&y (only set by MOUSE_WHEEL events)
  1704. };
  1705.  
  1706. /*-KEVENT_MOUSE-*/
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712. /*+KEVENT_JOY+*/
  1713.  
  1714. enum Event_Joystick_BatteryEnum {
  1715.   JOY_BATTERY_UNKNOWN = -1,
  1716.   JOY_BATTERY_EMPTY,  // <= 5%
  1717.   JOY_BATTERY_LOW,    // <= 20%
  1718.   JOY_BATTERY_MEDIUM, // <= 70%
  1719.   JOY_BATTERY_FULL,   // <= 100%
  1720.   JOY_BATTERY_WIRED,
  1721.   JOY_BATTERY_MAX,
  1722. };
  1723.  
  1724. enum Event_Joystick_HatEnum {
  1725.   JOY_HAT_CENTERED  = 0x00,
  1726.   JOY_HAT_UP        = 0x01,
  1727.   JOY_HAT_RIGHT     = 0x02,
  1728.   JOY_HAT_DOWN      = 0x04,
  1729.   JOY_HAT_LEFT      = 0x08,
  1730.  
  1731.   JOY_HAT_RIGHTUP   = (JOY_HAT_RIGHT|JOY_HAT_UP  ),
  1732.   JOY_HAT_RIGHTDOWN = (JOY_HAT_RIGHT|JOY_HAT_DOWN),
  1733.   JOY_HAT_LEFTUP    = (JOY_HAT_LEFT |JOY_HAT_UP  ),
  1734.   JOY_HAT_LEFTDOWN  = (JOY_HAT_LEFT |JOY_HAT_DOWN),
  1735. };
  1736.  
  1737.  
  1738. struct Event_Joystick_Axis { //4B
  1739.   u8  which;
  1740.   u8 _padding8;
  1741.   s16 value;
  1742. } __attribute__((packed));
  1743.  
  1744. struct Event_Joystick_Trackball { //12B
  1745.   u8   which;
  1746.   u8  _padding8;
  1747.   s16  dx, dy;    //movement delta
  1748.   u16 _padding16; //(extra explicit padding added, since
  1749.   u32 _padding32;  //trackball is the largest subevent)
  1750. } __attribute__((packed));
  1751.  
  1752. struct Event_Joystick_Hat { //2B
  1753.   u8 which;
  1754.   u8 value; //see Event_Joystick_HatEnum
  1755. } __attribute__((packed));
  1756.  
  1757. struct Event_Joystick_Button { //2B
  1758.   u8   which;
  1759.   bool pressed;
  1760. } __attribute__((packed));
  1761.  
  1762. struct Event_Joystick_Device { //2B
  1763.   u8 _padding8;
  1764.   bool added; //device was removed if false
  1765. } __attribute__((packed));
  1766.  
  1767. struct Event_Joystick_Battery { //2B
  1768.   u8 _padding8;
  1769.   s8 level; //see Event_Joystick_BatteryEnum
  1770. } __attribute__((packed));
  1771.  
  1772.  
  1773. struct Event_Joystick { //24B
  1774.   u32 type;
  1775.   u32 timestamp;
  1776.   u32 id; //associated joystick instance
  1777.   union {
  1778.     Event_Joystick_Axis      axis;      // 4B
  1779.     Event_Joystick_Trackball trackball; //12B
  1780.     Event_Joystick_Hat       hat;       // 2B
  1781.     Event_Joystick_Button    button;    // 2B
  1782.     Event_Joystick_Device    device;    // 2B; redundant, but included for consistency
  1783.     Event_Joystick_Battery   battery;   // 2B
  1784.   };
  1785. };
  1786.  
  1787. /*-KEVENT_JOY-*/
  1788.  
  1789.  
  1790.  
  1791.  
  1792.  
  1793. /*+KEVENT_CTLR+*/
  1794.  
  1795. enum Event_GameController_AxisEnum {
  1796.   CTLR_AXIS_INVALID = -1,
  1797.   CTLR_AXIS_LEFTX,
  1798.   CTLR_AXIS_LEFTY,
  1799.   CTLR_AXIS_RIGHTX,
  1800.   CTLR_AXIS_RIGHTY,
  1801.   CTLR_AXIS_TRIGGERLEFT,
  1802.   CTLR_AXIS_TRIGGERRIGHT,
  1803.   CTLR_AXIS_MAX,
  1804. };
  1805.  
  1806. enum Event_GameController_ButtonEnum {
  1807.   CTLR_BUTTON_INVALID = -1,
  1808.   CTLR_BUTTON_A,
  1809.   CTLR_BUTTON_B,
  1810.   CTLR_BUTTON_X,
  1811.   CTLR_BUTTON_Y,
  1812.   CTLR_BUTTON_BACK,
  1813.   CTLR_BUTTON_GUIDE,
  1814.   CTLR_BUTTON_START,
  1815.   CTLR_BUTTON_LEFTSTICK,
  1816.   CTLR_BUTTON_RIGHTSTICK,
  1817.   CTLR_BUTTON_LEFTSHOULDER,
  1818.   CTLR_BUTTON_RIGHTSHOULDER,
  1819.   CTLR_BUTTON_DPAD_UP,
  1820.   CTLR_BUTTON_DPAD_DOWN,
  1821.   CTLR_BUTTON_DPAD_LEFT,
  1822.   CTLR_BUTTON_DPAD_RIGHT,
  1823.   CTLR_BUTTON_MISC1,    //Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button
  1824.   CTLR_BUTTON_PADDLE1,  //Xbox Elite paddle P1 (upper left,  facing the back)
  1825.   CTLR_BUTTON_PADDLE2,  //Xbox Elite paddle P3 (upper right, facing the back)
  1826.   CTLR_BUTTON_PADDLE3,  //Xbox Elite paddle P2 (lower left,  facing the back)
  1827.   CTLR_BUTTON_PADDLE4,  //Xbox Elite paddle P4 (lower right, facing the back)
  1828.   CTLR_BUTTON_TOUCHPAD, //PS4/PS5 touchpad button
  1829.   CTLR_BUTTON_MAX,
  1830. };
  1831.  
  1832. enum Event_GameController_SensorEnum {
  1833.   CTLR_SENSOR_INVALID = -1, //Returned for an invalid sensor
  1834.   CTLR_SENSOR_UNKNOWN,      //Unknown sensor type
  1835.   CTLR_SENSOR_ACCEL,        //Accelerometer
  1836.   CTLR_SENSOR_GYRO,         //Gyroscope
  1837.   CTLR_SENSOR_ACCEL_L,      //Accelerometer for left Joy-Con controller and Wii nunchuk
  1838.   CTLR_SENSOR_GYRO_L,       //Gyroscope for left Joy-Con controller
  1839.   CTLR_SENSOR_ACCEL_R,      //Accelerometer for right Joy-Con controller
  1840.   CTLR_SENSOR_GYRO_R,       //Gyroscope for right Joy-Con controller
  1841. };
  1842.  
  1843. /**
  1844.  * Accelerometer sensor
  1845.  *
  1846.  * The accelerometer returns the current acceleration in SI meters per
  1847.  * second squared. This measurement includes the force of gravity, so
  1848.  * a device at rest will have an value of KIT_STANDARD_GRAVITY away
  1849.  * from the center of the earth, which is a positive Y value.
  1850.  *
  1851.  * values[0]: Acceleration on the x axis
  1852.  * values[1]: Acceleration on the y axis
  1853.  * values[2]: Acceleration on the z axis
  1854.  *
  1855.  * For phones held in portrait mode and game controllers held in front of you,
  1856.  * the axes are defined as follows:
  1857.  * -X ... +X : left ... right
  1858.  * -Y ... +Y : bottom ... top
  1859.  * -Z ... +Z : farther ... closer
  1860.  *
  1861.  * The axis data is not changed when the phone is rotated.
  1862.  */
  1863. //#define SDL_STANDARD_GRAVITY    9.80665f
  1864. #define KIT_STANDARD_GRAVITY    9.80665f //for macro naming consistency
  1865.  
  1866. /**
  1867.  * Gyroscope sensor
  1868.  *
  1869.  * The gyroscope returns the current rate of rotation in radians per second.
  1870.  * The rotation is positive in the counter-clockwise direction. That is,
  1871.  * an observer looking from a positive location on one of the axes would
  1872.  * see positive rotation on that axis when it appeared to be rotating
  1873.  * counter-clockwise.
  1874.  *
  1875.  * values[0]: Angular speed around the x axis (pitch)
  1876.  * values[1]: Angular speed around the y axis (yaw)
  1877.  * values[2]: Angular speed around the z axis (roll)
  1878.  *
  1879.  * For phones held in portrait mode and game controllers held in front of you,
  1880.  * the axes are defined as follows:
  1881.  * -X ... +X : left ... right
  1882.  * -Y ... +Y : bottom ... top
  1883.  * -Z ... +Z : farther ... closer
  1884.  *
  1885.  * The axis data is not changed when the phone or controller is rotated.
  1886.  */
  1887.  
  1888.  
  1889. struct Event_GameController_Axis { //4B
  1890.   u8  which; //see Event_GameController_AxisEnum
  1891.   u8 _padding8;
  1892.   s16 value;
  1893. } __attribute__((packed));
  1894.  
  1895. struct Event_GameController_Button { //2B
  1896.   u8   which; //see Event_GameController_ButtonEnum
  1897.   bool pressed;
  1898. } __attribute__((packed));
  1899.  
  1900. struct Event_GameController_Device { //2B
  1901.   u16 subtype; //lower 16-bits of .type
  1902. } __attribute__((packed));
  1903.  
  1904. struct Event_GameController_Touchpad { //20B
  1905.   s32  which;
  1906.   s32  finger;
  1907.   f32  x, y; //from top-left going southeast, normalized; 0.0f -> 1.0f
  1908.   f32  pressure;
  1909. } __attribute__((packed));
  1910.  
  1911. struct Event_GameController_Sensor { //28B
  1912.   s32 which; //see Event_GameController_SensorEnum
  1913.   u32 _padding32;
  1914.   f32 data[3];
  1915.   u64 timestamp_us; //time at the point of sensor read, in microseconds
  1916.                      //(if the hardware provides that information)
  1917. } __attribute__((packed));
  1918.  
  1919.  
  1920. struct Event_GameController { //40B
  1921.   u32 type;
  1922.   u32 timestamp;
  1923.   s32 id; //joystick instance id (unless subtype is DEVICE_x)
  1924.   //^^ specifically for DEVICE_x:
  1925.   //   joy device index for ADDED, instance id for REMOVED/REMAPPED
  1926.   union {
  1927.     Event_GameController_Axis     axis;     // 4B
  1928.     Event_GameController_Button   button;   // 2B
  1929.     Event_GameController_Device   device;   // 2B; redundant, but included for consistency
  1930.     Event_GameController_Touchpad touchpad; //20B
  1931.     Event_GameController_Sensor   sensor;   //28B
  1932.   };
  1933. };
  1934.  
  1935. /*-KEVENT_CTLR-*/
  1936.  
  1937.  
  1938.  
  1939.  
  1940.  
  1941. /*+KEVENT_ADEV+*/
  1942.  
  1943. struct Event_AudioDevice { //16B
  1944.   u32  type;
  1945.   u32  timestamp;
  1946.   u32  id;
  1947.   bool isInput; //false = output/rendering, true = input/recording
  1948.   u8  _padding8;
  1949.   u16 _padding16;
  1950. };
  1951.  
  1952. /*-KEVENT_ADEV-*/
  1953.  
  1954.  
  1955.  
  1956.  
  1957.  
  1958. /*+KEVENT_DROP+*/
  1959.  
  1960. struct Event_Drop { //24B
  1961.   u32   type;
  1962.   u32   timestamp;
  1963.   u32   window;   //which window the file was dropped on, if any
  1964.   u32  _padding32;
  1965.   char* filePath; //should be freed with memory::free; nullptr on DROP_BEGIN/COMPLETE
  1966. };
  1967.  
  1968. /*-KEVENT_DROP-*/
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974. /*+KEVENT_QUIT+*/
  1975.  
  1976. struct Event_Quit { //8B
  1977.   u32 type;
  1978.   u32 timestamp;
  1979. };
  1980.  
  1981. /*-KEVENT_QUIT-*/
  1982.  
  1983.  
  1984.  
  1985.  
  1986.  
  1987. /*+KEVENT_USER+*/
  1988.  
  1989. struct Event_User { //24B
  1990.   u32   type;
  1991.   u32   timestamp;
  1992.   u32   window;
  1993.   s32   id;    //user-defined
  1994.   void* data1; //user-defined
  1995.   void* data2; //user-defined
  1996. };
  1997.  
  1998. /*-KEVENT_USER-*/
  1999.  
  2000.  
  2001.  
  2002.  
  2003.  
  2004. union Event { //<whatever the largest event is>B
  2005.   struct {
  2006.     u32                type;
  2007.     u32                timestamp;
  2008.   };
  2009.  
  2010.   Event_Common         common;  // 8B
  2011.   Event_Display        display; //16B
  2012.   Event_Window         win;     //24B
  2013.   Event_Key            key;     //24B
  2014.   Event_Mouse          mouse;   //40B
  2015.   Event_Joystick       joy;     //24B
  2016.   Event_GameController ctlr;    //40B
  2017.   Event_AudioDevice    adev;    //16B
  2018.   Event_Drop           drop;    //24B
  2019.   Event_Quit           quit;    // 8B
  2020.   Event_User           user;    //24B
  2021.  
  2022.   Event() : type(KEVENT_NULL) {}
  2023.  
  2024. };
  2025.  
  2026.  
  2027.  
  2028.  
  2029.  
  2030. }; /* namespace kit */
  2031.  
  2032. #endif /* _INC__MISC_EVENT_HPP */
  2033.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement