diff options
-rw-r--r-- | c_src/esdl2.h | 1 | ||||
-rw-r--r-- | c_src/sdl_renderer.c | 30 | ||||
-rw-r--r-- | src/esdl2.erl | 4 | ||||
-rw-r--r-- | src/sdl_renderer.erl | 8 |
4 files changed, 43 insertions, 0 deletions
diff --git a/c_src/esdl2.h b/c_src/esdl2.h index 1f0ee3c..f0e54c9 100644 --- a/c_src/esdl2.h +++ b/c_src/esdl2.h @@ -151,6 +151,7 @@ F(create_renderer, 3) \ F(get_num_render_drivers, 0) \ F(get_render_draw_blend_mode, 1) \ + F(get_render_draw_color, 1) \ F(render_clear, 1) \ F(render_copy, 4) \ F(render_present, 1) \ diff --git a/c_src/sdl_renderer.c b/c_src/sdl_renderer.c index 5f90f14..7787a3c 100644 --- a/c_src/sdl_renderer.c +++ b/c_src/sdl_renderer.c @@ -133,6 +133,36 @@ NIF_FUNCTION(get_render_draw_blend_mode) NIF_RES_GET(Renderer, renderer_res)); } +// get_render_draw_color + +NIF_CALL_HANDLER(thread_get_render_draw_color) +{ + Uint8 r, g, b, a; + + if (SDL_GetRenderDrawColor(args[0], &r, &g, &b, &a)) + return sdl_error_tuple(env); + + return enif_make_tuple2(env, + atom_ok, + enif_make_tuple4(env, + enif_make_uint(env, r), + enif_make_uint(env, g), + enif_make_uint(env, b), + enif_make_uint(env, a) + ) + ); +} + +NIF_FUNCTION(get_render_draw_color) +{ + void* renderer_res; + + BADARG_IF(!enif_get_resource(env, argv[0], res_Renderer, &renderer_res)); + + return nif_thread_call(env, thread_get_render_draw_color, 1, + NIF_RES_GET(Renderer, renderer_res)); +} + // render_clear NIF_CALL_HANDLER(thread_render_clear) diff --git a/src/esdl2.erl b/src/esdl2.erl index add7453..a64ee4c 100644 --- a/src/esdl2.erl +++ b/src/esdl2.erl @@ -56,6 +56,7 @@ -export([create_renderer/3]). -export([get_num_render_drivers/0]). -export([get_render_draw_blend_mode/1]). +-export([get_render_draw_color/1]). -export([render_clear/1]). -export([render_copy/4]). -export([render_present/1]). @@ -215,6 +216,9 @@ get_num_render_drivers() -> get_render_draw_blend_mode(_) -> erlang:nif_error({not_loaded, ?MODULE}). +get_render_draw_color(_) -> + erlang:nif_error({not_loaded, ?MODULE}). + render_clear(_) -> erlang:nif_error({not_loaded, ?MODULE}). diff --git a/src/sdl_renderer.erl b/src/sdl_renderer.erl index 18c368c..01bc314 100644 --- a/src/sdl_renderer.erl +++ b/src/sdl_renderer.erl @@ -17,6 +17,7 @@ -export([create/3]). -export([count_drivers/0]). -export([get_draw_blend_mode/1]). +-export([get_draw_color/1]). -export([clear/1]). -export([copy/2]). -export([copy/4]). @@ -39,6 +40,13 @@ get_draw_blend_mode(Renderer) -> Mode end. +get_draw_color(Renderer) -> + esdl2:get_render_draw_color(Renderer), + receive {'_nif_thread_ret_', Ret} -> + {ok, Mode} = Ret, + Mode + end. + clear(Renderer) -> esdl2:render_clear(Renderer), receive {'_nif_thread_ret_', Ret} -> Ret end. |