From 0e6c291c64e77181851b8a3255a3da8827124080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Tue, 6 Feb 2018 00:05:12 +0100 Subject: Initial work on the SDL_ttf functions --- c_src/sdl_pixels.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'c_src/sdl_pixels.c') diff --git a/c_src/sdl_pixels.c b/c_src/sdl_pixels.c index aa22329..1bdec60 100644 --- a/c_src/sdl_pixels.c +++ b/c_src/sdl_pixels.c @@ -60,3 +60,34 @@ NIF_ENUM_TO_ATOM_FUNCTION(pixel_format_to_atom, Uint32, PIXEL_FORMAT_ENUM) NIF_ATOM_TO_ENUM_FUNCTION(atom_to_pixel_format, Uint32, PIXEL_FORMAT_ENUM) + +int map_to_color(ErlNifEnv* env, ERL_NIF_TERM map, SDL_Color* color) +{ + ERL_NIF_TERM r, g, b, a; + unsigned int ri, gi, bi, ai; + + if (!enif_get_map_value(env, map, atom_r, &r)) + return 0; + if (!enif_get_map_value(env, map, atom_g, &g)) + return 0; + if (!enif_get_map_value(env, map, atom_b, &b)) + return 0; + if (!enif_get_map_value(env, map, atom_a, &a)) + return 0; + + if (!enif_get_uint(env, r, &ri)) + return 0; + if (!enif_get_uint(env, g, &gi)) + return 0; + if (!enif_get_uint(env, b, &bi)) + return 0; + if (!enif_get_uint(env, a, &ai)) + return 0; + + color->r = ri; + color->g = gi; + color->b = bi; + color->a = ai; + + return 1; +} -- cgit v1.2.3