Unified · Split
| @@ -46,7 +46,18 @@ typedef struct SDL_mutex SDL_mutex; · 45 unmodified lines | |||
| 46 | 46 | ||
| 47 | #define SDL_zero(x) do{ memset(&(x), 0, sizeof(x)); }while(0) | 47 | #define SDL_zero(x) do{ memset(&(x), 0, sizeof(x)); }while(0) |
| 48 | #define SDL_memset memset | 48 | #define SDL_memset memset |
| 49 | #define SDL_malloc malloc | ||
| 49 | #define SDL_realloc realloc | 50 | #define SDL_realloc realloc |
| 51 | #define SDL_calloc calloc | ||
| 52 | #define SDL_memcpy memcpy | ||
| 53 | #define SDL_memmove memmove | ||
| 54 | #define SDL_memcmp memcmp | ||
| 55 | #define SDL_printf printf | ||
| 56 | #define SDL_snprintf snprintf | ||
| 57 | #define SDL_strlen strlen | ||
| 58 | #define SDL_strlcpy strlcpy | ||
| 59 | #define SDL_strstr strstr | ||
| 60 | #define SDL_strncmp strncmp | ||
| 50 | 61 | ||
| 51 | #include <SDL2/SDL_keycode.h> | 62 | #include <SDL2/SDL_keycode.h> |
| 52 | #include <SDL2/SDL_scancode.h> | 63 | #include <SDL2/SDL_scancode.h> |
| @@ -81,6 +92,7 @@ void SDL_RestoreWindow(SDL_Window *window); · 28 unmodified lines | |||
| 81 | void SDL_RaiseWindow(SDL_Window *window); | 92 | void SDL_RaiseWindow(SDL_Window *window); |
| 82 | int SDL_UpdateTexture(SDL_Texture *texture, SDL_Rect *rect, void *pixels, int pitch); | 93 | int SDL_UpdateTexture(SDL_Texture *texture, SDL_Rect *rect, void *pixels, int pitch); |
| 83 | int SDL_RenderClear(SDL_Renderer *renderer); | 94 | int SDL_RenderClear(SDL_Renderer *renderer); |
| 95 | int SDL_RenderFillRect(SDL_Renderer *r, SDL_Rect *rect); | ||
| 84 | int SDL_GetWindowDisplayIndex(SDL_Window *window); | 96 | int SDL_GetWindowDisplayIndex(SDL_Window *window); |
| 85 | void SDL_FreeSurface(SDL_Surface *surface); | 97 | void SDL_FreeSurface(SDL_Surface *surface); |
| 86 | Uint32 SDL_GetGlobalMouseState(int *x, int *y); | 98 | Uint32 SDL_GetGlobalMouseState(int *x, int *y); |
| @@ -92,6 +104,7 @@ void SDL_FreeCursor(SDL_Cursor *cursor); · 5 unmodified lines | |||
| 92 | SDL_Surface *SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int w, int h, int bpp, Uint32 fmt); | 104 | SDL_Surface *SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int w, int h, int bpp, Uint32 fmt); |
| 93 | SDL_Surface *SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 rm, Uint32 gm, Uint32 bm, Uint32 am); | 105 | SDL_Surface *SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 rm, Uint32 gm, Uint32 bm, Uint32 am); |
| 94 | SDL_Surface *SDL_CreateRGBSurfaceFrom(void *pixels, int w, int h, int bpp, int pitch, Uint32 rm, Uint32 gm, Uint32 bm, Uint32 am); | 106 | SDL_Surface *SDL_CreateRGBSurfaceFrom(void *pixels, int w, int h, int bpp, int pitch, Uint32 rm, Uint32 gm, Uint32 bm, Uint32 am); |
| 107 | void SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat *format, Uint8 *r, Uint8 *g, Uint8 *b); | ||
| 95 | Uint32 SDL_MapRGB(SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b); | 108 | Uint32 SDL_MapRGB(SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b); |
| 96 | int SDL_SetColorKey(SDL_Surface *surface, int flag, Uint32 key); | 109 | int SDL_SetColorKey(SDL_Surface *surface, int flag, Uint32 key); |
| 97 | int SDL_SetSurfaceRLE(SDL_Surface *surface, int flag); | 110 | int SDL_SetSurfaceRLE(SDL_Surface *surface, int flag); |
| @@ -121,18 +134,21 @@ void SDL_SetWindowPosition(SDL_Window *window, int x, int y); · 23 unmodified lines | |||
| 121 | void SDL_DestroyTexture(SDL_Texture *texture); | 134 | void SDL_DestroyTexture(SDL_Texture *texture); |
| 122 | void SDL_DestroyRenderer(SDL_Renderer *renderer); | 135 | void SDL_DestroyRenderer(SDL_Renderer *renderer); |
| 123 | void SDL_DestroyWindow(SDL_Window *window); | 136 | void SDL_DestroyWindow(SDL_Window *window); |
| 137 | int SDL_GetDisplayUsableBounds(int displayIndex, SDL_Rect *rect); | ||
| 124 | int SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode *mode); | 138 | int SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode *mode); |
| 125 | void SDL_SetWindowTitle(SDL_Window *window, char *title); | 139 | void SDL_SetWindowTitle(SDL_Window *window, char *title); |
| 126 | int SDL_SetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode blendMode); | 140 | int SDL_SetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode blendMode); |
| 127 | SDL_bool SDL_SetHint(char *name, char *value); | 141 | SDL_bool SDL_SetHint(char *name, char *value); |
| 128 | SDL_Window *SDL_CreateWindow(char *title, int x, int y, int w, int h, Uint32 flags); | 142 | SDL_Window *SDL_CreateWindow(char *title, int x, int y, int w, int h, Uint32 flags); |
| 129 | SDL_Renderer *SDL_CreateRenderer(SDL_Window *window, int index, Uint32 flags); | 143 | SDL_Renderer *SDL_CreateRenderer(SDL_Window *window, int index, Uint32 flags); |
| 144 | int SDL_CreateWindowAndRenderer(int width, int height, Uint32 window_flags, SDL_Window **window, SDL_Renderer **renderer); | ||
| 130 | int SDL_SetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode); | 145 | int SDL_SetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode); |
| 131 | char *SDL_GetCurrentVideoDriver(void); | 146 | char *SDL_GetCurrentVideoDriver(void); |
| 132 | SDL_Texture *SDL_CreateTexture(SDL_Renderer *renderer, Uint32 format, int access, int w, int h); | 147 | SDL_Texture *SDL_CreateTexture(SDL_Renderer *renderer, Uint32 format, int access, int w, int h); |
| 133 | void SDL_EnableScreenSaver(void); | 148 | void SDL_EnableScreenSaver(void); |
| 134 | Uint32 SDL_GetTicks(void); | 149 | Uint32 SDL_GetTicks(void); |
| 135 | int SDL_GetRendererOutputSize(SDL_Renderer *renderer, int *w, int *h); | 150 | int SDL_GetRendererOutputSize(SDL_Renderer *renderer, int *w, int *h); |
| 151 | void SDL_RenderGetViewport(SDL_Renderer *rebderer, SDL_Rect *rect); | ||
| 136 | int SDL_SaveBMP(SDL_Surface *s, const char *file); | 152 | int SDL_SaveBMP(SDL_Surface *s, const char *file); |
| 137 | void SDL_ClearError(void); | 153 | void SDL_ClearError(void); |
| 138 | int SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha); | 154 | int SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha); |
| @@ -156,7 +172,9 @@ int SDL_UnlockMutex(SDL_mutex*); · 17 unmodified lines | |||
| 156 | #define SDL_mutexV(x) SDL_UnlockMutex(x) | 172 | #define SDL_mutexV(x) SDL_UnlockMutex(x) |
| 157 | #define SDL_mutexP(x) SDL_LockMutex(x) | 173 | #define SDL_mutexP(x) SDL_LockMutex(x) |
| 158 | int SDL_FillRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color); | 174 | int SDL_FillRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color); |
| 175 | SDL_Palette *SDL_AllocPalette(int ncolors); | ||
| 159 | int SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors); | 176 | int SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors); |
| 177 | int SDL_SetSurfacePalette(SDL_Surface *s, SDL_Palette *palette); | ||
| 160 | int SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect); | 178 | int SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect); |
| 161 | int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect); | 179 | int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect); |
| 162 | int SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch); | 180 | int SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch); |
| @@ -197,7 +215,10 @@ enum { · 34 unmodified lines | |||
| 197 | SDL_PIXELFORMAT_INDEX8 = 0x13000801, | 215 | SDL_PIXELFORMAT_INDEX8 = 0x13000801, |
| 198 | SDL_PIXELFORMAT_RGB24 = 0x17101803, | 216 | SDL_PIXELFORMAT_RGB24 = 0x17101803, |
| 199 | SDL_PIXELFORMAT_ABGR8888 = 0x16762004, | 217 | SDL_PIXELFORMAT_ABGR8888 = 0x16762004, |
| 218 | SDL_PIXELFORMAT_XBGR8888 = 0x16561804, | ||
| 219 | SDL_PIXELFORMAT_BGR24 = 0x17401803, | ||
| 200 | SDL_PIXELFORMAT_RGB888 = SDL_PIXELFORMAT_XRGB8888, | 220 | SDL_PIXELFORMAT_RGB888 = SDL_PIXELFORMAT_XRGB8888, |
| 221 | SDL_PIXELFORMAT_BGR888 = SDL_PIXELFORMAT_XBGR8888, | ||
| 201 | 222 | ||
| 202 | /* shit no one cares about */ | 223 | /* shit no one cares about */ |
| 203 | SDL_TEXTUREACCESS_STREAMING = 0, | 224 | SDL_TEXTUREACCESS_STREAMING = 0, |
| @@ -245,6 +266,7 @@ enum { · 41 unmodified lines | |||
| 245 | #define SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4 "SDL_WINDOWS_NO_CLOSE_ON_ALT_F4" | 266 | #define SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4 "SDL_WINDOWS_NO_CLOSE_ON_ALT_F4" |
| 246 | #define SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH "SDL_MOUSE_FOCUS_CLICKTHROUGH" | 267 | #define SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH "SDL_MOUSE_FOCUS_CLICKTHROUGH" |
| 247 | #define SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING "SDL_WINDOWS_DISABLE_THREAD_NAMING" | 268 | #define SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING "SDL_WINDOWS_DISABLE_THREAD_NAMING" |
| 269 | #define SDL_HINT_RENDER_VSYNC "SDL_RENDER_VSYNC" | ||
| 248 | 270 | ||
| 249 | struct SDL_Point { | 271 | struct SDL_Point { |
| 250 | int x, y; | 272 | int x, y; |
| @@ -288,6 +310,7 @@ struct SDL_Palette { · 37 unmodified lines | |||
| 288 | struct SDL_PixelFormat { | 310 | struct SDL_PixelFormat { |
| 289 | SDL_Palette *palette; | 311 | SDL_Palette *palette; |
| 290 | int format; | 312 | int format; |
| 313 | int BytesPerPixel; | ||
| 291 | }; | 314 | }; |
| 292 | 315 | ||
| 293 | struct SDL_RendererInfo { | 316 | struct SDL_RendererInfo { |
| @@ -58,6 +58,7 @@ typedef struct SDL_MouseButtonEvent SDL_MouseButtonEvent; · 57 unmodified lines | |||
| 58 | typedef struct SDL_Keysym SDL_Keysym; | 58 | typedef struct SDL_Keysym SDL_Keysym; |
| 59 | typedef struct SDL_Event SDL_Event; | 59 | typedef struct SDL_Event SDL_Event; |
| 60 | typedef int SDL_eventaction; | 60 | typedef int SDL_eventaction; |
| 61 | typedef int (*SDL_EventFilter)(void *userdata, SDL_Event *event); | ||
| 61 | 62 | ||
| 62 | struct SDL_WindowEvent { | 63 | struct SDL_WindowEvent { |
| 63 | Uint32 type; | 64 | Uint32 type; |
| @@ -127,6 +128,7 @@ struct SDL_Event { · 63 unmodified lines | |||
| 127 | struct { | 128 | struct { |
| 128 | int x, y; | 129 | int x, y; |
| 129 | int xrel, yrel; | 130 | int xrel, yrel; |
| 131 | int state; | ||
| 130 | }motion; | 132 | }motion; |
| 131 | struct { | 133 | struct { |
| 132 | char text[SDL_TEXTINPUTEVENT_TEXT_SIZE+1]; | 134 | char text[SDL_TEXTINPUTEVENT_TEXT_SIZE+1]; |
| @@ -145,5 +147,9 @@ int SDL_RegisterEvents(int); · 12 unmodified lines | |||
| 145 | int SDL_PeepEvents(SDL_Event *events, int numevents, SDL_eventaction action, Uint32 minType, Uint32 maxType); | 147 | int SDL_PeepEvents(SDL_Event *events, int numevents, SDL_eventaction action, Uint32 minType, Uint32 maxType); |
| 146 | Uint32 SDL_GetWindowID(SDL_Window *window); | 148 | Uint32 SDL_GetWindowID(SDL_Window *window); |
| 147 | void SDL_PumpEvents(void); | 149 | void SDL_PumpEvents(void); |
| 150 | void SDL_SetEventFilter(SDL_EventFilter filter, void *userdata); | ||
| 151 | SDL_Scancode SDL_GetScancodeFromKey(SDL_Keycode key); | ||
| 152 | Uint8* SDL_GetKeyboardState(int *numkeys); | ||
| 153 | char* SDL_GetKeyName(SDL_Keycode key); | ||
| 148 | 154 | ||
| 149 | #endif | 155 | #endif |
| @@ -5,5 +5,6 @@ · 4 unmodified lines | |||
| 5 | 5 | ||
| 6 | char *strerror(int errnum); | 6 | char *strerror(int errnum); |
| 7 | int strerror_r(int errnum, char *buf, size_t buflen); | 7 | int strerror_r(int errnum, char *buf, size_t buflen); |
| 8 | size_t strlcpy(char *dst, char *src, size_t sz); | ||
| 8 | 9 | ||
| 9 | #endif | 10 | #endif |
| @@ -62,6 +62,7 @@ OFILES=\ · 61 unmodified lines | |||
| 62 | strerror.$O\ | 62 | strerror.$O\ |
| 63 | strerror_r.$O\ | 63 | strerror_r.$O\ |
| 64 | strftime.$O\ | 64 | strftime.$O\ |
| 65 | strlcpy.$O\ | ||
| 65 | trunc.$O\ | 66 | trunc.$O\ |
| 66 | unlink.$O\ | 67 | unlink.$O\ |
| 67 | usleep.$O\ | 68 | usleep.$O\ |
| @@ -0,0 +1,19 @@ | |||
| 1 | #include <string.h> | ||
| 2 | |||
| 3 | size_t | ||
| 4 | strlcpy(char *dst, char *src, size_t sz) | ||
| 5 | { | ||
| 6 | char *start; | ||
| 7 | |||
| 8 | start = src; | ||
| 9 | if(sz == 0) | ||
| 10 | return strlen(start); | ||
| 11 | |||
| 12 | while(sz-- > 0 && (*dst++ = *src++) != '\0') | ||
| 13 | ; | ||
| 14 | if(dst[-1] != '\0') | ||
| 15 | dst[-1] = '\0'; | ||
| 16 | while(*src++) | ||
| 17 | ; | ||
| 18 | return src - start - 1; | ||
| 19 | } | ||
| @@ -1,6 +1,7 @@ | |||
| 1 | #include <SDL2/SDL.h> | 1 | #include <SDL2/SDL.h> |
| 2 | #include <sys/stat.h> | 2 | #include <sys/stat.h> |
| 3 | #include <stdint.h> | 3 | #include <stdint.h> |
| 4 | #include <string.h> | ||
| 4 | #include <tos.h> | 5 | #include <tos.h> |
| 5 | #include <thread.h> | 6 | #include <thread.h> |
| 6 | #include <draw.h> | 7 | #include <draw.h> |
| @@ -26,7 +26,6 @@ static Alt salt[Numchan+1] = { · 25 unmodified lines | |||
| 26 | [Numchan] = { nil, nil, CHANNOBLK }, | 26 | [Numchan] = { nil, nil, CHANNOBLK }, |
| 27 | }; | 27 | }; |
| 28 | 28 | ||
| 29 | static int rune2scancode(Rune r); | ||
| 30 | static void kbdproc(void *); | 29 | static void kbdproc(void *); |
| 31 | static void mouseproc(void *); | 30 | static void mouseproc(void *); |
| 32 | 31 | ||
| @@ -91,6 +90,21 @@ SDL_QuitRequested(void) · 58 unmodified lines | |||
| 91 | return quitreq; | 90 | return quitreq; |
| 92 | } | 91 | } |
| 93 | 92 | ||
| 93 | struct { | ||
| 94 | SDL_EventFilter f; | ||
| 95 | void *aux; | ||
| 96 | } filter = { | ||
| 97 | nil, | ||
| 98 | nil, | ||
| 99 | }; | ||
| 100 | |||
| 101 | void | ||
| 102 | SDL_SetEventFilter(SDL_EventFilter f, void *userdata) | ||
| 103 | { | ||
| 104 | filter.f = f; | ||
| 105 | filter.aux = userdata; | ||
| 106 | } | ||
| 107 | |||
| 94 | void | 108 | void |
| 95 | SDL_PumpEvents(void) | 109 | SDL_PumpEvents(void) |
| 96 | { | 110 | { |
| @@ -116,20 +130,20 @@ SDL_PollEvent(SDL_Event *e) · 19 unmodified lines | |||
| 116 | break; | 130 | break; |
| 117 | e->type = SDL_TEXTINPUT; | 131 | e->type = SDL_TEXTINPUT; |
| 118 | e->text.text[runetochar(e->text.text, &rune)] = 0; | 132 | e->text.text[runetochar(e->text.text, &rune)] = 0; |
| 119 | return 1; | 133 | goto Filter; |
| 120 | }else if((npe_sdl.hints & Altf4noclose) == 0 && (kmod & KMOD_LALT) != 0 && rune == (KF|4)){ | 134 | }else if((npe_sdl.hints & Altf4noclose) == 0 && (kmod & KMOD_LALT) != 0 && rune == (KF|4)){ |
| 121 | e->type = SDL_QUIT; | 135 | e->type = SDL_QUIT; |
| 122 | quitreq = 1; | 136 | quitreq = 1; |
| 123 | return 1; | 137 | goto Filter; |
| 124 | }else{ | 138 | }else{ |
| 125 | e->type = (t == Rup) ? SDL_KEYUP : SDL_KEYDOWN; | 139 | e->type = (t == Rup) ? SDL_KEYUP : SDL_KEYDOWN; |
| 126 | e->key.repeat = t == Rrepeat; | 140 | e->key.repeat = t == Rrepeat; |
| 127 | e->key.keysym.scancode = rune2scancode(rune); | 141 | e->key.keysym.scancode = SDL_GetScancodeFromKey(rune); |
| 128 | if(rune == '\n') | 142 | if(rune == '\n') |
| 129 | rune = SDLK_RETURN; | 143 | rune = SDLK_RETURN; |
| 130 | e->key.keysym.sym = rune; | 144 | e->key.keysym.sym = rune; |
| 131 | e->key.state = e->type; | 145 | e->key.state = e->type; |
| 132 | return 1; | 146 | goto Filter; |
| 133 | } | 147 | } |
| 134 | break; | 148 | break; |
| 135 | 149 | ||
| @@ -153,7 +167,8 @@ SDL_PollEvent(SDL_Event *e) · 17 unmodified lines | |||
| 153 | npe_sdl.mredraw = 1; | 167 | npe_sdl.mredraw = 1; |
| 154 | if(npe_sdl.m.buttons == npe_sdl.om.buttons){ | 168 | if(npe_sdl.m.buttons == npe_sdl.om.buttons){ |
| 155 | e->type = SDL_MOUSEMOTION; | 169 | e->type = SDL_MOUSEMOTION; |
| 156 | return 1; | 170 | e->motion.state = npe_sdl.m.buttons; |
| 171 | goto Filter; | ||
| 157 | } | 172 | } |
| 158 | } | 173 | } |
| 159 | if(npe_sdl.m.buttons == npe_sdl.om.buttons) | 174 | if(npe_sdl.m.buttons == npe_sdl.om.buttons) |
| @@ -163,25 +178,25 @@ SDL_PollEvent(SDL_Event *e) · 3 unmodified lines | |||
| 163 | e->type = down ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP; | 178 | e->type = down ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP; |
| 164 | e->button.button = SDL_BUTTON_LEFT; | 179 | e->button.button = SDL_BUTTON_LEFT; |
| 165 | npe_sdl.om.buttons = (npe_sdl.om.buttons & ~1) | (npe_sdl.m.buttons & 1); | 180 | npe_sdl.om.buttons = (npe_sdl.om.buttons & ~1) | (npe_sdl.m.buttons & 1); |
| 166 | return 1; | 181 | goto Filter; |
| 167 | } | 182 | } |
| 168 | if((down = (npe_sdl.m.buttons & 2)) != (npe_sdl.om.buttons & 2)){ /* middle */ | 183 | if((down = (npe_sdl.m.buttons & 2)) != (npe_sdl.om.buttons & 2)){ /* middle */ |
| 169 | e->type = down ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP; | 184 | e->type = down ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP; |
| 170 | e->button.button = SDL_BUTTON_MIDDLE; | 185 | e->button.button = SDL_BUTTON_MIDDLE; |
| 171 | npe_sdl.om.buttons = (npe_sdl.om.buttons & ~2) | (npe_sdl.m.buttons & 2); | 186 | npe_sdl.om.buttons = (npe_sdl.om.buttons & ~2) | (npe_sdl.m.buttons & 2); |
| 172 | return 1; | 187 | goto Filter; |
| 173 | } | 188 | } |
| 174 | if((down = (npe_sdl.m.buttons & 4)) != (npe_sdl.om.buttons & 4)){ /* right */ | 189 | if((down = (npe_sdl.m.buttons & 4)) != (npe_sdl.om.buttons & 4)){ /* right */ |
| 175 | e->type = down ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP; | 190 | e->type = down ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP; |
| 176 | e->button.button = SDL_BUTTON_RIGHT; | 191 | e->button.button = SDL_BUTTON_RIGHT; |
| 177 | npe_sdl.om.buttons = (npe_sdl.om.buttons & ~4) | (npe_sdl.m.buttons & 4); | 192 | npe_sdl.om.buttons = (npe_sdl.om.buttons & ~4) | (npe_sdl.m.buttons & 4); |
| 178 | return 1; | 193 | goto Filter; |
| 179 | } | 194 | } |
| 180 | if(npe_sdl.m.buttons & (8|16)){ | 195 | if(npe_sdl.m.buttons & (8|16)){ |
| 181 | e->type = SDL_MOUSEWHEEL; | 196 | e->type = SDL_MOUSEWHEEL; |
| 182 | e->wheel.x = 0; | 197 | e->wheel.x = 0; |
| 183 | e->wheel.y = (npe_sdl.m.buttons & 8) ? 1 : -1; | 198 | e->wheel.y = (npe_sdl.m.buttons & 8) ? 1 : -1; |
| 184 | return 1; | 199 | goto Filter; |
| 185 | } | 200 | } |
| 186 | break; | 201 | break; |
| 187 | 202 | ||
| @@ -193,10 +208,15 @@ SDL_PollEvent(SDL_Event *e) · 5 unmodified lines | |||
| 193 | e->type = SDL_WINDOWEVENT; | 208 | e->type = SDL_WINDOWEVENT; |
| 194 | e->window.event = SDL_WINDOWEVENT_EXPOSED; | 209 | e->window.event = SDL_WINDOWEVENT_EXPOSED; |
| 195 | e->window.windowID = 1; //TODO more then one? | 210 | e->window.windowID = 1; //TODO more then one? |
| 196 | return 1; | 211 | goto Filter; |
| 197 | } | 212 | } |
| 198 | 213 | ||
| 199 | return 0; | 214 | return 0; |
| 215 | |||
| 216 | Filter: | ||
| 217 | if(filter.f != nil && filter.f(filter.aux, e) == 0) | ||
| 218 | return 0; | ||
| 219 | return 1; | ||
| 200 | } | 220 | } |
| 201 | 221 | ||
| 202 | int | 222 | int |
| @@ -211,8 +231,8 @@ SDL_WaitEvent(SDL_Event *e) · 8 unmodified lines | |||
| 211 | return r; | 231 | return r; |
| 212 | } | 232 | } |
| 213 | 233 | ||
| 214 | static int | 234 | SDL_Scancode |
| 215 | rune2scancode(Rune r) | 235 | SDL_GetScancodeFromKey(SDL_Keycode r) |
| 216 | { | 236 | { |
| 217 | if(r >= 'a' && r <= 'z') | 237 | if(r >= 'a' && r <= 'z') |
| 218 | return r - 'a' + SDL_SCANCODE_A; | 238 | return r - 'a' + SDL_SCANCODE_A; |
| @@ -282,12 +302,29 @@ rune2scancode(Rune r) · 63 unmodified lines | |||
| 282 | return r; | 302 | return r; |
| 283 | } | 303 | } |
| 284 | 304 | ||
| 305 | static Uint8 kbdstate[SDL_NUM_SCANCODES]; | ||
| 306 | |||
| 307 | Uint8* | ||
| 308 | SDL_GetKeyboardState(int *numkeys) | ||
| 309 | { | ||
| 310 | if(numkeys != nil) | ||
| 311 | *numkeys = SDL_NUM_SCANCODES; | ||
| 312 | return kbdstate; | ||
| 313 | } | ||
| 314 | |||
| 315 | char* | ||
| 316 | SDL_GetKeyName(SDL_Keycode key) | ||
| 317 | { | ||
| 318 | USED(key); | ||
| 319 | return ""; /* FIXME */ | ||
| 320 | } | ||
| 321 | |||
| 285 | static void | 322 | static void |
| 286 | kbdproc(void *) | 323 | kbdproc(void *) |
| 287 | { | 324 | { |
| 288 | char buf[128], buf2[128], *s; | 325 | char buf[128], buf2[128], *s; |
| 289 | int kfd, n, kbin, t; | 326 | int kfd, n, kbin, t; |
| 290 | Rune r, o; | 327 | Rune r, scan, o; |
| 291 | 328 | ||
| 292 | threadsetname("kbdproc"); | 329 | threadsetname("kbdproc"); |
| 293 | if((kfd = open("/dev/kbd", OREAD|OCEXEC)) < 0) | 330 | if((kfd = open("/dev/kbd", OREAD|OCEXEC)) < 0) |
| @@ -325,8 +362,12 @@ kbdproc(void *) · 31 unmodified lines | |||
| 325 | 362 | ||
| 326 | case 'k': | 363 | case 'k': |
| 327 | s = buf+1; | 364 | s = buf+1; |
| 365 | memset(kbdstate, 0, sizeof kbdstate); | ||
| 328 | while(*s){ | 366 | while(*s){ |
| 329 | s += chartorune(&r, s); | 367 | s += chartorune(&r, s); |
| 368 | scan = SDL_GetScancodeFromKey(r); | ||
| 369 | if(scan < nelem(kbdstate)) | ||
| 370 | kbdstate[scan] = 1; | ||
| 330 | if(utfrune(buf2+1, r) == nil){ | 371 | if(utfrune(buf2+1, r) == nil){ |
| 331 | t = Rdown; | 372 | t = Rdown; |
| 332 | if(r == Kalt){ | 373 | if(r == Kalt){ |
| @@ -356,8 +397,12 @@ kbdproc(void *) · 23 unmodified lines | |||
| 356 | 397 | ||
| 357 | case 'K': | 398 | case 'K': |
| 358 | s = buf2+1; | 399 | s = buf2+1; |
| 400 | memset(kbdstate, 0, sizeof kbdstate); | ||
| 359 | while(*s){ | 401 | while(*s){ |
| 360 | s += chartorune(&r, s); | 402 | s += chartorune(&r, s); |
| 403 | scan = SDL_GetScancodeFromKey(r); | ||
| 404 | if(scan < nelem(kbdstate)) | ||
| 405 | kbdstate[scan] = 1; | ||
| 361 | if(utfrune(buf+1, r) == nil){ | 406 | if(utfrune(buf+1, r) == nil){ |
| 362 | if(r == Kalt) | 407 | if(r == Kalt) |
| 363 | kmod &= ~KMOD_LALT; | 408 | kmod &= ~KMOD_LALT; |
| @@ -21,22 +21,6 @@ struct SDL_Cursor { · 20 unmodified lines | |||
| 21 | Point hot; | 21 | Point hot; |
| 22 | }; | 22 | }; |
| 23 | 23 | ||
| 24 | static SDL_PixelFormat argb8888 = { | ||
| 25 | .format = SDL_PIXELFORMAT_ARGB8888, | ||
| 26 | }; | ||
| 27 | |||
| 28 | static SDL_PixelFormat xrgb8888 = { | ||
| 29 | .format = SDL_PIXELFORMAT_XRGB8888, | ||
| 30 | }; | ||
| 31 | |||
| 32 | static SDL_PixelFormat abgr8888 = { | ||
| 33 | .format = SDL_PIXELFORMAT_ABGR8888, | ||
| 34 | }; | ||
| 35 | |||
| 36 | static SDL_PixelFormat rgb24 = { | ||
| 37 | .format = SDL_PIXELFORMAT_RGB24, | ||
| 38 | }; | ||
| 39 | |||
| 40 | static SDL_Window onewin; | 24 | static SDL_Window onewin; |
| 41 | static SDL_Renderer oneren; | 25 | static SDL_Renderer oneren; |
| 42 | static Memimage *back; | 26 | static Memimage *back; |
| @@ -47,6 +31,9 @@ static SDL_Cursor *oldcursor, *cursor; · 4 unmodified lines | |||
| 47 | static int showcursor = SDL_ENABLE; | 31 | static int showcursor = SDL_ENABLE; |
| 48 | static char basepath[PATH_MAX]; | 32 | static char basepath[PATH_MAX]; |
| 49 | static u32int renddrawcol = DBlack; | 33 | static u32int renddrawcol = DBlack; |
| 34 | struct { | ||
| 35 | Uint32 r, g, b, a; | ||
| 36 | } defmask; | ||
| 50 | 37 | ||
| 51 | struct npe_sdl npe_sdl = {0}; | 38 | struct npe_sdl npe_sdl = {0}; |
| 52 | 39 | ||
| @@ -92,6 +79,114 @@ SDL_SetWindowBordered(SDL_Window *w, SDL_bool flag) · 39 unmodified lines | |||
| 92 | USED(w); USED(flag); | 79 | USED(w); USED(flag); |
| 93 | } | 80 | } |
| 94 | 81 | ||
| 82 | static int | ||
| 83 | chan2mask(Uint32 chan, Uint32 *rm, Uint32 *gm, Uint32 *bm, Uint32 *am) | ||
| 84 | { | ||
| 85 | switch(chan){ | ||
| 86 | case ARGB32: | ||
| 87 | *am = 0xFF000000; | ||
| 88 | if(0){ | ||
| 89 | case XRGB32: | ||
| 90 | *am = 0x00000000; | ||
| 91 | } | ||
| 92 | case RGB24: | ||
| 93 | *rm = 0x00FF0000; | ||
| 94 | *gm = 0x0000FF00; | ||
| 95 | *bm = 0x000000FF; | ||
| 96 | break; | ||
| 97 | case ABGR32: | ||
| 98 | *am = 0xFF000000; | ||
| 99 | if(0){ | ||
| 100 | case XBGR32: | ||
| 101 | *am = 0x00000000; | ||
| 102 | } | ||
| 103 | case BGR24: | ||
| 104 | *bm = 0x00FF0000; | ||
| 105 | *gm = 0x0000FF00; | ||
| 106 | *rm = 0x000000FF; | ||
| 107 | break; | ||
| 108 | default: | ||
| 109 | assert(0); | ||
| 110 | } | ||
| 111 | return 0; | ||
| 112 | } | ||
| 113 | |||
| 114 | static ulong | ||
| 115 | mask2chan(int bpp, Uint32 rm, Uint32 gm, Uint32 bm, Uint32 am) | ||
| 116 | { | ||
| 117 | USED(gm, bm); | ||
| 118 | |||
| 119 | switch(bpp){ | ||
| 120 | case 8: | ||
| 121 | return CMAP8; | ||
| 122 | case 24: | ||
| 123 | if(rm & 0xFF0000) | ||
| 124 | return RGB24; | ||
| 125 | else | ||
| 126 | return BGR24; | ||
| 127 | case 32: | ||
| 128 | if(am == 0){ | ||
| 129 | if(rm & 0xFF0000) | ||
| 130 | return XRGB32; | ||
| 131 | else | ||
| 132 | return XBGR32; | ||
| 133 | } else { | ||
| 134 | if(rm & 0xFF0000) | ||
| 135 | return ARGB32; | ||
| 136 | else | ||
| 137 | return XBGR32; | ||
| 138 | } | ||
| 139 | } | ||
| 140 | assert(0); | ||
| 141 | return 0; | ||
| 142 | } | ||
| 143 | |||
| 144 | static Uint32 | ||
| 145 | chan2pixel(ulong chan) | ||
| 146 | { | ||
| 147 | switch(chan){ | ||
| 148 | case ARGB32: | ||
| 149 | return SDL_PIXELFORMAT_ARGB8888; | ||
| 150 | case XRGB32: | ||
| 151 | return SDL_PIXELFORMAT_XRGB8888; | ||
| 152 | case RGB24: | ||
| 153 | return SDL_PIXELFORMAT_RGB24; | ||
| 154 | case ABGR32: | ||
| 155 | return SDL_PIXELFORMAT_ABGR8888; | ||
| 156 | case XBGR32: | ||
| 157 | return SDL_PIXELFORMAT_XBGR8888; | ||
| 158 | case BGR24: | ||
| 159 | return SDL_PIXELFORMAT_BGR24; | ||
| 160 | case CMAP8: | ||
| 161 | return SDL_PIXELFORMAT_INDEX8; | ||
| 162 | } | ||
| 163 | assert(0); | ||
| 164 | return 0; | ||
| 165 | } | ||
| 166 | |||
| 167 | static ulong | ||
| 168 | pixel2chan(Uint32 format) | ||
| 169 | { | ||
| 170 | switch(format){ | ||
| 171 | case SDL_PIXELFORMAT_ARGB8888: | ||
| 172 | return ARGB32; | ||
| 173 | case SDL_PIXELFORMAT_XRGB8888: | ||
| 174 | return XRGB32; | ||
| 175 | case SDL_PIXELFORMAT_RGB24: | ||
| 176 | return RGB24; | ||
| 177 | case SDL_PIXELFORMAT_ABGR8888: | ||
| 178 | return ABGR32; | ||
| 179 | case SDL_PIXELFORMAT_XBGR8888: | ||
| 180 | return XBGR32; | ||
| 181 | case SDL_PIXELFORMAT_BGR24: | ||
| 182 | return BGR24; | ||
| 183 | case SDL_PIXELFORMAT_INDEX8: | ||
| 184 | return CMAP8; | ||
| 185 | } | ||
| 186 | assert(0); | ||
| 187 | return 0; | ||
| 188 | } | ||
| 189 | |||
| 95 | int | 190 | int |
| 96 | SDL_Init(int mask) | 191 | SDL_Init(int mask) |
| 97 | { | 192 | { |
| @@ -113,7 +208,10 @@ SDL_Init(int mask) · 15 unmodified lines | |||
| 113 | npe_sdl.scale = 1; | 208 | npe_sdl.scale = 1; |
| 114 | physw = Dx(screen->r); | 209 | physw = Dx(screen->r); |
| 115 | physh = Dy(screen->r); | 210 | physh = Dy(screen->r); |
| 116 | 211 | if(chan2mask(screen->chan, &defmask.r, &defmask.g, &defmask.b, &defmask.a) < 0){ | |
| 212 | werrstr("SDL_Init: unsupported screen channel"); | ||
| 213 | return -1; | ||
| 214 | } | ||
| 117 | return 0; | 215 | return 0; |
| 118 | err: | 216 | err: |
| 119 | werrstr("SDL_Init: %r"); | 217 | werrstr("SDL_Init: %r"); |
| @@ -223,17 +321,7 @@ SDL_CreateTexture(SDL_Renderer *, Uint32 format, int, int w, int h) · 103 unmodified lines | |||
| 223 | SDL_Texture *t; | 321 | SDL_Texture *t; |
| 224 | int dformat; | 322 | int dformat; |
| 225 | 323 | ||
| 226 | switch(format){ | 324 | if((dformat = pixel2chan(format)) == 0){ |
| 227 | case SDL_PIXELFORMAT_ARGB8888: | ||
| 228 | dformat = ARGB32; | ||
| 229 | break; | ||
| 230 | case SDL_PIXELFORMAT_XRGB8888: | ||
| 231 | dformat = XRGB32; | ||
| 232 | break; | ||
| 233 | case SDL_PIXELFORMAT_ABGR8888: | ||
| 234 | dformat = ABGR32; | ||
| 235 | break; | ||
| 236 | default: | ||
| 237 | werrstr("SDL_CreateTexture: format is not supported"); | 325 | werrstr("SDL_CreateTexture: format is not supported"); |
| 238 | goto err; | 326 | goto err; |
| 239 | } | 327 | } |
| @@ -341,6 +429,14 @@ SDL_RenderClear(SDL_Renderer *) · 101 unmodified lines | |||
| 341 | return 0; | 429 | return 0; |
| 342 | } | 430 | } |
| 343 | 431 | ||
| 432 | int | ||
| 433 | SDL_RenderFillRect(SDL_Renderer *r, SDL_Rect *rect) | ||
| 434 | { | ||
| 435 | /* FIXME */ | ||
| 436 | assert(rect == nil); | ||
| 437 | return SDL_RenderClear(r); | ||
| 438 | } | ||
| 439 | |||
| 344 | int | 440 | int |
| 345 | SDL_SetRenderDrawColor(SDL_Renderer *, Uint8 r, Uint8 g, Uint8 b, Uint8 a) | 441 | SDL_SetRenderDrawColor(SDL_Renderer *, Uint8 r, Uint8 g, Uint8 b, Uint8 a) |
| 346 | { | 442 | { |
| @@ -368,40 +464,37 @@ SDL_free(void *p) · 21 unmodified lines | |||
| 368 | } | 464 | } |
| 369 | 465 | ||
| 370 | SDL_Surface * | 466 | SDL_Surface * |
| 371 | SDL_CreateRGBSurface(Uint32 flags, int w, int h, int bpp, Uint32 rm, Uint32 gm, Uint32 bm, Uint32 am) | 467 | SDL_CreateRGBSurface(Uint32, int w, int h, int bpp, Uint32 rm, Uint32 gm, Uint32 bm, Uint32 am) |
| 372 | { | 468 | { |
| 373 | SDL_Surface *s; | 469 | SDL_Surface *s; |
| 374 | int n; | 470 | int n; |
| 375 | Memimage *i; | 471 | ulong chan; |
| 376 | |||
| 377 | USED(flags, rm, gm, bm, am); /* FIXME flags & masks */ | ||
| 378 | 472 | ||
| 473 | rm = rm ? rm : defmask.r; | ||
| 474 | gm = gm ? gm : defmask.g; | ||
| 475 | bm = bm ? bm : defmask.b; | ||
| 476 | if((chan = mask2chan(bpp, rm, gm, bm, am)) == 0){ | ||
| 477 | werrstr("bad bpp and/or mask"); | ||
| 478 | return nil; | ||
| 479 | } | ||
| 379 | n = w*h*bpp/8; | 480 | n = w*h*bpp/8; |
| 380 | if((s = calloc(1, sizeof(*s))) == nil){ | 481 | if((s = calloc(1, sizeof(*s))) == nil){ |
| 381 | werrstr("SDL_CreateRGBSurface: memory"); | 482 | werrstr("SDL_CreateRGBSurface: memory"); |
| 382 | return nil; | 483 | return nil; |
| 383 | } | 484 | } |
| 384 | s->i = i = allocmemimage(Rect(0,0,w,h), screen->chan); | 485 | s->i = allocmemimage(Rect(0,0,w,h), chan == CMAP8 ? screen->chan : chan); |
| 385 | s->format = calloc(1, sizeof(SDL_PixelFormat)); | 486 | s->format = calloc(1, sizeof(SDL_PixelFormat)); |
| 386 | switch(bpp){ | 487 | s->format->BytesPerPixel = bpp/8; |
| 387 | case 32: | 488 | s->format->format = chan2pixel(chan); |
| 388 | s->format->format = SDL_PIXELFORMAT_ARGB8888; | 489 | if(chan == CMAP8){ |
| 389 | s->pixels = i->data->bdata; | 490 | s->i = allocmemimage(Rect(0,0,w,h), screen->chan); |
| 390 | break; | ||
| 391 | case 24: | ||
| 392 | s->format->format = SDL_PIXELFORMAT_RGB24; | ||
| 393 | s->pixels = calloc(1, n); | ||
| 394 | break; | ||
| 395 | case 8: | ||
| 396 | s->format->format = SDL_PIXELFORMAT_INDEX8; | ||
| 397 | s->format->palette = calloc(1, sizeof(SDL_Palette)); | 491 | s->format->palette = calloc(1, sizeof(SDL_Palette)); |
| 398 | s->format->palette->ncolors = 256; | 492 | s->format->palette->ncolors = 256; |
| 399 | s->format->palette->colors = calloc(1, sizeof(SDL_Color) * 256); | 493 | s->format->palette->colors = calloc(1, sizeof(SDL_Color) * 256); |
| 400 | s->pixels = calloc(1, n); | 494 | s->pixels = calloc(1, n); |
| 401 | break; | 495 | }else{ |
| 402 | default: | 496 | s->i = allocmemimage(Rect(0,0,w,h), chan); |
| 403 | werrstr("non supported bpp"); | 497 | s->pixels = ((Memimage*)s->i)->data->bdata; |
| 404 | return nil; | ||
| 405 | } | 498 | } |
| 406 | 499 | ||
| 407 | s->w = w; | 500 | s->w = w; |
| @@ -436,27 +529,17 @@ SDL_CreateRGBSurfaceFrom(void *pixels, int w, int h, int bpp, int pitch, Uint32 · 28 unmodified lines | |||
| 436 | SDL_Surface * | 529 | SDL_Surface * |
| 437 | SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int w, int h, int bpp, Uint32 fmt) | 530 | SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int w, int h, int bpp, Uint32 fmt) |
| 438 | { | 531 | { |
| 439 | SDL_PixelFormat *f; | ||
| 440 | SDL_Surface *s; | 532 | SDL_Surface *s; |
| 533 | ulong chan; | ||
| 534 | Uint32 rm, gm, bm, am; | ||
| 441 | 535 | ||
| 442 | if(fmt == SDL_PIXELFORMAT_ARGB8888) | 536 | if((chan = pixel2chan(fmt)) == 0){ |
| 443 | f = &argb8888; | ||
| 444 | else if(fmt == SDL_PIXELFORMAT_XRGB8888) | ||
| 445 | f = &xrgb8888; | ||
| 446 | else if(fmt == SDL_PIXELFORMAT_RGB24) | ||
| 447 | f = &rgb24; | ||
| 448 | else if(fmt == SDL_PIXELFORMAT_ABGR8888) | ||
| 449 | f = &abgr8888; | ||
| 450 | else{ | ||
| 451 | werrstr("SDL_CreateRGBSurfaceWithFormat: FIXME format %8ux not implemented", fmt); | 537 | werrstr("SDL_CreateRGBSurfaceWithFormat: FIXME format %8ux not implemented", fmt); |
| 452 | return nil; | 538 | return nil; |
| 453 | } | 539 | } |
| 454 | 540 | chan2mask(chan, &rm, &gm, &bm, &am); | |
| 455 | if((s = SDL_CreateRGBSurface(flags, w, h, bpp, 0, 0, 0, 0)) == nil) | 541 | if((s = SDL_CreateRGBSurface(flags, w, h, bpp, rm, bm, gm, am)) == nil) |
| 456 | return nil; | 542 | return nil; |
| 457 | |||
| 458 | s->format = f; | ||
| 459 | |||
| 460 | return s; | 543 | return s; |
| 461 | } | 544 | } |
| 462 | 545 | ||
| @@ -470,6 +553,7 @@ SDL_FillRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color) · 7 unmodified lines | |||
| 470 | switch(dst->format->format){ | 553 | switch(dst->format->format){ |
| 471 | case SDL_PIXELFORMAT_XRGB8888: | 554 | case SDL_PIXELFORMAT_XRGB8888: |
| 472 | case SDL_PIXELFORMAT_ARGB8888: | 555 | case SDL_PIXELFORMAT_ARGB8888: |
| 556 | case SDL_PIXELFORMAT_XBGR8888: | ||
| 473 | case SDL_PIXELFORMAT_ABGR8888: | 557 | case SDL_PIXELFORMAT_ABGR8888: |
| 474 | p = (Uint32*)dst->pixels; | 558 | p = (Uint32*)dst->pixels; |
| 475 | for(i = 0; i < dst->n / sizeof(*p); i++) | 559 | for(i = 0; i < dst->n / sizeof(*p); i++) |
| @@ -491,6 +575,17 @@ SDL_FillRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color) · 15 unmodified lines | |||
| 491 | return 0; | 575 | return 0; |
| 492 | } | 576 | } |
| 493 | 577 | ||
| 578 | SDL_Palette* | ||
| 579 | SDL_AllocPalette(int ncolors) | ||
| 580 | { | ||
| 581 | SDL_Palette *p; | ||
| 582 | |||
| 583 | p = malloc(sizeof(*p)); | ||
| 584 | p->ncolors = ncolors; | ||
| 585 | p->colors = mallocz(sizeof(SDL_Color)*ncolors, 1); | ||
| 586 | return p; | ||
| 587 | } | ||
| 588 | |||
| 494 | int | 589 | int |
| 495 | SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors) | 590 | SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors) |
| 496 | { | 591 | { |
| @@ -502,6 +597,13 @@ SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcol · 5 unmodified lines | |||
| 502 | return 0; | 597 | return 0; |
| 503 | } | 598 | } |
| 504 | 599 | ||
| 600 | int | ||
| 601 | SDL_SetSurfacePalette(SDL_Surface *s, SDL_Palette *palette) | ||
| 602 | { | ||
| 603 | s->format->palette = palette; | ||
| 604 | return 0; | ||
| 605 | } | ||
| 606 | |||
| 505 | static void | 607 | static void |
| 506 | syncpalette(SDL_Surface *s) | 608 | syncpalette(SDL_Surface *s) |
| 507 | { | 609 | { |
| @@ -519,6 +621,32 @@ syncpalette(SDL_Surface *s) · 11 unmodified lines | |||
| 519 | } | 621 | } |
| 520 | } | 622 | } |
| 521 | 623 | ||
| 624 | static void | ||
| 625 | synctopalette(SDL_Surface *s) | ||
| 626 | { | ||
| 627 | SDL_Color c, *f; | ||
| 628 | Uint32 *from; | ||
| 629 | int j, k; | ||
| 630 | Memimage *i; | ||
| 631 | SDL_PixelFormat fmt; | ||
| 632 | |||
| 633 | i = s->i; | ||
| 634 | fmt.format = chan2pixel(screen->chan); | ||
| 635 | from = (void*)i->data->bdata; | ||
| 636 | for(j = 0; j < s->n; j++){ | ||
| 637 | SDL_GetRGB(from[j], &fmt, &c.r, &c.g, &c.b); | ||
| 638 | for(k = 0; k < s->format->palette->ncolors; k++){ | ||
| 639 | f = s->format->palette->colors + k; | ||
| 640 | if(c.r == f->r && c.g == f->g && c.b == f->b) | ||
| 641 | break; | ||
| 642 | } | ||
| 643 | if(k == s->format->palette->ncolors) | ||
| 644 | s->pixels[j] = 0; /* FIXME */ | ||
| 645 | else | ||
| 646 | s->pixels[j] = k; | ||
| 647 | } | ||
| 648 | } | ||
| 649 | |||
| 522 | int | 650 | int |
| 523 | SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect) | 651 | SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect) |
| 524 | { | 652 | { |
| @@ -530,9 +658,10 @@ SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL · 5 unmodified lines | |||
| 530 | if(src->format->format == SDL_PIXELFORMAT_INDEX8) | 658 | if(src->format->format == SDL_PIXELFORMAT_INDEX8) |
| 531 | syncpalette(src); | 659 | syncpalette(src); |
| 532 | 660 | ||
| 533 | /* FIXME */ | ||
| 534 | assert(dst->format->format != SDL_PIXELFORMAT_INDEX8); | ||
| 535 | memimagedraw(dst->i, r2, src->i, ZP, nil, ZP, S); | 661 | memimagedraw(dst->i, r2, src->i, ZP, nil, ZP, S); |
| 662 | |||
| 663 | if(dst->format->format == SDL_PIXELFORMAT_INDEX8) | ||
| 664 | synctopalette(dst); | ||
| 536 | return 0; | 665 | return 0; |
| 537 | } | 666 | } |
| 538 | 667 | ||
| @@ -615,10 +744,63 @@ SDL_FreeSurface(SDL_Surface *surface) · 76 unmodified lines | |||
| 615 | free(surface); | 744 | free(surface); |
| 616 | } | 745 | } |
| 617 | 746 | ||
| 747 | void | ||
| 748 | SDL_GetRGB(Uint32 pixel, SDL_PixelFormat *fmt, Uint8 *r, Uint8 *g, Uint8 *b) | ||
| 749 | { | ||
| 750 | SDL_Color *c; | ||
| 751 | |||
| 752 | switch(fmt->format){ | ||
| 753 | case SDL_PIXELFORMAT_ARGB8888: | ||
| 754 | case SDL_PIXELFORMAT_XRGB8888: | ||
| 755 | case SDL_PIXELFORMAT_RGB24: | ||
| 756 | *r = pixel>>16; | ||
| 757 | *g = pixel>>8; | ||
| 758 | *b = pixel; | ||
| 759 | break; | ||
| 760 | case SDL_PIXELFORMAT_ABGR8888: | ||
| 761 | case SDL_PIXELFORMAT_XBGR8888: | ||
| 762 | case SDL_PIXELFORMAT_BGR24: | ||
| 763 | *b = pixel>>16; | ||
| 764 | *g = pixel>>8; | ||
| 765 | *r = pixel; | ||
| 766 | break; | ||
| 767 | case SDL_PIXELFORMAT_INDEX8: | ||
| 768 | assert(fmt->palette); | ||
| 769 | assert(pixel < fmt->palette->ncolors); | ||
| 770 | c = fmt->palette->colors + pixel; | ||
| 771 | *r = c->r; | ||
| 772 | *g = c->g; | ||
| 773 | *b = c->b; | ||
| 774 | break; | ||
| 775 | default: | ||
| 776 | assert(0); | ||
| 777 | } | ||
| 778 | } | ||
| 779 | |||
| 618 | Uint32 | 780 | Uint32 |
| 619 | SDL_MapRGB(SDL_PixelFormat *, Uint8 r, Uint8 g, Uint8 b) | 781 | SDL_MapRGB(SDL_PixelFormat *fmt, Uint8 r, Uint8 g, Uint8 b) |
| 620 | { | 782 | { |
| 621 | return r<<24 | g<<16 | b<<8 | 0xff; | 783 | SDL_Color *c; |
| 784 | |||
| 785 | switch(fmt->format){ | ||
| 786 | case SDL_PIXELFORMAT_ARGB8888: | ||
| 787 | case SDL_PIXELFORMAT_XRGB8888: | ||
| 788 | case SDL_PIXELFORMAT_RGB24: | ||
| 789 | return 0xff<<24 | r<<16 | g<<8 | b; | ||
| 790 | case SDL_PIXELFORMAT_ABGR8888: | ||
| 791 | case SDL_PIXELFORMAT_XBGR8888: | ||
| 792 | case SDL_PIXELFORMAT_BGR24: | ||
| 793 | return 0xff<<24 | b<<16 | g<<8 | r; | ||
| 794 | case SDL_PIXELFORMAT_INDEX8: | ||
| 795 | assert(fmt->palette); | ||
| 796 | for(c = fmt->palette->colors; c < fmt->palette->colors + fmt->palette->ncolors; c++){ | ||
| 797 | if(c->r == r && c->g == g && c->b == b) | ||
| 798 | return c - fmt->palette->colors; | ||
| 799 | } | ||
| 800 | default: | ||
| 801 | assert(0); | ||
| 802 | return 0; | ||
| 803 | } | ||
| 622 | } | 804 | } |
| 623 | 805 | ||
| 624 | int | 806 | int |
| @@ -1027,6 +1209,14 @@ SDL_GetRendererOutputSize(SDL_Renderer *r, int *w, int *h) · 402 unmodified lines | |||
| 1027 | return 0; | 1209 | return 0; |
| 1028 | } | 1210 | } |
| 1029 | 1211 | ||
| 1212 | void | ||
| 1213 | SDL_RenderGetViewport(SDL_Renderer *r, SDL_Rect *rect) | ||
| 1214 | { | ||
| 1215 | rect->x = rect->y = 0; | ||
| 1216 | rect->w = r->logiw; | ||
| 1217 | rect->h = r->logih; | ||
| 1218 | } | ||
| 1219 | |||
| 1030 | void | 1220 | void |
| 1031 | SDL_SetWindowSize(SDL_Window *, int w, int h) | 1221 | SDL_SetWindowSize(SDL_Window *, int w, int h) |
| 1032 | { | 1222 | { |
| @@ -1094,6 +1284,22 @@ SDL_SetWindowPosition(SDL_Window *, int x, int y) · 61 unmodified lines | |||
| 1094 | } | 1284 | } |
| 1095 | } | 1285 | } |
| 1096 | 1286 | ||
| 1287 | int | ||
| 1288 | SDL_GetDisplayUsableBounds(int displayIndex, SDL_Rect *r) | ||
| 1289 | { | ||
| 1290 | if(displayIndex != 0) | ||
| 1291 | return -1; | ||
| 1292 | |||
| 1293 | if(r == nil) | ||
| 1294 | return 0; | ||
| 1295 | |||
| 1296 | r->x = display->image->r.min.x; | ||
| 1297 | r->y = display->image->r.min.y; | ||
| 1298 | r->w = Dx(display->image->r); | ||
| 1299 | r->h = Dy(display->image->r); | ||
| 1300 | return 0; | ||
| 1301 | } | ||
| 1302 | |||
| 1097 | int | 1303 | int |
| 1098 | SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode *mode) | 1304 | SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode *mode) |
| 1099 | { | 1305 | { |
| @@ -1202,6 +1408,15 @@ SDL_CreateRenderer(SDL_Window *, int, Uint32) · 102 unmodified lines | |||
| 1202 | return &oneren; | 1408 | return &oneren; |
| 1203 | } | 1409 | } |
| 1204 | 1410 | ||
| 1411 | int | ||
| 1412 | SDL_CreateWindowAndRenderer(int w, int h, Uint32, SDL_Window **win, SDL_Renderer **rend) | ||
| 1413 | { | ||
| 1414 | SDL_SetWindowSize(&onewin, w, h); | ||
| 1415 | *win = &onewin; | ||
| 1416 | *rend = &oneren; | ||
| 1417 | return 0; | ||
| 1418 | } | ||
| 1419 | |||
| 1205 | int | 1420 | int |
| 1206 | SDL_SetRenderDrawBlendMode(SDL_Renderer *, SDL_BlendMode blendMode) | 1421 | SDL_SetRenderDrawBlendMode(SDL_Renderer *, SDL_BlendMode blendMode) |
| 1207 | { | 1422 | { |
| @@ -1533,7 +1748,7 @@ SDL_CreateMutex(void) · 325 unmodified lines | |||
| 1533 | { | 1748 | { |
| 1534 | SDL_mutex *m; | 1749 | SDL_mutex *m; |
| 1535 | 1750 | ||
| 1536 | m = mallocz(sizeof *m, 1); | 1751 | m = mallocz(sizeof(*m), 1); |
| 1537 | return m; | 1752 | return m; |
| 1538 | } | 1753 | } |
| 1539 | 1754 | ||