aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2014-04-03 13:50:11 +0200
committerLoïc Hoguin <[email protected]>2014-04-03 14:37:15 +0200
commitba902081dd0386455dedc247a89f645ff9135877 (patch)
treecfab78cb9a6b4a95cc4fcd2ec22841a2044e0eb4
parentbc5bcab82c15731b585936f375330b5c1aad3ed5 (diff)
downloadesdl2-ba902081dd0386455dedc247a89f645ff9135877.tar.gz
esdl2-ba902081dd0386455dedc247a89f645ff9135877.tar.bz2
esdl2-ba902081dd0386455dedc247a89f645ff9135877.zip
Add sdl_window:get_size/1
-rw-r--r--c_src/esdl2.h1
-rw-r--r--c_src/sdl_window.c24
-rw-r--r--src/esdl2.erl4
-rw-r--r--src/sdl_window.erl5
4 files changed, 34 insertions, 0 deletions
diff --git a/c_src/esdl2.h b/c_src/esdl2.h
index 3a69b8f..7aea80f 100644
--- a/c_src/esdl2.h
+++ b/c_src/esdl2.h
@@ -169,6 +169,7 @@
F(get_window_maximum_size, 1) \
F(get_window_minimum_size, 1) \
F(get_window_position, 1) \
+ F(get_window_size, 1) \
// Generated declarations for the NIF.
diff --git a/c_src/sdl_window.c b/c_src/sdl_window.c
index 9ddd3f4..becf4d4 100644
--- a/c_src/sdl_window.c
+++ b/c_src/sdl_window.c
@@ -302,3 +302,27 @@ NIF_FUNCTION(get_window_position)
return nif_thread_call(env, thread_get_window_position, 1,
NIF_RES_GET(Window, window_res));
}
+
+// get_window_size
+
+NIF_CALL_HANDLER(thread_get_window_size)
+{
+ int w, h;
+
+ SDL_GetWindowSize(args[0], &w, &h);
+
+ return enif_make_tuple2(env,
+ enif_make_int(env, w),
+ enif_make_int(env, h)
+ );
+}
+
+NIF_FUNCTION(get_window_size)
+{
+ void* window_res;
+
+ BADARG_IF(!enif_get_resource(env, argv[0], res_Window, &window_res));
+
+ return nif_thread_call(env, thread_get_window_size, 1,
+ NIF_RES_GET(Window, window_res));
+}
diff --git a/src/esdl2.erl b/src/esdl2.erl
index 0d838d4..352d0e9 100644
--- a/src/esdl2.erl
+++ b/src/esdl2.erl
@@ -81,6 +81,7 @@
-export([get_window_maximum_size/1]).
-export([get_window_minimum_size/1]).
-export([get_window_position/1]).
+-export([get_window_size/1]).
%% @todo We probably want to accept an env variable or somthing for the location.
-on_load(on_load/0).
@@ -253,3 +254,6 @@ get_window_minimum_size(_) ->
get_window_position(_) ->
erlang:nif_error({not_loaded, ?MODULE}).
+
+get_window_size(_) ->
+ erlang:nif_error({not_loaded, ?MODULE}).
diff --git a/src/sdl_window.erl b/src/sdl_window.erl
index 2242464..dc265f1 100644
--- a/src/sdl_window.erl
+++ b/src/sdl_window.erl
@@ -24,6 +24,7 @@
-export([get_max_size/1]).
-export([get_min_size/1]).
-export([get_pos/1]).
+-export([get_size/1]).
create(Title, X, Y, W, H, Flags) ->
esdl2:create_window(Title, X, Y, W, H, Flags),
@@ -67,3 +68,7 @@ get_min_size(Window) ->
get_pos(Window) ->
esdl2:get_window_position(Window),
receive {'_nif_thread_ret_', Ret} -> Ret end.
+
+get_size(Window) ->
+ esdl2:get_window_size(Window),
+ receive {'_nif_thread_ret_', Ret} -> Ret end.