Kitomas

ksdl2 work for 2024-08-02 (4/5)

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