Carp/core/SDLHelper.h

104 lines
1.6 KiB
C
Raw Normal View History

2020-10-15 14:14:31 +03:00
#define Uint8 SDLUint8
#define Uint16 SDLUint16
#define Uint32 SDLUint32
#define Uint64 SDLUint64
2020-04-10 18:31:51 +03:00
#include <SDL2/SDL.h>
2020-10-15 14:14:31 +03:00
#undef Uint8
#undef Uint16
#undef Uint32
#undef Uint64
2017-06-26 12:15:03 +03:00
2018-03-20 18:18:44 +03:00
// Event
SDL_Event SDL_Event_init() {
2017-06-26 12:15:03 +03:00
SDL_Event e;
2019-06-14 14:13:22 +03:00
memset(&e, 0, sizeof(e));
2017-06-26 12:15:03 +03:00
return e;
}
int SDL_Event_type(SDL_Event *e) {
return e->type;
}
2017-06-26 12:15:03 +03:00
SDL_Keycode SDL_Event_keycode(SDL_Event *e) {
return e->key.keysym.sym;
}
2017-06-26 12:15:03 +03:00
bool SDL_Event__EQ_(SDL_EventType a, SDL_EventType b) {
return a == b;
}
2018-03-20 18:18:44 +03:00
SDL_Event SDL_Event_copy(SDL_Event *e) {
return *e;
}
2018-03-20 18:18:44 +03:00
// Keycode
2017-06-26 12:15:03 +03:00
SDL_Keycode SDL_Keycode_copy(SDL_Keycode *a) {
return *a;
}
2018-03-19 15:01:14 +03:00
String SDL_Keycode_str(SDL_Keycode a) {
char *buffer = CARP_MALLOC(32);
snprintf(buffer, 32, "%d", a);
return buffer;
}
2018-03-20 18:18:44 +03:00
// Helpers
2018-03-20 14:49:46 +03:00
SDL_Rect SDL_rect(int x, int y, int w, int h) {
2017-06-26 12:15:03 +03:00
SDL_Rect r;
r.x = x;
r.y = y;
r.w = w;
r.h = h;
return r;
}
2018-03-20 14:49:46 +03:00
SDL_Point SDL_point(int x, int y) {
2017-06-26 12:15:03 +03:00
SDL_Point p;
p.x = x;
p.y = y;
return p;
}
2018-03-22 15:36:16 +03:00
SDL_Color SDL_rgb(int r, int g, int b) {
SDL_Color p;
p.r = r;
p.g = g;
p.b = b;
p.a = 255;
return p;
}
2018-03-22 15:36:16 +03:00
SDL_Color SDL_rgba(int r, int g, int b, int a) {
SDL_Color p;
p.r = r;
p.g = g;
p.b = b;
p.a = a;
return p;
}
int SDL_Color_r(SDL_Color *col) {
return (int)(col->r);
}
int SDL_Color_g(SDL_Color *col) {
return (int)(col->g);
}
int SDL_Color_b(SDL_Color *col) {
return (int)(col->b);
}
int SDL_Color_a(SDL_Color *col) {
return (int)(col->a);
}
2018-11-15 17:25:57 +03:00
void *SDL_SurfacePixels(SDL_Surface *s) {
return s->pixels;
}
2018-11-15 17:25:57 +03:00
int SDL_SurfacePitch(SDL_Surface *s) {
return s->pitch;
}