Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\src\kit_sdl2\_kit_private.cpp":
- #include "_kit_common.hpp"
- namespace kit {
- #define ERRORS_INVALID (_gl.errors == nullptr || _gl.errors_len == 0)
- #define LAST_INDEX ((_gl.errors_len>0) ? _gl.errors_len-1 : 0)
- //returns newest last index on success, or < 0 on failure of some kind
- static s64 _changeErrorsSize(s32 change){ //(change is in elements, not bytes)
- if(ERRORS_INVALID) return -1;
- if(change == 0 ) return LAST_INDEX;
- if(((s64)_gl.errors_len)+change <= 0) return -1;
- LOCK_GLOBALS();
- s64 last_index = -1;
- u32 _errors_len = _gl.errors_len + change;
- size_t _errors_size = sizeof(Error) * _errors_len;
- if(memory::realloc(&_gl.errors, _errors_size))
- {
- //if errors array grew, zero out any new memory
- //(this loop won't even start if _errors_len <= _gl.errors_len)
- for(u32 i = _gl.errors_len; i<_errors_len; ++i)
- _gl.errors[i]._0 = 0, _gl.errors[i]._1 = 0;
- _gl.errors_len = _errors_len;
- last_index = LAST_INDEX;
- }
- UNLOCK_GLOBALS();
- return last_index;
- }
- static char _errortext_default[] = "(FAILED TO ALLOCATE MEMORY FOR ERROR TEXT)";
- //push heap error
- //(this assumes only one error will exist per thread at any given time!)
- const char* _pushError(const char* errortext){
- if(ERRORS_INVALID ) return "(THREAD ERROR ARRAY IS NULLPTR)";
- if(errortext == nullptr) return "_pushError(): errortext = nullptr";
- LOCK_GLOBALS();
- //attempt to find an empty space inside already existing errors array
- u32 i = 0;
- for(; i<_gl.errors_len; ++i){
- if(_gl.errors[i]._txt == nullptr) break;
- }
- //if no empty space for an error was found,
- //attempt to grow errors by 1 element
- if(i == _gl.errors_len){
- s64 last_index = _changeErrorsSize(1);
- //if errors failed to change size, and/or last index is not empty
- if(last_index < 0 || _gl.errors[last_index]._txt != nullptr)
- i = KIT_U32_MAX; //indicates failure to find any empty space
- }
- char* _errortext = _errortext_default;
- //if valid index was found, copy error text to new string inside errors array
- if(i < KIT_U32_MAX){
- size_t errortext_len = strnLen(errortext);
- char* _errortext_tmp = (char*)memory::alloc(errortext_len+1);
- //(memory::set is unnecessary here, since all bytes are overwritten anyway)
- if(_errortext_tmp != nullptr){
- _errortext = _errortext_tmp;
- //strcpy basically
- for(size_t c=0; c<errortext_len; ++c)
- _errortext[c] = errortext[c];
- _errortext[errortext_len] = 0; //manually add null terminator
- //set members of new error accordingly
- _gl.errors[i]._txt = _errortext;
- _gl.errors[i]._thread_id = SDL_GetThreadID(nullptr); //error belongs to calling thread
- _gl.errors[i]._heap = true;
- }
- }
- UNLOCK_GLOBALS();
- return (const char*)_errortext;
- }
- void _freeError(u32 thread_id){
- if(ERRORS_INVALID) return;
- if(!thread_id) thread_id = SDL_GetThreadID(nullptr); //id of calling thread
- LOCK_GLOBALS();
- //try to find error based on its thread id
- u32 i = 0;
- for(; i<_gl.errors_len; ++i){
- if(_gl.errors[i]._thread_id == thread_id){
- if(_gl.errors[i]._txt != nullptr && _gl.errors[i]._heap)
- memory::free(&_gl.errors[i]._txt);
- _gl.errors[i]._txt = nullptr;
- _gl.errors[i]._thread_id = 0;
- _gl.errors[i]._heap = false;
- break; //thread error found; break loop
- }
- }
- //shrink errors if the last error is now empty
- if(_gl.errors[_gl.errors_len-1]._txt == nullptr)
- _changeErrorsSize(-1);
- UNLOCK_GLOBALS();
- }
- void _freeErrors(){
- //(ERRORS_INVALID is not used here)
- if(_gl.errors == nullptr) return;
- LOCK_GLOBALS();
- for(u32 i=0; i<_gl.errors_len; ++i){
- if(_gl.errors[i]._txt != nullptr && _gl.errors[i]._heap)
- memory::free(&_gl.errors[i]._txt); //automatically sets _txt to nullptr
- }
- memory::free(&_gl.errors);
- _gl.errors_len = 0;
- UNLOCK_GLOBALS();
- }
- }; /* namespace kit */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\include\kit\all.hpp":
- //THIS LIBRARY WAS MADE TO USE SDL2 VERSION 2.28.2
- #ifndef _INC_ALL_HPP
- #define _INC_ALL_HPP
- #include "commondef.hpp"
- #include "misc.hpp"
- #include "video.hpp"
- #include "audio.hpp"
- #endif /* _INC_ALL_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\include\kit\audio.hpp":
- //THIS LIBRARY WAS MADE TO USE SDL2 VERSION 2.28.2
- #ifndef _INC_AUDIO_HPP
- #define _INC_AUDIO_HPP
- #include "commondef.hpp"
- #include "_audio_types.hpp"
- #include "_audio_func.hpp"
- #include "_audio_AudioDevice.hpp"
- #endif /* _INC_AUDIO_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\include\kit\commondef.hpp":
- //THIS LIBRARY WAS MADE TO USE SDL2 VERSION 2.28.2
- #ifndef _COMMONDEF_HPP
- #define _COMMONDEF_HPP
- namespace kit {
- #ifndef MIN
- #define MIN(a,b) ( ((a)<(b)) ? (a) : (b) )
- #endif /* MIN(a,b) */
- #ifndef MAX
- #define MAX(a,b) ( ((a)>(b)) ? (a) : (b) )
- #endif /* MAX(a,b) */
- #ifndef CLAMP
- #define CLAMP(n, mn, mx) MIN(MAX(n,mn),mx)
- #endif /* CLAMP(n, mn, mx) */
- //precise version
- #ifndef LERP
- #define LERP(_v0, _v1, _t) ( (1.0f-(_t)) * (_v0) + (_t) * (_v1) )
- #endif /* LERP */
- //imprecise version
- #ifndef LERP2
- #define LERP2(_v0, _v1, _t) ( (_v0) + (_t) * ((_v1)-(_v0)) )
- #endif /* LERP2 */
- //creates an ABGR color in the form of a u32, not color::ABGR
- #ifndef ABGR_U32
- #define ABGR_U32(_r,_g,_b,_a) (\
- ((kit::u32)(_a)<<24) | ((kit::u32)(_b)<<16) |\
- ((kit::u32)(_g)<< 8) | ((kit::u32)(_r) ) )
- #endif /* ABGR_U32 */
- //creates an ARGB color in the form of a u32, not color::ARGB
- #ifndef ARGB_U32
- #define ARGB_U32(_r,_g,_b,_a) (\
- ((kit::u32)(_a)<<24) | ((kit::u32)(_r)<<16) |\
- ((kit::u32)(_g)<< 8) | ((kit::u32)(_b) ) )
- #endif /* ABGR_U32 */
- #ifndef NULLDELETE
- #define NULLDELETE(_ptr_to_thing) { delete _ptr_to_thing; _ptr_to_thing = nullptr; }
- #endif /* NULLDELETE */
- #ifndef PTR_OFFSET
- #define PTR_OFFSET(_ptr, _offset, _type) ( \
- (_type*)( ((kit::u64)(_ptr)) + ((kit::s64)(_offset)) ) )
- #endif /* PTR_OFFSET */
- #ifndef PTR_OFFSETB
- #define PTR_OFFSETB(_ptr, _offset, _type) ( \
- (_type*)( ((kit::u64)(_ptr)) + ((kit::s64)(_offset)*sizeof(_type)) ) )
- #endif /* PTR_OFFSETB */
- // integer bounds
- #define KIT_U8_MAX (0xFF)
- #define KIT_U16_MAX (0xFFFF)
- #define KIT_U32_MAX (0xFFFFFFFF)
- #define KIT_U64_MAX (0xFFFFFFFFFFFFFFFF)
- //
- #define KIT_S8_MIN (0x80)
- #define KIT_S8_MAX (0x7F)
- #define KIT_S16_MIN (0x8000)
- #define KIT_S16_MAX (0x7FFF)
- #define KIT_S32_MIN (0x80000000)
- #define KIT_S32_MAX (0x7FFFFFFF)
- #define KIT_S64_MIN (0x8000000000000000)
- #define KIT_S64_MAX (0x7FFFFFFFFFFFFFFF)
- // most significant bits/Bytes
- #define KIT_MSb_8 (0x80)
- #define KIT_MSb_16 (0x8000)
- #define KIT_MSb_32 (0x80000000)
- #define KIT_MSb_64 (0x8000000000000000)
- //
- #define KIT_MSB_8 (0xFF)
- #define KIT_MSB_16 (0xFF00)
- #define KIT_MSB_32 (0xFF000000)
- #define KIT_MSB_64 (0xFF00000000000000)
- #if defined(_STDINT) || defined(_CSTDINT_)
- typedef uint8_t u8 ;
- typedef uint16_t u16;
- typedef uint32_t u32;
- typedef uint64_t u64;
- typedef int8_t s8 ;
- typedef int16_t s16;
- typedef int32_t s32;
- typedef int64_t s64;
- #else
- typedef unsigned char u8 ;
- typedef unsigned short u16;
- typedef unsigned int u32;
- typedef unsigned long long u64;
- typedef signed char s8 ;
- typedef signed short s16;
- typedef signed int s32;
- typedef signed long long s64;
- #endif
- // for consistency
- typedef float f32;
- typedef double f64;
- #if !defined(_STDDEF_H) && !defined(_STDDEF_H_) && !defined(_GLIBCXX_CSTDDEF)
- #ifndef _SIZE_T_DEFINED
- #define _SIZE_T_DEFINED
- typedef u64 size_t;
- #endif /* _SIZE_T_DEFINED */
- #endif
- //short for Generic Opaque Pointer; mostly used internally
- typedef void* GenOpqPtr;
- namespace color {
- union ARGB8888 { //4B; 0xAARRGGBB
- //what GDI uses (save for the alpha channel)
- u32 v; //entire color [v]alue
- struct { u8 b, g, r, a; };
- ARGB8888() : v(0) {}
- ARGB8888(u32 _v) : v(_v) {}
- ARGB8888(u8 _r, u8 _g,
- u8 _b, u8 _a) : b(_b), g(_g), r(_r), a(_a) {}
- inline bool operator==(const ARGB8888& c ){ return (v == c.v); }
- inline bool operator!=(const ARGB8888& c ){ return (v != c.v); }
- inline bool operator==(const u32 & cv){ return (v == cv ); }
- inline bool operator!=(const u32 & cv){ return (v != cv ); }
- inline void operator =(const u32 cv){ (v = cv ); }
- };
- typedef ARGB8888 ARGB;
- union ABGR8888 { //4B; 0xAABBGGRR
- u32 v; //entire color [v]alue
- struct { u8 r, g, b, a; };
- ABGR8888() : v(0) {}
- ABGR8888(u32 _v) : v(_v) {}
- ABGR8888(u8 _r, u8 _g,
- u8 _b, u8 _a) : r(_r), g(_g), b(_b), a(_a) {}
- inline bool operator==(const ABGR8888& c ){ return (v == c.v); }
- inline bool operator!=(const ABGR8888& c ){ return (v != c.v); }
- inline bool operator==(const u32 & cv){ return (v == cv ); }
- inline bool operator!=(const u32 & cv){ return (v != cv ); }
- inline void operator =(const u32 cv){ (v = cv ); }
- };
- typedef ABGR8888 ABGR;
- union ARGB1555 { //2B; 0bARRRRRGGGGGBBBBB
- u16 v; //entire color [v]alue
- struct {
- u16 b : 5;
- u16 g : 5;
- u16 r : 5;
- u16 a : 1;
- };
- ARGB1555() : v(0) {}
- ARGB1555(u16 _v) : v(_v) {}
- ARGB1555(u8 _r, u8 _g,
- u8 _b, u8 _a) : b(_b>>3), g(_g>>3), r(_r>>3), a(_a>>7) {}
- inline bool operator==(const ARGB1555& c ){ return (v == c.v); }
- inline bool operator!=(const ARGB1555& c ){ return (v != c.v); }
- inline bool operator==(const u16 & cv){ return (v == cv ); }
- inline bool operator!=(const u16 & cv){ return (v != cv ); }
- inline void operator =(const u16 cv){ (v = cv ); }
- };
- }; /* namespace color */
- namespace shape {
- struct spoint {
- s16 x, y;
- spoint() : x(0), y(0) {}
- spoint(s16 _x, s16 _y) : x(_x), y(_y) {}
- inline bool operator==(const spoint& p){ return (x==p.x && y==p.y); };
- inline bool operator!=(const spoint& p){ return (x!=p.x && y!=p.y); };
- inline void operator-=(const spoint& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const spoint& p){ x += p.x; y += p.y; }
- };
- struct srect {
- s16 x, y; //x & y position of the rectangle's top-left corner
- s16 w, h; //the rectangle's width & height
- srect() : x(0), y(0), w(0), h(0) {}
- srect(s16 _x, s16 _y) : x(_x), y(_y) {}
- srect(s16 _x, s16 _y,
- s16 _w, s16 _h) : x(_x), y(_y), w(_w), h(_h) {}
- inline bool operator==(const srect& r){ return (x==r.x && y==r.y && w==r.w && h==r.h); };
- inline bool operator!=(const srect& r){ return (x!=r.x && y!=r.y && w!=r.w && h!=r.h); };
- inline void operator-=(const spoint& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const spoint& p){ x += p.x; y += p.y; }
- };
- struct sline {
- s16 x0, y0;
- s16 x1, y1;
- sline() : x0(0), y0(0), x1(0), y1(0) {}
- sline(s16 _x0, s16 _y0,
- s16 _x1, s16 _y1) : x0(_x0), y0(_y0), x1(_x1), y1(_y1) {}
- inline bool operator==(const sline& l){ return (x0==l.x0 && y0==l.y0 && x1==l.x1 && y1==l.y1); };
- inline bool operator!=(const sline& l){ return (x0!=l.x0 && y0!=l.y0 && x1!=l.x1 && y1!=l.y1); };
- };
- struct scircle {
- s16 x, y, r;
- scircle() : x(0), y(0), r(0) {}
- scircle(s16 _x, s16 _y, s16 _r) : x(_x), y(_y), r(_r) {}
- inline bool operator==(const scircle& c){ return (x==c.x && y==c.y && r==c.r); };
- inline bool operator!=(const scircle& c){ return (x!=c.x && y!=c.y && r!=c.r); };
- inline void operator-=(const spoint& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const spoint& p){ x += p.x; y += p.y; }
- };
- struct spoint3d {
- s16 x, y, z;
- spoint3d() : x(0), y(0), z(0) {}
- spoint3d(s16 _x, s16 _y, s16 _z) : x(_x), y(_y), z(_z) {}
- inline bool operator==(const spoint3d& p){ return (x==p.x && y==p.y && z==p.z); }
- inline bool operator!=(const spoint3d& p){ return (x!=p.x && y!=p.y && z!=p.z); }
- };
- struct point {
- s32 x, y;
- point() : x(0), y(0) {}
- point(s32 _x, s32 _y) : x(_x), y(_y) {}
- inline bool operator==(const point& p){ return (x==p.x && y==p.y); };
- inline bool operator!=(const point& p){ return (x!=p.x && y!=p.y); };
- inline void operator-=(const point& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const point& p){ x += p.x; y += p.y; }
- };
- struct rect {
- s32 x, y; //x & y position of the rectangle's top-left corner
- s32 w, h; //the rectangle's width & height
- rect() : x(0), y(0), w(0), h(0) {}
- rect(s32 _x, s32 _y) : x(_x), y(_y) {}
- rect(s32 _x, s32 _y,
- s32 _w, s32 _h) : x(_x), y(_y), w(_w), h(_h) {}
- inline bool operator==(const rect& r){ return (x==r.x && y==r.y && w==r.w && h==r.h); };
- inline bool operator!=(const rect& r){ return (x!=r.x && y!=r.y && w!=r.w && h!=r.h); };
- inline void operator-=(const point& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const point& p){ x += p.x; y += p.y; }
- };
- struct line {
- s32 x0, y0;
- s32 x1, y1;
- line() : x0(0), y0(0), x1(0), y1(0) {}
- line(s32 _x0, s32 _y0,
- s32 _x1, s32 _y1) : x0(_x0), y0(_y0), x1(_x1), y1(_y1) {}
- inline bool operator==(const line& l){ return (x0==l.x0 && y0==l.y0 && x1==l.x1 && y1==l.y1); };
- inline bool operator!=(const line& l){ return (x0!=l.x0 && y0!=l.y0 && x1!=l.x1 && y1!=l.y1); };
- };
- struct circle {
- s32 x, y, r;
- circle() : x(0), y(0), r(0) {}
- circle(s32 _x, s32 _y, s32 _r) : x(_x), y(_y), r(_r) {}
- inline bool operator==(const circle& c){ return (x==c.x && y==c.y && r==c.r); };
- inline bool operator!=(const circle& c){ return (x!=c.x && y!=c.y && r!=c.r); };
- inline void operator-=(const point& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const point& p){ x += p.x; y += p.y; }
- };
- struct point3d {
- s32 x, y, z;
- point3d() : x(0), y(0), z(0) {}
- point3d(s32 _x, s32 _y, s32 _z) : x(_x), y(_y), z(_z) {}
- inline bool operator==(const point3d& p){ return (x==p.x && y==p.y && z==p.z); }
- inline bool operator!=(const point3d& p){ return (x!=p.x && y!=p.y && z!=p.z); }
- };
- struct fpoint {
- f32 x, y;
- fpoint() : x(0.0f), y(0.0f) {}
- fpoint(f32 _x, f32 _y) : x(_x), y(_y) {}
- inline bool operator==(const fpoint& p){ return (x==p.x && y==p.y); };
- inline bool operator!=(const fpoint& p){ return (x!=p.x && y!=p.y); };
- inline void operator-=(const fpoint& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const fpoint& p){ x += p.x; y += p.y; }
- };
- struct frect {
- f32 x, y; //x & y position of rectangle's top-left corner
- f32 w, h; //the rectangle's width & height
- frect() : x(0.0f), y(0.0f), w(0.0f), h(0.0f) {}
- frect(f32 _x, f32 _y) : x(_x), y(_y) {}
- frect(f32 _x, f32 _y,
- f32 _w, f32 _h) : x(_x), y(_y), w(_w), h(_h) {}
- inline bool operator==(const frect& r){ return (x==r.x && y==r.y && w==r.w && h==r.h); };
- inline bool operator!=(const frect& r){ return (x!=r.x && y!=r.y && w!=r.w && h!=r.h); };
- inline void operator-=(const fpoint& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const fpoint& p){ x += p.x; y += p.y; }
- };
- struct fline {
- f32 x0, y0;
- f32 x1, y1;
- fline() : x0(0.0f), y0(0.0f), x1(0.0f), y1(0.0f) {}
- fline(f32 _x0, f32 _y0,
- f32 _x1, f32 _y1) : x0(_x0), y0(_y0), x1(_x1), y1(_y1) {}
- inline bool operator==(const fline& l){ return (x0==l.x0 && y0==l.y0 && x1==l.x1 && y1==l.y1); };
- inline bool operator!=(const fline& l){ return (x0!=l.x0 && y0!=l.y0 && x1!=l.x1 && y1!=l.y1); };
- };
- struct fcircle {
- f32 x, y, r;
- fcircle() : x(0.0f), y(0.0f), r(0.0f) {}
- fcircle(f32 _x, f32 _y, f32 _r) : x(_x), y(_y), r(_r) {}
- inline bool operator==(const fcircle& c){ return (x==c.x && y==c.y && r==c.r); };
- inline bool operator!=(const fcircle& c){ return (x!=c.x && y!=c.y && r!=c.r); };
- inline void operator-=(const fpoint& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const fpoint& p){ x += p.x; y += p.y; }
- };
- struct fpoint3d {
- f32 x, y, z;
- fpoint3d() : x(0.0f), y(0.0f), z(0.0f) {}
- fpoint3d(f32 _x, f32 _y, f32 _z) : x(_x), y(_y), z(_z) {}
- inline bool operator==(const fpoint3d& p){ return (x==p.x && y==p.y && z==p.z); }
- inline bool operator!=(const fpoint3d& p){ return (x!=p.x && y!=p.y && z!=p.z); }
- };
- struct dpoint {
- f64 x, y;
- dpoint() : x(0.0), y(0.0) {}
- dpoint(f64 _x, f64 _y) : x(_x), y(_y) {}
- inline bool operator==(const dpoint& p){ return (x==p.x && y==p.y); };
- inline bool operator!=(const dpoint& p){ return (x!=p.x && y!=p.y); };
- inline void operator-=(const dpoint& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const dpoint& p){ x += p.x; y += p.y; }
- };
- struct drect {
- f64 x, y; //x & y position of rectangle's top-left corner
- f64 w, h; //the rectangle's width & height
- drect() : x(0.0), y(0.0), w(0.0), h(0.0) {}
- drect(f64 _x, f64 _y) : x(_x), y(_y) {}
- drect(f64 _x, f64 _y,
- f64 _w, f64 _h) : x(_x), y(_y), w(_w), h(_h) {}
- inline bool operator==(const drect& r){ return (x==r.x && y==r.y && w==r.w && h==r.h); };
- inline bool operator!=(const drect& r){ return (x!=r.x && y!=r.y && w!=r.w && h!=r.h); };
- inline void operator-=(const dpoint& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const dpoint& p){ x += p.x; y += p.y; }
- };
- struct dline {
- f64 x0, y0;
- f64 x1, y1;
- dline() : x0(0.0), y0(0.0), x1(0.0), y1(0.0) {}
- dline(f64 _x0, f64 _y0,
- f64 _x1, f64 _y1) : x0(_x0), y0(_y0), x1(_x1), y1(_y1) {}
- inline bool operator==(const dline& l){ return (x0==l.x0 && y0==l.y0 && x1==l.x1 && y1==l.y1); };
- inline bool operator!=(const dline& l){ return (x0!=l.x0 && y0!=l.y0 && x1!=l.x1 && y1!=l.y1); };
- };
- struct dcircle {
- f64 x, y;
- f64 r;
- dcircle() : x(0.0), y(0.0), r(0.0) {}
- dcircle(f64 _x, f64 _y, f64 _r) : x(_x), y(_y), r(_r) {}
- inline bool operator==(const dcircle& c){ return (x==c.x && y==c.y && r==c.r); };
- inline bool operator!=(const dcircle& c){ return (x!=c.x && y!=c.y && r!=c.r); };
- inline void operator-=(const dpoint& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const dpoint& p){ x += p.x; y += p.y; }
- };
- struct dpoint3d {
- f64 x, y, z;
- dpoint3d() : x(0.0), y(0.0), z(0.0) {}
- dpoint3d(f64 _x, f64 _y, f64 _z) : x(_x), y(_y), z(_z) {}
- inline bool operator==(const dpoint3d& p){ return (x==p.x && y==p.y && z==p.z); }
- inline bool operator!=(const dpoint3d& p){ return (x!=p.x && y!=p.y && z!=p.z); }
- };
- }; /* namespace shape */
- }; /* namespace kit */
- #endif /* _COMMONDEF_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\include\kit\misc.hpp":
- //THIS LIBRARY WAS MADE TO USE SDL2 VERSION 2.28.2
- #ifndef _INC_MISC_HPP
- #define _INC_MISC_HPP
- #include "commondef.hpp"
- #include "_misc_memory.hpp"
- #include "_misc_Mutex.hpp"
- #include "_misc_Thread.hpp"
- #include "_misc_func.hpp"
- #include "_misc_time.hpp"
- #include "_misc_Event.hpp"
- #include "_misc_fileio.hpp"
- #endif /* _INC_MISC_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\include\kit\video.hpp":
- //THIS LIBRARY WAS MADE TO USE SDL2 VERSION 2.28.2
- #ifndef _INC_VIDEO_HPP
- #define _INC_VIDEO_HPP
- #include "commondef.hpp"
- #include "_video_Window.hpp"
- #endif /* _INC_VIDEO_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\include\kit\_audio_AudioDevice.hpp":
- #ifndef _INC__AUDIO_AUDIODEVICE_HPP
- #define _INC__AUDIO_AUDIODEVICE_HPP
- #include "commondef.hpp"
- #include "_audio_types.hpp"
- namespace kit {
- //if disableFadeDelay == false, audio will be muted for 90ms
- //before fading in over the course of 10ms (100ms in total).
- //if disableFadeDelay == true, only the fade-in will occur
- class AudioDevice { //64B
- u32 _type;
- bool _valid = false;
- bool _constructing = true;
- u16 _padding16;
- GenOpqPtr _opq = nullptr;
- //(device starts in a paused state!)
- void _construct(const char* name,
- const AudioDeviceInfo* desired,
- bool disableFadeDelay = false,
- bool indexed = true);
- public:
- const AudioDeviceInfo info;
- //(internally calls SDL_GetAudioDeviceName to get device's name)
- AudioDevice(s32 index, //-1 to use default device
- const AudioDeviceInfo* desired,
- bool disableFadeDelay = false);
- AudioDevice(const char* name, //nullptr to use default device
- const AudioDeviceInfo* desired,
- bool disableFadeDelay = false)
- { _construct(name, desired, disableFadeDelay, false); }
- //this will abruptly stop audio playback with no fade-out, so make sure
- //to have the device be completely paused by the time this is called!
- //(it's technically fine to do this w/o pausing, but it sounds terrible)
- ~AudioDevice();
- inline bool isValid() { return _valid; }
- inline bool isConstructing(){ return _constructing; }
- bool isPlaying();
- bool isActive();
- //(^^returning true does not necessarily mean
- //that the callback is actually being called!)
- void setCallback(AudioCallback callback);
- void setUserdata(void* userdata);
- void setPlayback(bool playing);
- void setPlaybackAndWait(bool playing); //false,true = wait 10ms, wait 100ms
- inline void play() { setPlayback(true ); }
- inline void pause(){ setPlayback(false); }
- inline void playAndWait() { setPlaybackAndWait(true ); }
- inline void pauseAndWait(){ setPlaybackAndWait(false); }
- void lock(bool locked = true);
- inline void unlock(){ lock(false); }
- };
- }; /* namespace kit */
- #endif /* _INC__AUDIO_AUDIODEVICE_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\include\kit\_audio_func.hpp":
- #ifndef _INC__AUDIO_FUNC_HPP
- #define _INC__AUDIO_FUNC_HPP
- #include "commondef.hpp"
- #include "_audio_types.hpp"
- namespace kit {
- namespace audio {
- //if name_p != nullptr, *name_p will be filled with the name of the device
- //(memory is allocated here; call memory::free() on it to prevent leaks!)
- //(also, this function can potentially be quite expensive, so don't call it often!)
- AudioDeviceInfo getDefaultDevInfo(char** name_p = nullptr, bool isInput = false);
- AudioDeviceInfo getDeviceInfo(s32 index, bool isInput);
- //returns -1 if explicit device list could not be determined
- //(doesn't necessarily mean an error, but call getLastSysError() just in case)
- s32 getNumDevices(bool isInput);
- //the returned pointer (utf-8 encoded) is managed internally and should not be freed
- //if you want to reference/store the string long-term, it should be copied, as the returned
- //pointer will become invalid the next time certain SDL functions are called internally
- //(also, the returned value and its associated index reflect the latest call to
- //getNumDevices(), so that should be called in order to redetect available hardware)
- const char* getDeviceName(u32 index, bool isInput);
- }; /* namespace audio */
- }; /* namespace kit */
- #endif /* _INC__AUDIO_FUNC_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\include\kit\_audio_types.hpp":
- #ifndef _INC__AUDIO_TYPES_HPP
- #define _INC__AUDIO_TYPES_HPP
- #include "commondef.hpp"
- namespace kit {
- #define KIT_AUDIO_BITSIZE(x) (x & (0xFF ))
- #define KIT_AUDIO_ISFLOAT(x) (x & (1<< 8))
- //#define KIT_AUDIO_ISBIGENDIAN(x) (x & (1<<12))
- #define KIT_AUDIO_ISSIGNED(x) (x & (1<<15))
- #define KIT_AUDIO_BYTESIZE(x) (KIT_AUDIO_BITSIZE(x)/8)
- //(big-endian sample formats are not supported currently)
- enum AudioSampleFormatEnum {
- SMPFMT_U8 = 0x0008, //unsigned 8-bit samples
- SMPFMT_S8 = 0x8008, // signed 8-bit samples
- SMPFMT_U16LSB = 0x0010, //unsigned 16-bit samples
- SMPFMT_S16LSB = 0x8010, // signed 16-bit samples
- //SMPFMT_U16MSB = 0x1010, //as above, but big-endian byte order
- //SMPFMT_S16MSB = 0x9010, //as above, but big-endian byte order
- SMPFMT_S32LSB = 0x8020, // signed 32-bit samples
- //SMPFMT_S32MSB = 0x9020, //As above, but big-endian byte order
- SMPFMT_F32LSB = 0x8120, //32-bit floating point samples
- //SMPFMT_F32MSB = 0x9120, //As above, but big-endian byte order
- SMPFMT_U16 = SMPFMT_U16LSB,
- SMPFMT_S16 = SMPFMT_S16LSB,
- SMPFMT_S32 = SMPFMT_S32LSB,
- SMPFMT_F32 = SMPFMT_F32LSB,
- };
- struct AudioDeviceInfo; //forward declaration
- //returns 'should device keep playing?' (will pause otherwise)
- typedef bool (*AudioCallback)(void* _buffer, const AudioDeviceInfo* info);
- /* (taken from the SDL2 wiki):
- For multi-channel audio, the default SDL channel mapping is:
- 2: FL FR (stereo)
- 3: FL FR LFE (2.1 surround)
- 4: FL FR BL BR (quad)
- 5: FL FR LFE BL BR (4.1 surround)
- 6: FL FR FC LFE SL SR (5.1 surround - last two can also be BL BR)
- 7: FL FR FC LFE BC SL SR (6.1 surround)
- 8: FL FR FC LFE BL BR SL SR (7.1 surround)
- */
- struct AudioDeviceInfo { //48B
- u64 timeStartTicks = 0; //timestamp (in ticks) at start of callback (read-only)
- u64 timeStartMS = 0; //timestamp (in ms) at start of callback (read-only)
- u32 deviceID = 0; //(read-only)
- u32 sampleRate = 0; //0 to use device's default
- u16 sampleFrames = 0; //0 to use device's default (should always be a power of 2)
- u16 sampleFormat = SMPFMT_F32; //samples are floats by default
- u8 sampleFrameSize = 0; //size of a single sample frame, in bytes (read only)
- u8 numChannels = 0; //0 to use device's default
- bool isInput = false; //is this a recording device? (rendering/output otherwise)
- bool zeroBuffer = false; //'memset 0 the audio buffer before calling callback?' (output devs only)
- AudioCallback callback = nullptr;
- void* userdata = nullptr; //optional, unlike callback
- };
- union Mono_smp {
- u8* u8_ ;
- s8* s8_ ;
- u16* u16_;
- s16* s16_;
- s32* s32_;
- f32* f32_;
- void* data;
- Mono_smp(void* _data) : data(_data) {}
- };
- struct Stereo_u8 { u8 l, r; };
- struct Stereo_s8 { s8 l, r; };
- struct Stereo_u16 { u16 l, r; };
- struct Stereo_s16 { s16 l, r; };
- struct Stereo_s32 { s32 l, r; };
- struct Stereo_f32 { f32 l, r; };
- union Stereo_smp {
- Stereo_u8* u8_ ;
- Stereo_s8* s8_ ;
- Stereo_u16* u16_;
- Stereo_s16* s16_;
- Stereo_s32* s32_;
- Stereo_f32* f32_;
- void* data;
- Stereo_smp(void* _data) : data(_data) {}
- };
- }; /* namespace kit */
- #endif /* _INC__AUDIO_TYPES_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\include\kit\_misc_Event.hpp":
- #ifndef _INC__MISC_EVENT_HPP
- #define _INC__MISC_EVENT_HPP
- #include "commondef.hpp"
- namespace kit {
- #define KIT_EVENT_ID(_id) ( (_id) & 0xFFFF0000 )
- #define KIT_SUBEVENT_ID(_sub_id) ( (_sub_id) & 0xFFFF )
- #define _KIT_INC_ETYPE(_previous_type) ( (_previous_type) + 0x00010000 )
- enum EventTypesEnum {
- KEVENT_NULL = 0x00000000,
- //(common is not an actual event that occurs,
- //it just includes what the other events have in common)
- KEVENT_COMMON = _KIT_INC_ETYPE(KEVENT_NULL), //Event_Common
- KEVENT_DISPLAY = _KIT_INC_ETYPE(KEVENT_COMMON), //Event_Display
- KEVENT_DISPLAY_ORIENTATION = KEVENT_DISPLAY | 0x0001, //display orientation has changed to data1
- KEVENT_DISPLAY_DISCONNECTED = KEVENT_DISPLAY | 0x0002, //display has been removed from the system
- KEVENT_DISPLAY_CONNECTED = KEVENT_DISPLAY | 0x0003, //display has been added to the system
- KEVENT_DISPLAY_MOVED = KEVENT_DISPLAY | 0x0004, //display has changed position
- KEVENT_WIN = _KIT_INC_ETYPE(KEVENT_DISPLAY), //Event_Window
- KEVENT_WIN_EXPOSED = KEVENT_WIN | 0x0001, //window has been exposed and should be redrawn
- KEVENT_WIN_HIDDEN = KEVENT_WIN | 0x0002, //window has been hidden
- KEVENT_WIN_SHOWN = KEVENT_WIN | 0x0003, //window has been shown
- KEVENT_WIN_MOVED = KEVENT_WIN | 0x0004, //window has been moved to dataX, dataY
- KEVENT_WIN_RESIZED = KEVENT_WIN | 0x0005, //window has been resized to dataX, dataY
- KEVENT_WIN_SIZE_CHANGED = KEVENT_WIN | 0x0006, //window size has changed, via API, system, or user.
- KEVENT_WIN_RESTORED = KEVENT_WIN | 0x0007, //window has been restored to normal size and position
- KEVENT_WIN_MINIMIZED = KEVENT_WIN | 0x0008, //window has been minimized
- KEVENT_WIN_MAXIMIZED = KEVENT_WIN | 0x0009, //window has been maximized
- KEVENT_WIN_MFOCUS_LOST = KEVENT_WIN | 0x000A, //window has lost mouse focus
- KEVENT_WIN_MFOCUS_GAINED = KEVENT_WIN | 0x000B, //window has gained mouse focus
- KEVENT_WIN_KFOCUS_LOST = KEVENT_WIN | 0x000C, //window has lost keyboard focus
- KEVENT_WIN_KFOCUS_GAINED = KEVENT_WIN | 0x000D, //window has gained keyboard focus
- KEVENT_WIN_CLOSE = KEVENT_WIN | 0x000E, //window manager requests that the window be closed
- 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)
- KEVENT_WIN_HIT_TEST = KEVENT_WIN | 0x0010, //window had a hit test that wasn't HITTEST_NORMAL.
- KEVENT_WIN_ICCPROF_CHANGED = KEVENT_WIN | 0x0011, //the ICC profile of the window's display has changed.
- KEVENT_WIN_DISPLAY_CHANGED = KEVENT_WIN | 0x0012, //window has been moved to display data1.
- KEVENT_KEY = _KIT_INC_ETYPE(KEVENT_WIN), //Event_Key
- KEVENT_KEY_DOWN = KEVENT_KEY | 0x0001,
- KEVENT_KEY_UP = KEVENT_KEY | 0x0002,
- KEVENT_KEYMAPCHANGED = _KIT_INC_ETYPE(KEVENT_KEY), //(N/A); keymap changed by a input language/layout system event
- KEVENT_MOUSE = _KIT_INC_ETYPE(KEVENT_KEYMAPCHANGED), //Event_Mouse
- KEVENT_MOUSE_MOVED = KEVENT_MOUSE | 0x0001,
- KEVENT_MOUSE_UP = KEVENT_MOUSE | 0x0002,
- KEVENT_MOUSE_DOWN = KEVENT_MOUSE | 0x0003,
- KEVENT_MOUSE_WHEEL = KEVENT_MOUSE | 0x0004,
- KEVENT_JOY = _KIT_INC_ETYPE(KEVENT_MOUSE), //Event_Joystick
- KEVENT_JOY_AXIS = KEVENT_JOY | 0x0001,
- KEVENT_JOY_TRACKBALL = KEVENT_JOY | 0x0002,
- KEVENT_JOY_HAT = KEVENT_JOY | 0x0003,
- KEVENT_JOY_BUTTON_UP = KEVENT_JOY | 0x0004,
- KEVENT_JOY_BUTTON_DOWN = KEVENT_JOY | 0x0005,
- KEVENT_JOY_DEVICE_REMOVED = KEVENT_JOY | 0x0006,
- KEVENT_JOY_DEVICE_ADDED = KEVENT_JOY | 0x0007,
- KEVENT_JOY_BATTERY = KEVENT_JOY | 0x0008,
- KEVENT_CTLR = _KIT_INC_ETYPE(KEVENT_JOY), //Event_GameController
- KEVENT_CTLR_AXIS = KEVENT_CTLR | 0x0001,
- KEVENT_CTLR_BUTTON_UP = KEVENT_CTLR | 0x0002,
- KEVENT_CTLR_BUTTON_DOWN = KEVENT_CTLR | 0x0003,
- KEVENT_CTLR_DEVICE_REMOVED = KEVENT_CTLR | 0x0004,
- KEVENT_CTLR_DEVICE_ADDED = KEVENT_CTLR | 0x0005,
- KEVENT_CTLR_DEVICE_REMAPPED = KEVENT_CTLR | 0x0006,
- KEVENT_CTLR_TOUCHPAD_UP = KEVENT_CTLR | 0x0007,
- KEVENT_CTLR_TOUCHPAD_DOWN = KEVENT_CTLR | 0x0008,
- KEVENT_CTLR_TOUCHPAD_MOVED = KEVENT_CTLR | 0x0009,
- KEVENT_CTLR_SENSOR = KEVENT_CTLR | 0x000A,
- KEVENT_ADEV = _KIT_INC_ETYPE(KEVENT_CTLR), //Event_AudioDevice
- KEVENT_ADEV_ADDED = KEVENT_ADEV | 0x0001,
- KEVENT_ADEV_REMOVED = KEVENT_ADEV | 0x0002,
- KEVENT_DROP = _KIT_INC_ETYPE(KEVENT_ADEV), //Event_Drop
- KEVENT_DROP_FILE = KEVENT_DROP | 0x0001, //system requests a file to open
- KEVENT_DROP_TEXT = KEVENT_DROP | 0x0002, //text/plain drag-and-drop event
- KEVENT_DROP_BEGIN = KEVENT_DROP | 0x0003, //new set of drops beginning (filePath=nullptr)
- KEVENT_DROP_COMPLETE = KEVENT_DROP | 0x0004, //current set of drops complete (filePath=nullptr)
- KEVENT_QUIT = _KIT_INC_ETYPE(KEVENT_DROP), //Event_Quit
- KEVENT_USER = _KIT_INC_ETYPE(KEVENT_QUIT), //Event_User
- KEVENT_RENDER = _KIT_INC_ETYPE(KEVENT_USER), //(N/A)
- KEVENT_RENDER_TARGETS_RESET = KEVENT_RENDER | 0x0001,
- KEVENT_RENDER_DEVICE_RESET = KEVENT_RENDER | 0x0002,
- KEVENT_CLIPBOARDUPDATE = _KIT_INC_ETYPE(KEVENT_RENDER), //(N/A)
- KEVENT_UNKNOWN = 0xFFFFFFFF,
- NUM_KEVENT_TYPES = KEVENT_CLIPBOARDUPDATE >> 16,
- };
- /*+KEVENT_COMMON+*/
- struct Event_Common { //8B
- u32 type;
- u32 timestamp; //in milliseconds, same as getMS_32
- };
- /*-KEVENT_COMMON-*/
- /*+KEVENT_DISPLAY+*/
- struct Event_Display { //16B
- u32 type;
- u32 timestamp;
- u32 id; //index of associated display
- s32 data;
- };
- /*-KEVENT_DISPLAY-*/
- /*+KEVENT_WIN+*/
- enum Event_Window_HitTestEnum {
- WIN_HITTEST_NORMAL, // Region is normal. No special properties.
- WIN_HITTEST_DRAGGABLE, // Region can drag entire window.
- WIN_HITTEST_RESIZE_TOPLEFT,
- WIN_HITTEST_RESIZE_TOP,
- WIN_HITTEST_RESIZE_TOPRIGHT,
- WIN_HITTEST_RESIZE_RIGHT,
- WIN_HITTEST_RESIZE_BOTTOMRIGHT,
- WIN_HITTEST_RESIZE_BOTTOM,
- WIN_HITTEST_RESIZE_BOTTOMLEFT,
- WIN_HITTEST_RESIZE_LEFT
- };
- struct Event_Window { //24B
- u32 type;
- u32 timestamp;
- u32 id; //index of associated window
- u32 _padding32;
- union { s32 data1, dataX; };
- union { s32 data2, dataY; };
- };
- /*-KEVENT_WIN-*/
- /*+KEVENT_KEY+*/
- //(these enums are mostly ripped directly from
- //SDL2's header files! please don't sue me! D:)
- enum Event_Key_PhysicalEnum { //aka scancodes
- PKEY_UNKNOWN = 0,
- /**
- * \name Usage page 0x07
- *
- * These values are from usage page 0x07 (USB keyboard page).
- */
- /* @{ */
- PKEY_A = 4,
- PKEY_B = 5,
- PKEY_C = 6,
- PKEY_D = 7,
- PKEY_E = 8,
- PKEY_F = 9,
- PKEY_G = 10,
- PKEY_H = 11,
- PKEY_I = 12,
- PKEY_J = 13,
- PKEY_K = 14,
- PKEY_L = 15,
- PKEY_M = 16,
- PKEY_N = 17,
- PKEY_O = 18,
- PKEY_P = 19,
- PKEY_Q = 20,
- PKEY_R = 21,
- PKEY_S = 22,
- PKEY_T = 23,
- PKEY_U = 24,
- PKEY_V = 25,
- PKEY_W = 26,
- PKEY_X = 27,
- PKEY_Y = 28,
- PKEY_Z = 29,
- PKEY_1 = 30,
- PKEY_2 = 31,
- PKEY_3 = 32,
- PKEY_4 = 33,
- PKEY_5 = 34,
- PKEY_6 = 35,
- PKEY_7 = 36,
- PKEY_8 = 37,
- PKEY_9 = 38,
- PKEY_0 = 39,
- PKEY_RETURN = 40,
- PKEY_ESCAPE = 41,
- PKEY_BACKSPACE = 42,
- PKEY_TAB = 43,
- PKEY_SPACE = 44,
- PKEY_MINUS = 45,
- PKEY_EQUALS = 46,
- PKEY_LEFTBRACKET = 47,
- PKEY_RIGHTBRACKET = 48,
- PKEY_BACKSLASH = 49, /**< Located at the lower left of the return
- * key on ISO keyboards and at the right end
- * of the QWERTY row on ANSI keyboards.
- * Produces REVERSE SOLIDUS (backslash) and
- * VERTICAL LINE in a US layout, REVERSE
- * SOLIDUS and VERTICAL LINE in a UK Mac
- * layout, NUMBER SIGN and TILDE in a UK
- * Windows layout, DOLLAR SIGN and POUND SIGN
- * in a Swiss German layout, NUMBER SIGN and
- * APOSTROPHE in a German layout, GRAVE
- * ACCENT and POUND SIGN in a French Mac
- * layout, and ASTERISK and MICRO SIGN in a
- * French Windows layout.
- */
- PKEY_NONUSHASH = 50, /**< ISO USB keyboards actually use this code
- * instead of 49 for the same key, but all
- * OSes I've seen treat the two codes
- * identically. So, as an implementor, unless
- * your keyboard generates both of those
- * codes and your OS treats them differently,
- * you should generate PKEY_BACKSLASH
- * instead of this code. As a user, you
- * should not rely on this code because SDL
- * will never generate it with most (all?)
- * keyboards.
- */
- PKEY_SEMICOLON = 51,
- PKEY_APOSTROPHE = 52,
- PKEY_GRAVE = 53, /**< Located in the top left corner (on both ANSI
- * and ISO keyboards). Produces GRAVE ACCENT and
- * TILDE in a US Windows layout and in US and UK
- * Mac layouts on ANSI keyboards, GRAVE ACCENT
- * and NOT SIGN in a UK Windows layout, SECTION
- * SIGN and PLUS-MINUS SIGN in US and UK Mac
- * layouts on ISO keyboards, SECTION SIGN and
- * DEGREE SIGN in a Swiss German layout (Mac:
- * only on ISO keyboards), CIRCUMFLEX ACCENT and
- * DEGREE SIGN in a German layout (Mac: only on
- * ISO keyboards), SUPERSCRIPT TWO and TILDE in a
- * French Windows layout, COMMERCIAL AT and
- * NUMBER SIGN in a French Mac layout on ISO
- * keyboards, and LESS-THAN SIGN and GREATER-THAN
- * SIGN in a Swiss German, German, or French Mac
- * layout on ANSI keyboards.
- */
- PKEY_COMMA = 54,
- PKEY_PERIOD = 55,
- PKEY_SLASH = 56,
- PKEY_CAPSLOCK = 57,
- PKEY_F1 = 58,
- PKEY_F2 = 59,
- PKEY_F3 = 60,
- PKEY_F4 = 61,
- PKEY_F5 = 62,
- PKEY_F6 = 63,
- PKEY_F7 = 64,
- PKEY_F8 = 65,
- PKEY_F9 = 66,
- PKEY_F10 = 67,
- PKEY_F11 = 68,
- PKEY_F12 = 69,
- PKEY_PRINTSCREEN = 70,
- PKEY_SCROLLLOCK = 71,
- PKEY_PAUSE = 72,
- PKEY_INSERT = 73, /**< insert on PC, help on some Mac keyboards (but
- does send code 73, not 117) */
- PKEY_HOME = 74,
- PKEY_PAGEUP = 75,
- PKEY_DELETE = 76,
- PKEY_END = 77,
- PKEY_PAGEDOWN = 78,
- PKEY_RIGHT = 79,
- PKEY_LEFT = 80,
- PKEY_DOWN = 81,
- PKEY_UP = 82,
- PKEY_NUMLOCKCLEAR = 83, /**< num lock on PC, clear on Mac keyboards */
- PKEY_KP_DIVIDE = 84,
- PKEY_KP_MULTIPLY = 85,
- PKEY_KP_MINUS = 86,
- PKEY_KP_PLUS = 87,
- PKEY_KP_ENTER = 88,
- PKEY_KP_1 = 89,
- PKEY_KP_2 = 90,
- PKEY_KP_3 = 91,
- PKEY_KP_4 = 92,
- PKEY_KP_5 = 93,
- PKEY_KP_6 = 94,
- PKEY_KP_7 = 95,
- PKEY_KP_8 = 96,
- PKEY_KP_9 = 97,
- PKEY_KP_0 = 98,
- PKEY_KP_PERIOD = 99,
- PKEY_NONUSBACKSLASH = 100, /**< This is the additional key that ISO
- * keyboards have over ANSI ones,
- * located between left shift and Y.
- * Produces GRAVE ACCENT and TILDE in a
- * US or UK Mac layout, REVERSE SOLIDUS
- * (backslash) and VERTICAL LINE in a
- * US or UK Windows layout, and
- * LESS-THAN SIGN and GREATER-THAN SIGN
- * in a Swiss German, German, or French
- * layout. */
- PKEY_APPLICATION = 101, /**< windows contextual menu, compose */
- PKEY_POWER = 102, /**< The USB document says this is a status flag,
- * not a physical key - but some Mac keyboards
- * do have a power key. */
- PKEY_KP_EQUALS = 103,
- PKEY_F13 = 104,
- PKEY_F14 = 105,
- PKEY_F15 = 106,
- PKEY_F16 = 107,
- PKEY_F17 = 108,
- PKEY_F18 = 109,
- PKEY_F19 = 110,
- PKEY_F20 = 111,
- PKEY_F21 = 112,
- PKEY_F22 = 113,
- PKEY_F23 = 114,
- PKEY_F24 = 115,
- PKEY_EXECUTE = 116,
- PKEY_HELP = 117, /**< AL Integrated Help Center */
- PKEY_MENU = 118, /**< Menu (show menu) */
- PKEY_SELECT = 119,
- PKEY_STOP = 120, /**< AC Stop */
- PKEY_AGAIN = 121, /**< AC Redo/Repeat */
- PKEY_UNDO = 122, /**< AC Undo */
- PKEY_CUT = 123, /**< AC Cut */
- PKEY_COPY = 124, /**< AC Copy */
- PKEY_PASTE = 125, /**< AC Paste */
- PKEY_FIND = 126, /**< AC Find */
- PKEY_MUTE = 127,
- PKEY_VOLUMEUP = 128,
- PKEY_VOLUMEDOWN = 129,
- /* not sure whether there's a reason to enable these */
- /* PKEY_LOCKINGCAPSLOCK = 130, */
- /* PKEY_LOCKINGNUMLOCK = 131, */
- /* PKEY_LOCKINGSCROLLLOCK = 132, */
- PKEY_KP_COMMA = 133,
- PKEY_KP_EQUALSAS400 = 134,
- PKEY_INTERNATIONAL1 = 135, /**< used on Asian keyboards, see
- footnotes in USB doc */
- PKEY_INTERNATIONAL2 = 136,
- PKEY_INTERNATIONAL3 = 137, /**< Yen */
- PKEY_INTERNATIONAL4 = 138,
- PKEY_INTERNATIONAL5 = 139,
- PKEY_INTERNATIONAL6 = 140,
- PKEY_INTERNATIONAL7 = 141,
- PKEY_INTERNATIONAL8 = 142,
- PKEY_INTERNATIONAL9 = 143,
- PKEY_LANG1 = 144, /**< Hangul/English toggle */
- PKEY_LANG2 = 145, /**< Hanja conversion */
- PKEY_LANG3 = 146, /**< Katakana */
- PKEY_LANG4 = 147, /**< Hiragana */
- PKEY_LANG5 = 148, /**< Zenkaku/Hankaku */
- PKEY_LANG6 = 149, /**< reserved */
- PKEY_LANG7 = 150, /**< reserved */
- PKEY_LANG8 = 151, /**< reserved */
- PKEY_LANG9 = 152, /**< reserved */
- PKEY_ALTERASE = 153, /**< Erase-Eaze */
- PKEY_SYSREQ = 154,
- PKEY_CANCEL = 155, /**< AC Cancel */
- PKEY_CLEAR = 156,
- PKEY_PRIOR = 157,
- PKEY_RETURN2 = 158,
- PKEY_SEPARATOR = 159,
- PKEY_OUT = 160,
- PKEY_OPER = 161,
- PKEY_CLEARAGAIN = 162,
- PKEY_CRSEL = 163,
- PKEY_EXSEL = 164,
- PKEY_KP_00 = 176,
- PKEY_KP_000 = 177,
- PKEY_THOUSANDSSEPARATOR = 178,
- PKEY_DECIMALSEPARATOR = 179,
- PKEY_CURRENCYUNIT = 180,
- PKEY_CURRENCYSUBUNIT = 181,
- PKEY_KP_LEFTPAREN = 182,
- PKEY_KP_RIGHTPAREN = 183,
- PKEY_KP_LEFTBRACE = 184,
- PKEY_KP_RIGHTBRACE = 185,
- PKEY_KP_TAB = 186,
- PKEY_KP_BACKSPACE = 187,
- PKEY_KP_A = 188,
- PKEY_KP_B = 189,
- PKEY_KP_C = 190,
- PKEY_KP_D = 191,
- PKEY_KP_E = 192,
- PKEY_KP_F = 193,
- PKEY_KP_XOR = 194,
- PKEY_KP_POWER = 195,
- PKEY_KP_PERCENT = 196,
- PKEY_KP_LESS = 197,
- PKEY_KP_GREATER = 198,
- PKEY_KP_AMPERSAND = 199,
- PKEY_KP_DBLAMPERSAND = 200,
- PKEY_KP_VERTICALBAR = 201,
- PKEY_KP_DBLVERTICALBAR = 202,
- PKEY_KP_COLON = 203,
- PKEY_KP_HASH = 204,
- PKEY_KP_SPACE = 205,
- PKEY_KP_AT = 206,
- PKEY_KP_EXCLAM = 207,
- PKEY_KP_MEMSTORE = 208,
- PKEY_KP_MEMRECALL = 209,
- PKEY_KP_MEMCLEAR = 210,
- PKEY_KP_MEMADD = 211,
- PKEY_KP_MEMSUBTRACT = 212,
- PKEY_KP_MEMMULTIPLY = 213,
- PKEY_KP_MEMDIVIDE = 214,
- PKEY_KP_PLUSMINUS = 215,
- PKEY_KP_CLEAR = 216,
- PKEY_KP_CLEARENTRY = 217,
- PKEY_KP_BINARY = 218,
- PKEY_KP_OCTAL = 219,
- PKEY_KP_DECIMAL = 220,
- PKEY_KP_HEXADECIMAL = 221,
- PKEY_LCTRL = 224,
- PKEY_LSHIFT = 225,
- PKEY_LALT = 226, /**< alt, option */
- PKEY_LGUI = 227, /**< windows, command (apple), meta */
- PKEY_RCTRL = 228,
- PKEY_RSHIFT = 229,
- PKEY_RALT = 230, /**< alt gr, option */
- PKEY_RGUI = 231, /**< windows, command (apple), meta */
- PKEY_MODE = 257, /**< I'm not sure if this is really not covered
- * by any of the above, but since there's a
- * special KEYMOD_MODE for it I'm adding it here
- */
- /* @} *//* Usage page 0x07 */
- /**
- * \name Usage page 0x0C
- *
- * These values are mapped from usage page 0x0C (USB consumer page).
- * See https://usb.org/sites/default/files/hut1_2.pdf
- *
- * There are way more keys in the spec than we can represent in the
- * current scancode range, so pick the ones that commonly come up in
- * real world usage.
- */
- /* @{ */
- PKEY_AUDIONEXT = 258,
- PKEY_AUDIOPREV = 259,
- PKEY_AUDIOSTOP = 260,
- PKEY_AUDIOPLAY = 261,
- PKEY_AUDIOMUTE = 262,
- PKEY_MEDIASELECT = 263,
- PKEY_WWW = 264, /**< AL Internet Browser */
- PKEY_MAIL = 265,
- PKEY_CALCULATOR = 266, /**< AL Calculator */
- PKEY_COMPUTER = 267,
- PKEY_AC_SEARCH = 268, /**< AC Search */
- PKEY_AC_HOME = 269, /**< AC Home */
- PKEY_AC_BACK = 270, /**< AC Back */
- PKEY_AC_FORWARD = 271, /**< AC Forward */
- PKEY_AC_STOP = 272, /**< AC Stop */
- PKEY_AC_REFRESH = 273, /**< AC Refresh */
- PKEY_AC_BOOKMARKS = 274, /**< AC Bookmarks */
- /* @} *//* Usage page 0x0C */
- /**
- * \name Walther keys
- *
- * These are values that Christian Walther added (for mac keyboard?).
- */
- /* @{ */
- PKEY_BRIGHTNESSDOWN = 275,
- PKEY_BRIGHTNESSUP = 276,
- PKEY_DISPLAYSWITCH = 277, /**< display mirroring/dual display
- switch, video mode switch */
- PKEY_KBDILLUMTOGGLE = 278,
- PKEY_KBDILLUMDOWN = 279,
- PKEY_KBDILLUMUP = 280,
- PKEY_EJECT = 281,
- PKEY_SLEEP = 282, /**< SC System Sleep */
- PKEY_APP1 = 283,
- PKEY_APP2 = 284,
- /* @} *//* Walther keys */
- /**
- * \name Usage page 0x0C (additional media keys)
- *
- * These values are mapped from usage page 0x0C (USB consumer page).
- */
- /* @{ */
- PKEY_AUDIOREWIND = 285,
- PKEY_AUDIOFASTFORWARD = 286,
- /* @} *//* Usage page 0x0C (additional media keys) */
- /**
- * \name Mobile keys
- *
- * These are values that are often used on mobile phones.
- */
- /* @{ */
- PKEY_SOFTLEFT = 287, /**< Usually situated below the display on phones and
- used as a multi-function feature key for selecting
- a software defined function shown on the bottom left
- of the display. */
- PKEY_SOFTRIGHT = 288, /**< Usually situated below the display on phones and
- used as a multi-function feature key for selecting
- a software defined function shown on the bottom right
- of the display. */
- PKEY_CALL = 289, /**< Used for accepting phone calls. */
- PKEY_ENDCALL = 290, /**< Used for rejecting phone calls. */
- /* @} *//* Mobile keys */
- /* Add any other keys here. */
- KIT_NUM_PKEYS = 512 /**< not a key, just marks the number of scancodes
- for array bounds */
- };
- #define _KIT_PKEY_MASK (1<<30)
- #define KIT_PKEY_TO_VKEY(X) (X | _KIT_PKEY_MASK)
- enum Event_Key_VirtualEnum {
- VKEY_UNKNOWN = 0,
- VKEY_RETURN = '\r',
- VKEY_ESCAPE = '\x1B',
- VKEY_BACKSPACE = '\b',
- VKEY_TAB = '\t',
- VKEY_SPACE = ' ',
- VKEY_EXCLAIM = '!',
- VKEY_QUOTEDBL = '"',
- VKEY_HASH = '#',
- VKEY_PERCENT = '%',
- VKEY_DOLLAR = '$',
- VKEY_AMPERSAND = '&',
- VKEY_QUOTE = '\'',
- VKEY_LEFTPAREN = '(',
- VKEY_RIGHTPAREN = ')',
- VKEY_ASTERISK = '*',
- VKEY_PLUS = '+',
- VKEY_COMMA = ',',
- VKEY_MINUS = '-',
- VKEY_PERIOD = '.',
- VKEY_SLASH = '/',
- VKEY_0 = '0',
- VKEY_1 = '1',
- VKEY_2 = '2',
- VKEY_3 = '3',
- VKEY_4 = '4',
- VKEY_5 = '5',
- VKEY_6 = '6',
- VKEY_7 = '7',
- VKEY_8 = '8',
- VKEY_9 = '9',
- VKEY_COLON = ':',
- VKEY_SEMICOLON = ';',
- VKEY_LESS = '<',
- VKEY_EQUALS = '=',
- VKEY_GREATER = '>',
- VKEY_QUESTION = '?',
- VKEY_AT = '@',
- /*
- Skip uppercase letters
- */
- VKEY_LEFTBRACKET = '[',
- VKEY_BACKSLASH = '\\',
- VKEY_RIGHTBRACKET = ']',
- VKEY_CARET = '^',
- VKEY_UNDERSCORE = '_',
- VKEY_BACKQUOTE = '`',
- VKEY_a = 'a',
- VKEY_b = 'b',
- VKEY_c = 'c',
- VKEY_d = 'd',
- VKEY_e = 'e',
- VKEY_f = 'f',
- VKEY_g = 'g',
- VKEY_h = 'h',
- VKEY_i = 'i',
- VKEY_j = 'j',
- VKEY_k = 'k',
- VKEY_l = 'l',
- VKEY_m = 'm',
- VKEY_n = 'n',
- VKEY_o = 'o',
- VKEY_p = 'p',
- VKEY_q = 'q',
- VKEY_r = 'r',
- VKEY_s = 's',
- VKEY_t = 't',
- VKEY_u = 'u',
- VKEY_v = 'v',
- VKEY_w = 'w',
- VKEY_x = 'x',
- VKEY_y = 'y',
- VKEY_z = 'z',
- VKEY_CAPSLOCK = KIT_PKEY_TO_VKEY(PKEY_CAPSLOCK),
- VKEY_F1 = KIT_PKEY_TO_VKEY(PKEY_F1),
- VKEY_F2 = KIT_PKEY_TO_VKEY(PKEY_F2),
- VKEY_F3 = KIT_PKEY_TO_VKEY(PKEY_F3),
- VKEY_F4 = KIT_PKEY_TO_VKEY(PKEY_F4),
- VKEY_F5 = KIT_PKEY_TO_VKEY(PKEY_F5),
- VKEY_F6 = KIT_PKEY_TO_VKEY(PKEY_F6),
- VKEY_F7 = KIT_PKEY_TO_VKEY(PKEY_F7),
- VKEY_F8 = KIT_PKEY_TO_VKEY(PKEY_F8),
- VKEY_F9 = KIT_PKEY_TO_VKEY(PKEY_F9),
- VKEY_F10 = KIT_PKEY_TO_VKEY(PKEY_F10),
- VKEY_F11 = KIT_PKEY_TO_VKEY(PKEY_F11),
- VKEY_F12 = KIT_PKEY_TO_VKEY(PKEY_F12),
- VKEY_PRINTSCREEN = KIT_PKEY_TO_VKEY(PKEY_PRINTSCREEN),
- VKEY_SCROLLLOCK = KIT_PKEY_TO_VKEY(PKEY_SCROLLLOCK),
- VKEY_PAUSE = KIT_PKEY_TO_VKEY(PKEY_PAUSE),
- VKEY_INSERT = KIT_PKEY_TO_VKEY(PKEY_INSERT),
- VKEY_HOME = KIT_PKEY_TO_VKEY(PKEY_HOME),
- VKEY_PAGEUP = KIT_PKEY_TO_VKEY(PKEY_PAGEUP),
- VKEY_DELETE = '\x7F',
- VKEY_END = KIT_PKEY_TO_VKEY(PKEY_END),
- VKEY_PAGEDOWN = KIT_PKEY_TO_VKEY(PKEY_PAGEDOWN),
- VKEY_RIGHT = KIT_PKEY_TO_VKEY(PKEY_RIGHT),
- VKEY_LEFT = KIT_PKEY_TO_VKEY(PKEY_LEFT),
- VKEY_DOWN = KIT_PKEY_TO_VKEY(PKEY_DOWN),
- VKEY_UP = KIT_PKEY_TO_VKEY(PKEY_UP),
- VKEY_NUMLOCKCLEAR = KIT_PKEY_TO_VKEY(PKEY_NUMLOCKCLEAR),
- VKEY_KP_DIVIDE = KIT_PKEY_TO_VKEY(PKEY_KP_DIVIDE),
- VKEY_KP_MULTIPLY = KIT_PKEY_TO_VKEY(PKEY_KP_MULTIPLY),
- VKEY_KP_MINUS = KIT_PKEY_TO_VKEY(PKEY_KP_MINUS),
- VKEY_KP_PLUS = KIT_PKEY_TO_VKEY(PKEY_KP_PLUS),
- VKEY_KP_ENTER = KIT_PKEY_TO_VKEY(PKEY_KP_ENTER),
- VKEY_KP_1 = KIT_PKEY_TO_VKEY(PKEY_KP_1),
- VKEY_KP_2 = KIT_PKEY_TO_VKEY(PKEY_KP_2),
- VKEY_KP_3 = KIT_PKEY_TO_VKEY(PKEY_KP_3),
- VKEY_KP_4 = KIT_PKEY_TO_VKEY(PKEY_KP_4),
- VKEY_KP_5 = KIT_PKEY_TO_VKEY(PKEY_KP_5),
- VKEY_KP_6 = KIT_PKEY_TO_VKEY(PKEY_KP_6),
- VKEY_KP_7 = KIT_PKEY_TO_VKEY(PKEY_KP_7),
- VKEY_KP_8 = KIT_PKEY_TO_VKEY(PKEY_KP_8),
- VKEY_KP_9 = KIT_PKEY_TO_VKEY(PKEY_KP_9),
- VKEY_KP_0 = KIT_PKEY_TO_VKEY(PKEY_KP_0),
- VKEY_KP_PERIOD = KIT_PKEY_TO_VKEY(PKEY_KP_PERIOD),
- VKEY_APPLICATION = KIT_PKEY_TO_VKEY(PKEY_APPLICATION),
- VKEY_POWER = KIT_PKEY_TO_VKEY(PKEY_POWER),
- VKEY_KP_EQUALS = KIT_PKEY_TO_VKEY(PKEY_KP_EQUALS),
- VKEY_F13 = KIT_PKEY_TO_VKEY(PKEY_F13),
- VKEY_F14 = KIT_PKEY_TO_VKEY(PKEY_F14),
- VKEY_F15 = KIT_PKEY_TO_VKEY(PKEY_F15),
- VKEY_F16 = KIT_PKEY_TO_VKEY(PKEY_F16),
- VKEY_F17 = KIT_PKEY_TO_VKEY(PKEY_F17),
- VKEY_F18 = KIT_PKEY_TO_VKEY(PKEY_F18),
- VKEY_F19 = KIT_PKEY_TO_VKEY(PKEY_F19),
- VKEY_F20 = KIT_PKEY_TO_VKEY(PKEY_F20),
- VKEY_F21 = KIT_PKEY_TO_VKEY(PKEY_F21),
- VKEY_F22 = KIT_PKEY_TO_VKEY(PKEY_F22),
- VKEY_F23 = KIT_PKEY_TO_VKEY(PKEY_F23),
- VKEY_F24 = KIT_PKEY_TO_VKEY(PKEY_F24),
- VKEY_EXECUTE = KIT_PKEY_TO_VKEY(PKEY_EXECUTE),
- VKEY_HELP = KIT_PKEY_TO_VKEY(PKEY_HELP),
- VKEY_MENU = KIT_PKEY_TO_VKEY(PKEY_MENU),
- VKEY_SELECT = KIT_PKEY_TO_VKEY(PKEY_SELECT),
- VKEY_STOP = KIT_PKEY_TO_VKEY(PKEY_STOP),
- VKEY_AGAIN = KIT_PKEY_TO_VKEY(PKEY_AGAIN),
- VKEY_UNDO = KIT_PKEY_TO_VKEY(PKEY_UNDO),
- VKEY_CUT = KIT_PKEY_TO_VKEY(PKEY_CUT),
- VKEY_COPY = KIT_PKEY_TO_VKEY(PKEY_COPY),
- VKEY_PASTE = KIT_PKEY_TO_VKEY(PKEY_PASTE),
- VKEY_FIND = KIT_PKEY_TO_VKEY(PKEY_FIND),
- VKEY_MUTE = KIT_PKEY_TO_VKEY(PKEY_MUTE),
- VKEY_VOLUMEUP = KIT_PKEY_TO_VKEY(PKEY_VOLUMEUP),
- VKEY_VOLUMEDOWN = KIT_PKEY_TO_VKEY(PKEY_VOLUMEDOWN),
- VKEY_KP_COMMA = KIT_PKEY_TO_VKEY(PKEY_KP_COMMA),
- VKEY_KP_EQUALSAS400 = KIT_PKEY_TO_VKEY(PKEY_KP_EQUALSAS400),
- VKEY_ALTERASE = KIT_PKEY_TO_VKEY(PKEY_ALTERASE),
- VKEY_SYSREQ = KIT_PKEY_TO_VKEY(PKEY_SYSREQ),
- VKEY_CANCEL = KIT_PKEY_TO_VKEY(PKEY_CANCEL),
- VKEY_CLEAR = KIT_PKEY_TO_VKEY(PKEY_CLEAR),
- VKEY_PRIOR = KIT_PKEY_TO_VKEY(PKEY_PRIOR),
- VKEY_RETURN2 = KIT_PKEY_TO_VKEY(PKEY_RETURN2),
- VKEY_SEPARATOR = KIT_PKEY_TO_VKEY(PKEY_SEPARATOR),
- VKEY_OUT = KIT_PKEY_TO_VKEY(PKEY_OUT),
- VKEY_OPER = KIT_PKEY_TO_VKEY(PKEY_OPER),
- VKEY_CLEARAGAIN = KIT_PKEY_TO_VKEY(PKEY_CLEARAGAIN),
- VKEY_CRSEL = KIT_PKEY_TO_VKEY(PKEY_CRSEL),
- VKEY_EXSEL = KIT_PKEY_TO_VKEY(PKEY_EXSEL),
- VKEY_KP_00 = KIT_PKEY_TO_VKEY(PKEY_KP_00),
- VKEY_KP_000 = KIT_PKEY_TO_VKEY(PKEY_KP_000),
- VKEY_THOUSANDSSEPARATOR = KIT_PKEY_TO_VKEY(PKEY_THOUSANDSSEPARATOR),
- VKEY_DECIMALSEPARATOR = KIT_PKEY_TO_VKEY(PKEY_DECIMALSEPARATOR),
- VKEY_CURRENCYUNIT = KIT_PKEY_TO_VKEY(PKEY_CURRENCYUNIT),
- VKEY_CURRENCYSUBUNIT = KIT_PKEY_TO_VKEY(PKEY_CURRENCYSUBUNIT),
- VKEY_KP_LEFTPAREN = KIT_PKEY_TO_VKEY(PKEY_KP_LEFTPAREN),
- VKEY_KP_RIGHTPAREN = KIT_PKEY_TO_VKEY(PKEY_KP_RIGHTPAREN),
- VKEY_KP_LEFTBRACE = KIT_PKEY_TO_VKEY(PKEY_KP_LEFTBRACE),
- VKEY_KP_RIGHTBRACE = KIT_PKEY_TO_VKEY(PKEY_KP_RIGHTBRACE),
- VKEY_KP_TAB = KIT_PKEY_TO_VKEY(PKEY_KP_TAB),
- VKEY_KP_BACKSPACE = KIT_PKEY_TO_VKEY(PKEY_KP_BACKSPACE),
- VKEY_KP_A = KIT_PKEY_TO_VKEY(PKEY_KP_A),
- VKEY_KP_B = KIT_PKEY_TO_VKEY(PKEY_KP_B),
- VKEY_KP_C = KIT_PKEY_TO_VKEY(PKEY_KP_C),
- VKEY_KP_D = KIT_PKEY_TO_VKEY(PKEY_KP_D),
- VKEY_KP_E = KIT_PKEY_TO_VKEY(PKEY_KP_E),
- VKEY_KP_F = KIT_PKEY_TO_VKEY(PKEY_KP_F),
- VKEY_KP_XOR = KIT_PKEY_TO_VKEY(PKEY_KP_XOR),
- VKEY_KP_POWER = KIT_PKEY_TO_VKEY(PKEY_KP_POWER),
- VKEY_KP_PERCENT = KIT_PKEY_TO_VKEY(PKEY_KP_PERCENT),
- VKEY_KP_LESS = KIT_PKEY_TO_VKEY(PKEY_KP_LESS),
- VKEY_KP_GREATER = KIT_PKEY_TO_VKEY(PKEY_KP_GREATER),
- VKEY_KP_AMPERSAND = KIT_PKEY_TO_VKEY(PKEY_KP_AMPERSAND),
- VKEY_KP_DBLAMPERSAND = KIT_PKEY_TO_VKEY(PKEY_KP_DBLAMPERSAND),
- VKEY_KP_VERTICALBAR = KIT_PKEY_TO_VKEY(PKEY_KP_VERTICALBAR),
- VKEY_KP_DBLVERTICALBAR = KIT_PKEY_TO_VKEY(PKEY_KP_DBLVERTICALBAR),
- VKEY_KP_COLON = KIT_PKEY_TO_VKEY(PKEY_KP_COLON),
- VKEY_KP_HASH = KIT_PKEY_TO_VKEY(PKEY_KP_HASH),
- VKEY_KP_SPACE = KIT_PKEY_TO_VKEY(PKEY_KP_SPACE),
- VKEY_KP_AT = KIT_PKEY_TO_VKEY(PKEY_KP_AT),
- VKEY_KP_EXCLAM = KIT_PKEY_TO_VKEY(PKEY_KP_EXCLAM),
- VKEY_KP_MEMSTORE = KIT_PKEY_TO_VKEY(PKEY_KP_MEMSTORE),
- VKEY_KP_MEMRECALL = KIT_PKEY_TO_VKEY(PKEY_KP_MEMRECALL),
- VKEY_KP_MEMCLEAR = KIT_PKEY_TO_VKEY(PKEY_KP_MEMCLEAR),
- VKEY_KP_MEMADD = KIT_PKEY_TO_VKEY(PKEY_KP_MEMADD),
- VKEY_KP_MEMSUBTRACT = KIT_PKEY_TO_VKEY(PKEY_KP_MEMSUBTRACT),
- VKEY_KP_MEMMULTIPLY = KIT_PKEY_TO_VKEY(PKEY_KP_MEMMULTIPLY),
- VKEY_KP_MEMDIVIDE = KIT_PKEY_TO_VKEY(PKEY_KP_MEMDIVIDE),
- VKEY_KP_PLUSMINUS = KIT_PKEY_TO_VKEY(PKEY_KP_PLUSMINUS),
- VKEY_KP_CLEAR = KIT_PKEY_TO_VKEY(PKEY_KP_CLEAR),
- VKEY_KP_CLEARENTRY = KIT_PKEY_TO_VKEY(PKEY_KP_CLEARENTRY),
- VKEY_KP_BINARY = KIT_PKEY_TO_VKEY(PKEY_KP_BINARY),
- VKEY_KP_OCTAL = KIT_PKEY_TO_VKEY(PKEY_KP_OCTAL),
- VKEY_KP_DECIMAL = KIT_PKEY_TO_VKEY(PKEY_KP_DECIMAL),
- VKEY_KP_HEXADECIMAL = KIT_PKEY_TO_VKEY(PKEY_KP_HEXADECIMAL),
- VKEY_LCTRL = KIT_PKEY_TO_VKEY(PKEY_LCTRL),
- VKEY_LSHIFT = KIT_PKEY_TO_VKEY(PKEY_LSHIFT),
- VKEY_LALT = KIT_PKEY_TO_VKEY(PKEY_LALT),
- VKEY_LGUI = KIT_PKEY_TO_VKEY(PKEY_LGUI),
- VKEY_RCTRL = KIT_PKEY_TO_VKEY(PKEY_RCTRL),
- VKEY_RSHIFT = KIT_PKEY_TO_VKEY(PKEY_RSHIFT),
- VKEY_RALT = KIT_PKEY_TO_VKEY(PKEY_RALT),
- VKEY_RGUI = KIT_PKEY_TO_VKEY(PKEY_RGUI),
- VKEY_MODE = KIT_PKEY_TO_VKEY(PKEY_MODE),
- VKEY_AUDIONEXT = KIT_PKEY_TO_VKEY(PKEY_AUDIONEXT),
- VKEY_AUDIOPREV = KIT_PKEY_TO_VKEY(PKEY_AUDIOPREV),
- VKEY_AUDIOSTOP = KIT_PKEY_TO_VKEY(PKEY_AUDIOSTOP),
- VKEY_AUDIOPLAY = KIT_PKEY_TO_VKEY(PKEY_AUDIOPLAY),
- VKEY_AUDIOMUTE = KIT_PKEY_TO_VKEY(PKEY_AUDIOMUTE),
- VKEY_MEDIASELECT = KIT_PKEY_TO_VKEY(PKEY_MEDIASELECT),
- VKEY_WWW = KIT_PKEY_TO_VKEY(PKEY_WWW),
- VKEY_MAIL = KIT_PKEY_TO_VKEY(PKEY_MAIL),
- VKEY_CALCULATOR = KIT_PKEY_TO_VKEY(PKEY_CALCULATOR),
- VKEY_COMPUTER = KIT_PKEY_TO_VKEY(PKEY_COMPUTER),
- VKEY_AC_SEARCH = KIT_PKEY_TO_VKEY(PKEY_AC_SEARCH),
- VKEY_AC_HOME = KIT_PKEY_TO_VKEY(PKEY_AC_HOME),
- VKEY_AC_BACK = KIT_PKEY_TO_VKEY(PKEY_AC_BACK),
- VKEY_AC_FORWARD = KIT_PKEY_TO_VKEY(PKEY_AC_FORWARD),
- VKEY_AC_STOP = KIT_PKEY_TO_VKEY(PKEY_AC_STOP),
- VKEY_AC_REFRESH = KIT_PKEY_TO_VKEY(PKEY_AC_REFRESH),
- VKEY_AC_BOOKMARKS = KIT_PKEY_TO_VKEY(PKEY_AC_BOOKMARKS),
- VKEY_BRIGHTNESSDOWN = KIT_PKEY_TO_VKEY(PKEY_BRIGHTNESSDOWN),
- VKEY_BRIGHTNESSUP = KIT_PKEY_TO_VKEY(PKEY_BRIGHTNESSUP),
- VKEY_DISPLAYSWITCH = KIT_PKEY_TO_VKEY(PKEY_DISPLAYSWITCH),
- VKEY_KBDILLUMTOGGLE = KIT_PKEY_TO_VKEY(PKEY_KBDILLUMTOGGLE),
- VKEY_KBDILLUMDOWN = KIT_PKEY_TO_VKEY(PKEY_KBDILLUMDOWN),
- VKEY_KBDILLUMUP = KIT_PKEY_TO_VKEY(PKEY_KBDILLUMUP),
- VKEY_EJECT = KIT_PKEY_TO_VKEY(PKEY_EJECT),
- VKEY_SLEEP = KIT_PKEY_TO_VKEY(PKEY_SLEEP),
- VKEY_APP1 = KIT_PKEY_TO_VKEY(PKEY_APP1),
- VKEY_APP2 = KIT_PKEY_TO_VKEY(PKEY_APP2),
- VKEY_AUDIOREWIND = KIT_PKEY_TO_VKEY(PKEY_AUDIOREWIND),
- VKEY_AUDIOFASTFORWARD = KIT_PKEY_TO_VKEY(PKEY_AUDIOFASTFORWARD),
- VKEY_SOFTLEFT = KIT_PKEY_TO_VKEY(PKEY_SOFTLEFT),
- VKEY_SOFTRIGHT = KIT_PKEY_TO_VKEY(PKEY_SOFTRIGHT),
- VKEY_CALL = KIT_PKEY_TO_VKEY(PKEY_CALL),
- VKEY_ENDCALL = KIT_PKEY_TO_VKEY(PKEY_ENDCALL),
- };
- enum Event_Key_ModifierFlagsEnum {
- KEYMOD_NONE = 0x0000,
- KEYMOD_LSHIFT = 0x0001,
- KEYMOD_RSHIFT = 0x0002,
- //(4 bits are skipped here)
- KEYMOD_LCTRL = 0x0040,
- KEYMOD_RCTRL = 0x0080,
- KEYMOD_LALT = 0x0100,
- KEYMOD_RALT = 0x0200,
- KEYMOD_LGUI = 0x0400,
- KEYMOD_RGUI = 0x0800,
- KEYMOD_LWIN = KEYMOD_LGUI,
- KEYMOD_RWIN = KEYMOD_RGUI,
- KEYMOD_NUM = 0x1000, //num lock
- KEYMOD_CAPS = 0x2000, //caps lock
- KEYMOD_MODE = 0x4000, //altgraph
- KEYMOD_SCROLL = 0x8000, //scroll lock
- KEYMOD_CTRL = ( KEYMOD_LCTRL | KEYMOD_RCTRL ),
- KEYMOD_SHIFT = ( KEYMOD_LSHIFT | KEYMOD_RSHIFT ),
- KEYMOD_ALT = ( KEYMOD_LALT | KEYMOD_RALT ),
- KEYMOD_GUI = ( KEYMOD_LGUI | KEYMOD_RGUI ),
- KEYMOD_WIN = ( KEYMOD_LWIN | KEYMOD_RWIN ),
- };
- union Event_Key_Mod { //2B
- struct {
- //low byte
- u16 lshift : 1;
- u16 rshift : 1;
- u16 _unused : 4;
- u16 lctrl : 1;
- u16 rctrl : 1;
- //high byte
- u16 lalt : 1;
- u16 ralt : 1;
- u16 lgui : 1;
- u16 rgui : 1;
- u16 num : 1;
- u16 caps : 1;
- u16 mode : 1;
- u16 scroll : 1;
- };
- u16 all;
- };
- struct Event_Key_Sym { //8B
- s32 vkey; //virtual key code
- u16 pkey; //physical key code (scancode)
- union { //some combination of Event_Key_ModifiersEnum flags (if any)
- u16 kmods;
- Event_Key_Mod kmod;
- };
- };
- struct Event_Key { //24B
- u32 type;
- u32 timestamp;
- u32 window; //window with keyboard focus, if any
- bool pressed; //key was released otherwise
- bool repeat; //'is this the result of holding a key down?' (useful for text input!)
- u16 _padding16;
- union {
- struct {
- s32 vkey; //virtual key code
- u16 pkey; //physical key code (scancode)
- u16 kmods; //some combination of Event_Key_ModifiersEnum flags (if any)
- };
- Event_Key_Sym sym;
- };
- };
- /*-KEVENT_KEY-*/
- /*+KEVENT_MOUSE+*/
- //for KEVENT_MOUSE_MOVED events, multiple of these
- //flags can be active simultaneously, whereas
- //for MOUSE_UP/DOWN events, only <=1 can be set
- enum Event_Mouse_ButtonFlagsEnum {
- MOUSE_BUTTON_LEFT = 0x01,
- MOUSE_BUTTON_MIDDLE = 0x02,
- MOUSE_BUTTON_RIGHT = 0x04,
- MOUSE_BUTTON_X1 = 0x08,
- MOUSE_BUTTON_X2 = 0x10,
- };
- //(internal note: mouse instance IDs are ignored)
- struct Event_Mouse { //40B
- u32 type;
- u32 timestamp;
- u32 window; //current window with mouse focus, if any
- u8 button; //which mouse button(s) are pressed (see Event_Mouse_ButtonFlagsEnum)
- bool pressed; //otherwise button was released
- bool dblClick; //'is double click?' (single click otherwise);
- bool flipped; //indicates whether x or y are flipped during mouse wheel events (*=-1 to flip back)
- s32 x, y; //coordinates, relative to window
- s32 dx, dy; //delta x&y (coordinates relative to last recorded position)
- f32 pdx, pdy; //precise delta x&y (only set by MOUSE_WHEEL events)
- };
- /*-KEVENT_MOUSE-*/
- /*+KEVENT_JOY+*/
- enum Event_Joystick_BatteryEnum {
- JOY_BATTERY_UNKNOWN = -1,
- JOY_BATTERY_EMPTY, // <= 5%
- JOY_BATTERY_LOW, // <= 20%
- JOY_BATTERY_MEDIUM, // <= 70%
- JOY_BATTERY_FULL, // <= 100%
- JOY_BATTERY_WIRED,
- JOY_BATTERY_MAX,
- };
- enum Event_Joystick_HatEnum {
- JOY_HAT_CENTERED = 0x00,
- JOY_HAT_UP = 0x01,
- JOY_HAT_RIGHT = 0x02,
- JOY_HAT_DOWN = 0x04,
- JOY_HAT_LEFT = 0x08,
- JOY_HAT_RIGHTUP = (JOY_HAT_RIGHT|JOY_HAT_UP ),
- JOY_HAT_RIGHTDOWN = (JOY_HAT_RIGHT|JOY_HAT_DOWN),
- JOY_HAT_LEFTUP = (JOY_HAT_LEFT |JOY_HAT_UP ),
- JOY_HAT_LEFTDOWN = (JOY_HAT_LEFT |JOY_HAT_DOWN),
- };
- struct Event_Joystick_Axis { //4B
- u8 which;
- u8 _padding8;
- s16 value;
- } __attribute__((packed));
- struct Event_Joystick_Trackball { //12B
- u8 which;
- u8 _padding8;
- s16 dx, dy; //movement delta
- u16 _padding16; //(extra explicit padding added, since
- u32 _padding32; //trackball is the largest subevent)
- } __attribute__((packed));
- struct Event_Joystick_Hat { //2B
- u8 which;
- u8 value; //see Event_Joystick_HatEnum
- } __attribute__((packed));
- struct Event_Joystick_Button { //2B
- u8 which;
- bool pressed;
- } __attribute__((packed));
- struct Event_Joystick_Device { //2B
- u8 _padding8;
- bool added; //device was removed if false
- } __attribute__((packed));
- struct Event_Joystick_Battery { //2B
- u8 _padding8;
- s8 level; //see Event_Joystick_BatteryEnum
- } __attribute__((packed));
- struct Event_Joystick { //24B
- u32 type;
- u32 timestamp;
- u32 id; //associated joystick instance
- union {
- Event_Joystick_Axis axis; // 4B
- Event_Joystick_Trackball trackball; //12B
- Event_Joystick_Hat hat; // 2B
- Event_Joystick_Button button; // 2B
- Event_Joystick_Device device; // 2B; redundant, but included for consistency
- Event_Joystick_Battery battery; // 2B
- };
- };
- /*-KEVENT_JOY-*/
- /*+KEVENT_CTLR+*/
- enum Event_GameController_AxisEnum {
- CTLR_AXIS_INVALID = -1,
- CTLR_AXIS_LEFTX,
- CTLR_AXIS_LEFTY,
- CTLR_AXIS_RIGHTX,
- CTLR_AXIS_RIGHTY,
- CTLR_AXIS_TRIGGERLEFT,
- CTLR_AXIS_TRIGGERRIGHT,
- CTLR_AXIS_MAX,
- };
- enum Event_GameController_ButtonEnum {
- CTLR_BUTTON_INVALID = -1,
- CTLR_BUTTON_A,
- CTLR_BUTTON_B,
- CTLR_BUTTON_X,
- CTLR_BUTTON_Y,
- CTLR_BUTTON_BACK,
- CTLR_BUTTON_GUIDE,
- CTLR_BUTTON_START,
- CTLR_BUTTON_LEFTSTICK,
- CTLR_BUTTON_RIGHTSTICK,
- CTLR_BUTTON_LEFTSHOULDER,
- CTLR_BUTTON_RIGHTSHOULDER,
- CTLR_BUTTON_DPAD_UP,
- CTLR_BUTTON_DPAD_DOWN,
- CTLR_BUTTON_DPAD_LEFT,
- CTLR_BUTTON_DPAD_RIGHT,
- CTLR_BUTTON_MISC1, //Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button
- CTLR_BUTTON_PADDLE1, //Xbox Elite paddle P1 (upper left, facing the back)
- CTLR_BUTTON_PADDLE2, //Xbox Elite paddle P3 (upper right, facing the back)
- CTLR_BUTTON_PADDLE3, //Xbox Elite paddle P2 (lower left, facing the back)
- CTLR_BUTTON_PADDLE4, //Xbox Elite paddle P4 (lower right, facing the back)
- CTLR_BUTTON_TOUCHPAD, //PS4/PS5 touchpad button
- CTLR_BUTTON_MAX,
- };
- enum Event_GameController_SensorEnum {
- CTLR_SENSOR_INVALID = -1, //Returned for an invalid sensor
- CTLR_SENSOR_UNKNOWN, //Unknown sensor type
- CTLR_SENSOR_ACCEL, //Accelerometer
- CTLR_SENSOR_GYRO, //Gyroscope
- CTLR_SENSOR_ACCEL_L, //Accelerometer for left Joy-Con controller and Wii nunchuk
- CTLR_SENSOR_GYRO_L, //Gyroscope for left Joy-Con controller
- CTLR_SENSOR_ACCEL_R, //Accelerometer for right Joy-Con controller
- CTLR_SENSOR_GYRO_R, //Gyroscope for right Joy-Con controller
- };
- /**
- * Accelerometer sensor
- *
- * The accelerometer returns the current acceleration in SI meters per
- * second squared. This measurement includes the force of gravity, so
- * a device at rest will have an value of KIT_STANDARD_GRAVITY away
- * from the center of the earth, which is a positive Y value.
- *
- * values[0]: Acceleration on the x axis
- * values[1]: Acceleration on the y axis
- * values[2]: Acceleration on the z axis
- *
- * For phones held in portrait mode and game controllers held in front of you,
- * the axes are defined as follows:
- * -X ... +X : left ... right
- * -Y ... +Y : bottom ... top
- * -Z ... +Z : farther ... closer
- *
- * The axis data is not changed when the phone is rotated.
- */
- //#define SDL_STANDARD_GRAVITY 9.80665f
- #define KIT_STANDARD_GRAVITY 9.80665f //for macro naming consistency
- /**
- * Gyroscope sensor
- *
- * The gyroscope returns the current rate of rotation in radians per second.
- * The rotation is positive in the counter-clockwise direction. That is,
- * an observer looking from a positive location on one of the axes would
- * see positive rotation on that axis when it appeared to be rotating
- * counter-clockwise.
- *
- * values[0]: Angular speed around the x axis (pitch)
- * values[1]: Angular speed around the y axis (yaw)
- * values[2]: Angular speed around the z axis (roll)
- *
- * For phones held in portrait mode and game controllers held in front of you,
- * the axes are defined as follows:
- * -X ... +X : left ... right
- * -Y ... +Y : bottom ... top
- * -Z ... +Z : farther ... closer
- *
- * The axis data is not changed when the phone or controller is rotated.
- */
- struct Event_GameController_Axis { //4B
- u8 which; //see Event_GameController_AxisEnum
- u8 _padding8;
- s16 value;
- } __attribute__((packed));
- struct Event_GameController_Button { //2B
- u8 which; //see Event_GameController_ButtonEnum
- bool pressed;
- } __attribute__((packed));
- struct Event_GameController_Device { //2B
- u16 subtype; //lower 16-bits of .type
- } __attribute__((packed));
- struct Event_GameController_Touchpad { //20B
- s32 which;
- s32 finger;
- f32 x, y; //from top-left going southeast, normalized; 0.0f -> 1.0f
- f32 pressure;
- } __attribute__((packed));
- struct Event_GameController_Sensor { //28B
- s32 which; //see Event_GameController_SensorEnum
- u32 _padding32;
- f32 data[3];
- u64 timestamp_us; //time at the point of sensor read, in microseconds
- //(if the hardware provides that information)
- } __attribute__((packed));
- struct Event_GameController { //40B
- u32 type;
- u32 timestamp;
- s32 id; //joystick instance id (unless subtype is DEVICE_x)
- //^^ specifically for DEVICE_x:
- // joy device index for ADDED, instance id for REMOVED/REMAPPED
- union {
- Event_GameController_Axis axis; // 4B
- Event_GameController_Button button; // 2B
- Event_GameController_Device device; // 2B; redundant, but included for consistency
- Event_GameController_Touchpad touchpad; //20B
- Event_GameController_Sensor sensor; //28B
- };
- };
- /*-KEVENT_CTLR-*/
- /*+KEVENT_ADEV+*/
- struct Event_AudioDevice { //16B
- u32 type;
- u32 timestamp;
- u32 id;
- bool isInput; //false = output/rendering, true = input/recording
- u8 _padding8;
- u16 _padding16;
- };
- /*-KEVENT_ADEV-*/
- /*+KEVENT_DROP+*/
- struct Event_Drop { //24B
- u32 type;
- u32 timestamp;
- char* filePath; //should be freed with memory::free; nullptr on DROP_BEGIN/COMPLETE
- u32 window; //which window the file was dropped on, if any
- u32 _padding32;
- };
- /*-KEVENT_DROP-*/
- /*+KEVENT_QUIT+*/
- struct Event_Quit { //8B
- u32 type;
- u32 timestamp;
- };
- /*-KEVENT_QUIT-*/
- /*+KEVENT_USER+*/
- struct Event_User { //24B
- u32 type;
- u32 timestamp;
- u32 window;
- s32 id; //user-defined
- void* data1; //user-defined
- void* data2; //user-defined
- };
- /*-KEVENT_USER-*/
- union Event { //<whatever the largest event is>B
- struct {
- u32 type;
- u32 timestamp;
- };
- Event_Common common; // 8B
- Event_Display display; //16B
- Event_Window win; //24B
- Event_Key key; //24B
- Event_Mouse mouse; //40B
- Event_Joystick joy; //24B
- Event_GameController ctlr; //40B
- Event_AudioDevice adev; //16B
- Event_Drop drop; //24B
- Event_Quit quit; // 8B
- Event_User user; //24B
- Event() : type(KEVENT_NULL) {}
- };
- }; /* namespace kit */
- #endif /* _INC__MISC_EVENT_HPP */
Add Comment
Please, Sign In to add comment