shithub: npe

Download patch

ref: 492aef060aadc2c1e9cb3db1a7b12739bc16952e
parent: 4c1fa073c7d7fff3c4e21717fcb0ad81a9ab3cf7
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Sep 17 03:27:02 EDT 2021

SDL2: more stubs

--- a/include/npe/SDL2/SDL.h
+++ b/include/npe/SDL2/SDL.h
@@ -14,13 +14,6 @@
 typedef u32int Uint32;
 typedef enum {SDL_FALSE, SDL_TRUE} SDL_bool;
 
-#include <SDL2/SDL_keycode.h>
-#include <SDL2/SDL_scancode.h>
-#include <SDL2/SDL_audio.h>
-#include <SDL2/SDL_events.h>
-#include <SDL2/SDL_thread.h>
-#include <SDL2/SDL_rwops.h>
-
 typedef struct SDL_Window SDL_Window;
 typedef struct SDL_Renderer SDL_Renderer;
 typedef struct SDL_Texture SDL_Texture;
@@ -34,10 +27,11 @@
 typedef struct SDL_DisplayMode SDL_DisplayMode;
 typedef int SDL_SystemCursor;
 typedef union SDL_Color SDL_Color;
+typedef struct SDL_Palette SDL_Palette;
 
 #pragma incomplete SDL_Cursor
-#pragma incomplete SDL_PixelFormat
 #pragma incomplete SDL_Renderer
+#pragma incomplete SDL_Surface
 #pragma incomplete SDL_Texture
 #pragma incomplete SDL_Window
 
@@ -47,6 +41,13 @@
 #define SDL_memset memset
 #define SDL_realloc realloc
 
+#include <SDL2/SDL_keycode.h>
+#include <SDL2/SDL_scancode.h>
+#include <SDL2/SDL_audio.h>
+#include <SDL2/SDL_events.h>
+#include <SDL2/SDL_thread.h>
+#include <SDL2/SDL_rwops.h>
+
 void SDL_StopTextInput(void);
 SDL_bool SDL_HasSSE(void);
 SDL_bool SDL_HasSSE2(void);
@@ -84,6 +85,7 @@
 void SDL_WarpMouseInWindow(SDL_Window *window, int x, int y);
 void SDL_RenderGetScale(SDL_Renderer *renderer, float *scaleX, float *scaleY);
 void SDL_GetWindowSize(SDL_Window *window, int *w, int *h);
+SDL_Surface *SDL_GetWindowSurface(SDL_Window *w);
 void SDL_GetWindowPosition(SDL_Window *window, int *x, int *y);
 Uint32 SDL_GetMouseState(int *x, int *y);
 SDL_bool SDL_IsTextInputActive(void);
@@ -214,8 +216,7 @@
 	uchar pixels[];
 };
 
-struct SDL_DisplayMode
-{
+struct SDL_DisplayMode {
 	int format;
 	int w;
 	int h;
@@ -226,6 +227,16 @@
 	struct {
 		Uint8 r, g, b, a;
 	};
+};
+
+struct SDL_Palette {
+	int ncolors;
+	SDL_Color *colors;
+};
+
+struct SDL_PixelFormat {
+	SDL_Palette *palette;
+	int format;
 };
 
 #endif
--- a/include/npe/SDL2/SDL_events.h
+++ b/include/npe/SDL2/SDL_events.h
@@ -18,6 +18,7 @@
 	SDL_WINDOWEVENT_FOCUS_LOST,
 	SDL_WINDOWEVENT_EXPOSED,
 	SDL_WINDOWEVENT_SIZE_CHANGED,
+	SDL_WINDOWEVENT_RESIZED = SDL_WINDOWEVENT_SIZE_CHANGED, /* FIXME I don't even fucking know... */
 
 	SDL_TEXTINPUTEVENT_TEXT_SIZE = UTFmax,
 };
--- a/libnpe_sdl2/sdl2.c
+++ b/libnpe_sdl2/sdl2.c
@@ -14,10 +14,6 @@
 	SDL_BlendMode blend;
 };
 
-struct SDL_PixelFormat {
-	int format;
-};
-
 struct SDL_Cursor {
 	Image *i;
 	Image *m;
@@ -344,12 +340,22 @@
 SDL_Surface *
 SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int w, int h, int bpp, Uint32 fmt)
 {
-	if(fmt != SDL_PIXELFORMAT_ARGB8888){
-		werrstr("SDL_CreateRGBSurfaceWithFormat: FIXME non-argb8888");
+	SDL_PixelFormat *f;
+	SDL_Surface *s;
+
+	if(fmt == SDL_PIXELFORMAT_ARGB8888)
+		f = &argb8888;
+	else{
+		werrstr("SDL_CreateRGBSurfaceWithFormat: FIXME format %8ux not implemented", fmt);
 		return nil;
 	}
 
-	return SDL_CreateRGBSurface(flags, w, h, bpp, 0, 0, 0, 0);
+	if((s = SDL_CreateRGBSurface(flags, w, h, bpp, 0, 0, 0, 0)) == nil)
+		return nil;
+
+	s->format = f;
+
+	return s;
 }
 
 void
@@ -1036,4 +1042,11 @@
 void
 SDL_ClearError(void)
 {
+}
+SDL_Surface *
+SDL_GetWindowSurface(SDL_Window *w)
+{
+	/* FIXME implement this */
+	USED(w);
+	return nil;
 }