aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2014-04-03 18:50:37 +0200
committerLoïc Hoguin <[email protected]>2014-04-03 19:02:54 +0200
commit8ee7b5dd33119f6a762b56735bdecce0ec165961 (patch)
tree6144a7ced68d343f24980434d970af60eeddf24e
parenta5d9a7becebd1b32d8b25a7de64fa710ea173136 (diff)
downloadesdl2-8ee7b5dd33119f6a762b56735bdecce0ec165961.tar.gz
esdl2-8ee7b5dd33119f6a762b56735bdecce0ec165961.tar.bz2
esdl2-8ee7b5dd33119f6a762b56735bdecce0ec165961.zip
Add sdl_window:grab_input/2
-rw-r--r--c_src/esdl2.h1
-rw-r--r--c_src/sdl_bool.c21
-rw-r--r--c_src/sdl_window.c19
-rw-r--r--src/esdl2.erl4
-rw-r--r--src/sdl_window.erl4
5 files changed, 49 insertions, 0 deletions
diff --git a/c_src/esdl2.h b/c_src/esdl2.h
index d1d4ae7..d8da051 100644
--- a/c_src/esdl2.h
+++ b/c_src/esdl2.h
@@ -179,6 +179,7 @@
F(set_window_bordered, 2) \
F(set_window_brightness, 2) \
F(set_window_fullscreen, 2) \
+ F(set_window_grab, 2) \
// Generated declarations for the NIF.
diff --git a/c_src/sdl_bool.c b/c_src/sdl_bool.c
new file mode 100644
index 0000000..778ac43
--- /dev/null
+++ b/c_src/sdl_bool.c
@@ -0,0 +1,21 @@
+// Copyright (c) 2014, Loïc Hoguin <[email protected]>
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+#include "esdl2.h"
+
+#define BOOL_ENUM(E) \
+ E(false, SDL_FALSE) \
+ E(true, SDL_TRUE)
+
+NIF_ATOM_TO_ENUM_FUNCTION(atom_to_bool, SDL_bool, BOOL_ENUM)
diff --git a/c_src/sdl_window.c b/c_src/sdl_window.c
index 6cc37a8..bdd66a4 100644
--- a/c_src/sdl_window.c
+++ b/c_src/sdl_window.c
@@ -507,3 +507,22 @@ NIF_FUNCTION(set_window_fullscreen)
return nif_thread_call(env, thread_set_window_fullscreen, 2,
NIF_RES_GET(Window, window_res), flags);
}
+
+// set_window_grab
+
+NIF_CAST_HANDLER(thread_set_window_grab)
+{
+ SDL_SetWindowGrab(args[0], (long)args[1]);
+}
+
+NIF_FUNCTION(set_window_grab)
+{
+ void* window_res;
+ SDL_bool b;
+
+ BADARG_IF(!enif_get_resource(env, argv[0], res_Window, &window_res));
+ BADARG_IF(!atom_to_bool(env, argv[1], &b));
+
+ return nif_thread_cast(env, thread_set_window_grab, 2,
+ NIF_RES_GET(Window, window_res), b);
+}
diff --git a/src/esdl2.erl b/src/esdl2.erl
index 144e8dd..4abc20b 100644
--- a/src/esdl2.erl
+++ b/src/esdl2.erl
@@ -91,6 +91,7 @@
-export([set_window_bordered/2]).
-export([set_window_brightness/2]).
-export([set_window_fullscreen/2]).
+-export([set_window_grab/2]).
%% @todo We probably want to accept an env variable or somthing for the location.
-on_load(on_load/0).
@@ -293,3 +294,6 @@ set_window_brightness(_, _) ->
set_window_fullscreen(_, _) ->
erlang:nif_error({not_loaded, ?MODULE}).
+
+set_window_grab(_, _) ->
+ erlang:nif_error({not_loaded, ?MODULE}).
diff --git a/src/sdl_window.erl b/src/sdl_window.erl
index f675f26..0da1e57 100644
--- a/src/sdl_window.erl
+++ b/src/sdl_window.erl
@@ -34,6 +34,7 @@
-export([set_bordered/2]).
-export([set_brightness/2]).
-export([set_fullscreen/2]).
+-export([grab_input/2]).
create(Title, X, Y, W, H, Flags) ->
esdl2:create_window(Title, X, Y, W, H, Flags),
@@ -111,3 +112,6 @@ set_brightness(Window, Brightness) ->
set_fullscreen(Window, Flag) ->
esdl2:set_window_fullscreen(Window, Flag),
receive {'_nif_thread_ret_', Ret} -> Ret end.
+
+grab_input(Window, Grab) ->
+ esdl2:set_window_grab(Window, Grab).