diff 0d98a32151079982dd23af0f3eca91b971eb1d6b uncommitted --- a/include/npe/SDL2/SDL.h +++ b/include/npe/SDL2/SDL.h @@ -179,6 +179,7 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect); int SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch); int SDL_UnlockTexture(SDL_Texture *texture); +int SDL_GetWindowBordersSize(SDL_Window *window, int *top, int *left, int *bot, int *right); enum { SDL_QUERY = -1, @@ -194,6 +195,9 @@ SDL_WINDOW_SHOWN = 1<<4, SDL_WINDOW_RESIZABLE = 1<<5, SDL_WINDOW_HIDDEN = 1<<6, + SDL_WINDOW_MAXIMIZED = 1<<7, + SDL_WINDOW_FULLSCREEN = 1<<8, + SDL_WINDOW_BORDERLESS = 1<<9, SDL_WINDOWPOS_CENTERED = -1, SDL_WINDOWPOS_UNDEFINED = -2, @@ -202,6 +206,7 @@ SDL_INIT_AUDIO = 1<<1, SDL_INIT_VIDEO = 1<<2, SDL_INIT_JOYSTICK = 0, + SDL_INIT_GAMECONTROLLER = 0, SDL_BLENDMODE_NONE = 0, SDL_BLENDMODE_BLEND, @@ -321,5 +326,18 @@ struct SDL_mutex { Lock l; }; + +typedef enum { + SDL_HITTEST_NORMAL, + SDL_HITTEST_DRAGGABLE, + SDL_HITTEST_RESIZE_TOPLEFT, + SDL_HITTEST_RESIZE_TOP, + SDL_HITTEST_RESIZE_TOPRIGHT, + SDL_HITTEST_RESIZE_RIGHT, + SDL_HITTEST_RESIZE_BOTTOMRIGHT, + SDL_HITTEST_RESIZE_BOTTOM, + SDL_HITTEST_RESIZE_BOTTOMLEFT, + SDL_HITTEST_RESIZE_LEFT, +} SDL_HitTestResult; #endif --- a/include/npe/SDL2/SDL_events.h +++ b/include/npe/SDL2/SDL_events.h @@ -151,5 +151,6 @@ SDL_Scancode SDL_GetScancodeFromKey(SDL_Keycode key); Uint8* SDL_GetKeyboardState(int *numkeys); char* SDL_GetKeyName(SDL_Keycode key); +SDL_Keycode SDL_GetKeyFromName(char *name); #endif --- a/include/npe/SDL2/SDL_mixer.h +++ b/include/npe/SDL2/SDL_mixer.h @@ -46,6 +46,8 @@ MIX_INIT_MID = 1, MIX_DEFAULT_FORMAT = 1, + + SDL_MIX_MAXVOLUME = 100, }; #endif --- a/include/npe/errno.h +++ b/include/npe/errno.h @@ -5,6 +5,7 @@ enum { ENOENT = 2, + EACCES = 13, EINVAL = 22, ERANGE = 34, ENAMETOOLONG = 36, --- a/libnpe_sdl2/events.c +++ b/libnpe_sdl2/events.c @@ -315,10 +315,107 @@ char* SDL_GetKeyName(SDL_Keycode key) { - USED(key); - return ""; /* FIXME */ + /* upstream quirk: return value is valid only until next call */ + static char res[64]; + + res[0] = res[1] = '\0'; + if(key >= '0' && key <= '9' || key == '-' || key == '=' || key == '\'') + res[0] = key; + else if(key == '[' || key == ']' || key == '\\' || key == ';' || key == '/') + res[0] = key; + else if(key >= 'a' && key <= 'z') + res[0] = toupper(key); + else if(key >= (KF|1) && key <= (KF|12)) + snprint(res, sizeof(res), "F%d", key - KF); + else if(key == '\n') + return "Return"; + else if(key == Kesc) + return "Escape"; + else if(key == Kbs) + return "Backspace"; + else if(key == '\t') + return "Tab"; + else if(key == ' ') + return "Space"; + else if(key == Kright) + return "Right"; + else if(key == Kleft) + return "Left"; + else if(key == Kup) + return "Up"; + else if(key == Kdown) + return "Down"; + else if(key == Kins) + return "Insert"; + else if(key == Khome) + return "Home"; + else if(key == Kpgup) + return "PageUp"; + else if(key == Kpgdown) + return "PageDown"; + else if(key == Kdel) + return "Delete"; + else if(key == Kend) + return "End"; + else if(key == Kalt) + return "Left Alt"; + else if(key == Kctl) + return "Left Ctrl"; + else if(key == Kmod4) + return "Left GUI"; + else if(key == Kaltgr) + return "Right Alt"; + else if(key == Kshift) + return "Left Shift"; + + return res; } +SDL_Keycode +SDL_GetKeyFromName(char *name) +{ + char *e; + long p; + + if(strcmp(name, "Return") == 0) return '\n'; + if(strcmp(name, "Escape") == 0) return Kesc; + if(strcmp(name, "Backspace") == 0) return Kbs; + if(strcmp(name, "Tab") == 0) return '\t'; + if(strcmp(name, "Space") == 0) return ' '; + if(strcmp(name, "Right") == 0) return Kright; + if(strcmp(name, "Left") == 0) return Kleft; + if(strcmp(name, "Up") == 0) return Kup; + if(strcmp(name, "Down") == 0) return Kdown; + if(strcmp(name, "Insert") == 0) return Kins; + if(strcmp(name, "Home") == 0) return Khome; + if(strcmp(name, "PageUp") == 0) return Kpgup; + if(strcmp(name, "PageDown") == 0) return Kpgdown; + if(strcmp(name, "Delete") == 0) return Kdel; + if(strcmp(name, "End") == 0) return Kend; + if(strcmp(name, "Left Alt") == 0) return Kalt; + if(strcmp(name, "Left Ctrl") == 0) return Kctl; + if(strcmp(name, "Left GUI") == 0) return Kmod4; + if(strcmp(name, "Right Alt") == 0) return Kaltgr; + if(strcmp(name, "Left Shift") == 0) return Kshift; + if(name[0] == 'F' && name[1] != '\0'){ + p = strtol(name+1, &e, 10); + if(e == name + 1 || p < 1 || p > 12) + return SDLK_UNKNOWN; + return KF | p; + } + if(name[0] >= '0' && name[0] <= '9') + return name[0]; + if(name[0] >= 'A' && name[0] <= 'Z') + return tolower(name[0]); + if(name[0] >= 'a' && name[0] <= 'z') + return name[0]; + if(name[0] == '-' || name[0] == '=' || name[0] == '\'') + return name[0]; + if(name[0] == '[' || name[0] == ']' || name[0] == '\\' || name[0] == ';' || name[0] == '/') + return name[0]; + return SDLK_UNKNOWN; +} + static void kbdproc(void *) { @@ -362,7 +459,7 @@ case 'k': s = buf+1; - memset(kbdstate, 0, sizeof kbdstate); + memset(kbdstate, 0, sizeof(kbdstate)); while(*s){ s += chartorune(&r, s); scan = SDL_GetScancodeFromKey(r); @@ -397,7 +494,7 @@ case 'K': s = buf2+1; - memset(kbdstate, 0, sizeof kbdstate); + memset(kbdstate, 0, sizeof(kbdstate)); while(*s){ s += chartorune(&r, s); scan = SDL_GetScancodeFromKey(r); --- a/libnpe_sdl2/sdl2.c +++ b/libnpe_sdl2/sdl2.c @@ -134,7 +134,7 @@ if(rm & 0xFF0000) return ARGB32; else - return XBGR32; + return ABGR32; } } assert(0); @@ -1786,4 +1786,18 @@ v->major = 2; v->minor = 24; v->patch = 1; +} + +int +SDL_GetWindowBordersSize(SDL_Window *, int *t, int *l, int *b, int *r) +{ + if(t != nil) + *t = Borderwidth; + if(l != nil) + *l = Borderwidth; + if(b != nil) + *b = Borderwidth; + if(r != nil) + *r = Borderwidth; + return 0; }