initial add
This commit is contained in:
109
sdl.h
Normal file
109
sdl.h
Normal file
@@ -0,0 +1,109 @@
|
||||
#ifndef QJS_SDL_H
|
||||
#define QJS_SDL_H
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include "cell.h"
|
||||
|
||||
// Simple vector types to replace HandmadeMath dependency
|
||||
typedef struct {
|
||||
float x, y;
|
||||
} vec2;
|
||||
|
||||
typedef struct {
|
||||
float x, y, z;
|
||||
} vec3;
|
||||
|
||||
typedef struct {
|
||||
float x, y, z, w;
|
||||
} vec4;
|
||||
|
||||
typedef struct {
|
||||
float x, y, z, w;
|
||||
} quat;
|
||||
|
||||
typedef union {
|
||||
struct { float x, y, z, w; };
|
||||
float e[4];
|
||||
} vec4_union;
|
||||
|
||||
SDL_Window *js2SDL_Window(JSContext *js, JSValue v);
|
||||
JSValue SDL_Window2js(JSContext *js, SDL_Window *w);
|
||||
|
||||
SDL_PixelFormat str2pixelformat(const char *str);
|
||||
SDL_PixelFormat js2pixelformat(JSContext *js, JSValue v);
|
||||
JSValue pixelformat2js(JSContext *js, SDL_PixelFormat format);
|
||||
const char *pixelformat2str(SDL_PixelFormat format);
|
||||
|
||||
// New enum system functions
|
||||
int js2SDL_PixelFormat(JSContext *js, JSValue v);
|
||||
JSValue SDL_PixelFormat2js(JSContext *js, int enumval);
|
||||
SDL_Colorspace str2colorspace(const char *str);
|
||||
SDL_Colorspace js2colorspace(JSContext *js, JSValue v);
|
||||
JSValue colorspace2js(JSContext *js, SDL_Colorspace colorspace);
|
||||
const char *colorspace2str(SDL_Colorspace colorspace);
|
||||
|
||||
// SDL Scale Mode functions
|
||||
SDL_ScaleMode js2SDL_ScaleMode(JSContext *js, JSValue v);
|
||||
JSValue SDL_ScaleMode2js(JSContext *js, SDL_ScaleMode mode);
|
||||
|
||||
// Surface type
|
||||
typedef struct SDL_Surface SDL_Surface;
|
||||
SDL_Surface *js2SDL_Surface(JSContext *js, JSValue v);
|
||||
JSValue SDL_Surface2js(JSContext *js, SDL_Surface *s);
|
||||
|
||||
struct lrtb {
|
||||
float l;
|
||||
float r;
|
||||
float t;
|
||||
float b;
|
||||
};
|
||||
typedef struct lrtb lrtb;
|
||||
|
||||
lrtb js2lrtb(JSContext *js, JSValue v);
|
||||
JSValue lrtb2js(JSContext *js, lrtb r);
|
||||
|
||||
struct text_vert {
|
||||
vec2 pos;
|
||||
vec2 uv;
|
||||
vec4 color;
|
||||
};
|
||||
|
||||
typedef struct text_vert text_vert;
|
||||
|
||||
JSValue quads_to_mesh(JSContext *js, text_vert *argv);
|
||||
|
||||
typedef vec4 colorf;
|
||||
typedef SDL_FRect rect;
|
||||
typedef SDL_Rect irect;
|
||||
|
||||
// Common conversion functions used across modules
|
||||
JSValue rect2js(JSContext *js, rect r);
|
||||
JSValue vec22js(JSContext *js, vec2 v);
|
||||
JSValue vec32js(JSContext *js, vec3 v);
|
||||
JSValue vec42js(JSContext *js, vec4 v);
|
||||
JSValue quat2js(JSContext *js, quat q);
|
||||
JSValue color2js(JSContext *js, colorf c);
|
||||
JSValue angle2js(JSContext *js, double a);
|
||||
|
||||
rect js2rect(JSContext *js, JSValue v);
|
||||
vec2 js2vec2(JSContext *js, JSValue v);
|
||||
vec3 js2vec3(JSContext *js, JSValue v);
|
||||
vec4 js2vec4(JSContext *js, JSValue v);
|
||||
quat js2quat(JSContext *js, JSValue v);
|
||||
colorf js2color(JSContext *js, JSValue v);
|
||||
double js2angle(JSContext *js, JSValue v);
|
||||
|
||||
#define RGBA_MAX 255
|
||||
|
||||
struct rgba {
|
||||
unsigned char r;
|
||||
unsigned char g;
|
||||
unsigned char b;
|
||||
unsigned char a;
|
||||
};
|
||||
|
||||
typedef struct rgba rgba;
|
||||
|
||||
float *rgba2floats(float *r, struct rgba c);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user