From bc5bcab82c15731b585936f375330b5c1aad3ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Thu, 3 Apr 2014 13:29:12 +0200 Subject: Add sdl_window:get_pos/1 --- c_src/esdl2.h | 1 + c_src/sdl_window.c | 24 ++++++++++++++++++++++++ src/esdl2.erl | 4 ++++ src/sdl_window.erl | 5 +++++ 4 files changed, 34 insertions(+) diff --git a/c_src/esdl2.h b/c_src/esdl2.h index cab3a1a..3a69b8f 100644 --- a/c_src/esdl2.h +++ b/c_src/esdl2.h @@ -168,6 +168,7 @@ F(get_window_id, 1) \ F(get_window_maximum_size, 1) \ F(get_window_minimum_size, 1) \ + F(get_window_position, 1) \ // Generated declarations for the NIF. diff --git a/c_src/sdl_window.c b/c_src/sdl_window.c index 242763e..9ddd3f4 100644 --- a/c_src/sdl_window.c +++ b/c_src/sdl_window.c @@ -278,3 +278,27 @@ NIF_FUNCTION(get_window_minimum_size) return nif_thread_call(env, thread_get_window_minimum_size, 1, NIF_RES_GET(Window, window_res)); } + +// get_window_position + +NIF_CALL_HANDLER(thread_get_window_position) +{ + int x, y; + + SDL_GetWindowPosition(args[0], &x, &y); + + return enif_make_tuple2(env, + enif_make_int(env, x), + enif_make_int(env, y) + ); +} + +NIF_FUNCTION(get_window_position) +{ + void* window_res; + + BADARG_IF(!enif_get_resource(env, argv[0], res_Window, &window_res)); + + return nif_thread_call(env, thread_get_window_position, 1, + NIF_RES_GET(Window, window_res)); +} diff --git a/src/esdl2.erl b/src/esdl2.erl index 0483779..0d838d4 100644 --- a/src/esdl2.erl +++ b/src/esdl2.erl @@ -80,6 +80,7 @@ -export([get_window_id/1]). -export([get_window_maximum_size/1]). -export([get_window_minimum_size/1]). +-export([get_window_position/1]). %% @todo We probably want to accept an env variable or somthing for the location. -on_load(on_load/0). @@ -249,3 +250,6 @@ get_window_maximum_size(_) -> get_window_minimum_size(_) -> erlang:nif_error({not_loaded, ?MODULE}). + +get_window_position(_) -> + erlang:nif_error({not_loaded, ?MODULE}). diff --git a/src/sdl_window.erl b/src/sdl_window.erl index 0dc0421..2242464 100644 --- a/src/sdl_window.erl +++ b/src/sdl_window.erl @@ -23,6 +23,7 @@ -export([get_id/1]). -export([get_max_size/1]). -export([get_min_size/1]). +-export([get_pos/1]). create(Title, X, Y, W, H, Flags) -> esdl2:create_window(Title, X, Y, W, H, Flags), @@ -62,3 +63,7 @@ get_max_size(Window) -> get_min_size(Window) -> esdl2:get_window_minimum_size(Window), receive {'_nif_thread_ret_', Ret} -> Ret end. + +get_pos(Window) -> + esdl2:get_window_position(Window), + receive {'_nif_thread_ret_', Ret} -> Ret end. -- cgit v1.2.3