ref: b4adec1f02eda895b9cb30cc96b1ffde8241e75d
parent: a30d7ca4b6b6e2d218e324847abd754ae834cc5e
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed Mar 17 05:12:20 EDT 2021
sdl2: add a small bunch of stuff
--- a/include/npe/SDL2/SDL.h
+++ b/include/npe/SDL2/SDL.h
@@ -125,6 +125,10 @@
int SDL_SetTextureColorMod(SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b);
int SDL_OpenURL(char *url);
SDL_Cursor *SDL_CreateSystemCursor(SDL_SystemCursor id);
+SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *r, SDL_Surface *s);
+char *SDL_GetBasePath(void);
+int SDL_SetRenderDrawColor(SDL_Renderer *r, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
+int SDL_GetCurrentDisplayMode(int displayIndex, SDL_DisplayMode *mode);
enum {
AUDIO_S16,
@@ -145,6 +149,7 @@
SDL_WINDOW_INPUT_FOCUS = 1<<2,
SDL_WINDOW_ALLOW_HIGHDPI = 1<<3,
SDL_WINDOW_SHOWN = 1<<4,
+ SDL_WINDOW_RESIZABLE = 1<<5,
SDL_WINDOWPOS_CENTERED = -1,
SDL_WINDOWPOS_UNDEFINED = -2,
@@ -154,6 +159,7 @@
SDL_INIT_JOYSTICK = 1<<2,
SDL_BLENDMODE_NONE = 0,
+ SDL_BLENDMODE_BLEND,
SDL_FLIP_NONE = 0,
SDL_FLIP_HORIZONTAL,
@@ -372,6 +378,7 @@
SDL_WINDOWEVENT_MINIMIZED,
SDL_WINDOWEVENT_FOCUS_LOST,
SDL_WINDOWEVENT_EXPOSED,
+ SDL_WINDOWEVENT_SIZE_CHANGED,
SDL_BUTTON_LEFT = 0,
SDL_BUTTON_MIDDLE = 1,
@@ -381,6 +388,8 @@
SDL_BUTTON_MMASK = 1<<SDL_BUTTON_MIDDLE,
SDL_BUTTON_RMASK = 1<<SDL_BUTTON_RIGHT,
};
+
+#define SDL_HINT_RENDER_SCALE_QUALITY "SDL_HINT_RENDER_SCALE_QUALITY"
struct SDL_AudioSpec {
void (*callback)(void *, Uint8 *, int);
--- a/libnpe_sdl2/sdl2.c
+++ b/libnpe_sdl2/sdl2.c
@@ -96,6 +96,8 @@
static int mouseredraw = 0;
static int showcursor = SDL_ENABLE;
static int textinput;
+static char basepath[PATH_MAX];
+static u32int renddrawcol = DBlack;
static Cursor nocursor = {
{0, 0},
@@ -220,6 +222,9 @@
/* FIXME actually use the mask? */
USED(mask);
+ if(getwd(basepath, sizeof(basepath)) == nil)
+ strcpy(basepath, "/");
+
if(memimageinit() < 0)
goto err;
if(initdraw(nil, nil, argv0) < 0)
@@ -523,6 +528,23 @@
return nil;
}
+SDL_Texture *
+SDL_CreateTextureFromSurface(SDL_Renderer *r, SDL_Surface *s)
+{
+ SDL_Texture *t;
+ SDL_Rect re;
+
+ if((t = SDL_CreateTexture(r, s->format->format, 0, s->w, s->h)) != nil){
+ re.x = 0;
+ re.y = 0;
+ re.w = s->w;
+ re.h = s->h;
+ SDL_UpdateTexture(t, &re, s->pixels, s->pitch);
+ }
+
+ return t;
+}
+
int
SDL_UpdateTexture(SDL_Texture *t, SDL_Rect *re, void *pixels, int pitch)
{
@@ -561,12 +583,20 @@
SDL_RenderClear(SDL_Renderer *)
{
if(back != nil)
- memfillcolor(back, DBlack);
+ memfillcolor(back, renddrawcol);
return 0;
}
int
+SDL_SetRenderDrawColor(SDL_Renderer *, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+ renddrawcol = r<<24 | g<<16 | b<<8 | a;
+
+ return 0;
+}
+
+int
SDL_GetWindowDisplayIndex(SDL_Window *)
{
return 0;
@@ -1189,6 +1219,12 @@
return 0;
}
+int
+SDL_GetCurrentDisplayMode(int displayIndex, SDL_DisplayMode *mode)
+{
+ return SDL_GetDesktopDisplayMode(displayIndex, mode);
+}
+
void
SDL_SetWindowTitle(SDL_Window *, char *title)
{
@@ -1294,6 +1330,12 @@
close(f);
return r;
+}
+
+char *
+SDL_GetBasePath(void)
+{
+ return strdup(basepath);
}
SDL_bool