aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-12-21 23:32:18 +0100
committerLoïc Hoguin <[email protected]>2017-12-21 23:32:18 +0100
commit9a8a6bf9b8414470952b008c84515b9516ddc7f2 (patch)
treed7c69c3fc273e25a5e9f8c23e1750c42bd63d7e3 /src
parentb0950785e72d9d59c6fd816c01d203ecb083c663 (diff)
downloadesdl2-9a8a6bf9b8414470952b008c84515b9516ddc7f2.tar.gz
esdl2-9a8a6bf9b8414470952b008c84515b9516ddc7f2.tar.bz2
esdl2-9a8a6bf9b8414470952b008c84515b9516ddc7f2.zip
Add sdl_cursor along with all its related functions
Diffstat (limited to 'src')
-rw-r--r--src/esdl2.erl32
-rw-r--r--src/sdl_cursor.erl80
2 files changed, 112 insertions, 0 deletions
diff --git a/src/esdl2.erl b/src/esdl2.erl
index 0b1b456..e18a7fc 100644
--- a/src/esdl2.erl
+++ b/src/esdl2.erl
@@ -45,6 +45,15 @@
-export([has_sse41/0]).
-export([has_sse42/0]).
+%% sdl_cursor
+-export([create_cursor/6]).
+-export([create_color_cursor/3]).
+-export([create_system_cursor/1]).
+-export([get_cursor/0]).
+-export([get_default_cursor/0]).
+-export([set_cursor/1]).
+-export([show_cursor/1]).
+
%% sdl_events
-export([poll_event/0]).
@@ -243,6 +252,29 @@ has_sse41() ->
has_sse42() ->
erlang:nif_error({not_loaded, ?MODULE}).
+%% sdl_cursor
+
+create_cursor(_, _, _, _, _, _) ->
+ erlang:nif_error({not_loaded, ?MODULE}).
+
+create_color_cursor(_, _, _) ->
+ erlang:nif_error({not_loaded, ?MODULE}).
+
+create_system_cursor(_) ->
+ erlang:nif_error({not_loaded, ?MODULE}).
+
+get_cursor() ->
+ erlang:nif_error({not_loaded, ?MODULE}).
+
+get_default_cursor() ->
+ erlang:nif_error({not_loaded, ?MODULE}).
+
+set_cursor(_) ->
+ erlang:nif_error({not_loaded, ?MODULE}).
+
+show_cursor(_) ->
+ erlang:nif_error({not_loaded, ?MODULE}).
+
%% sdl_events
poll_event() ->
diff --git a/src/sdl_cursor.erl b/src/sdl_cursor.erl
new file mode 100644
index 0000000..373838d
--- /dev/null
+++ b/src/sdl_cursor.erl
@@ -0,0 +1,80 @@
+%% Copyright (c) 2017, 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.
+
+-module(sdl_cursor).
+
+-export([create/1]).
+-export([create/3]).
+-export([create/6]).
+-export([get_current/0]).
+-export([get_default/0]).
+-export([hide/0]).
+-export([is_visible/0]).
+-export([set/1]).
+-export([show/0]).
+
+-opaque cursor() :: <<>>.
+-export_type([cursor/0]).
+
+-type system_cursor() :: arrow | ibeam | wait | crosshair | wait_arrow
+ | size_nwse | size_nesw | size_we | size_ns | size_all | no | hand.
+
+-spec create(system_cursor()) -> {ok, cursor()} | sdl:error().
+create(ID) ->
+ esdl2:create_system_cursor(ID),
+ receive {'_nif_thread_ret_', Ret} -> Ret end.
+
+-spec create(sdl_surface:surface(), integer(), integer())
+ -> {ok, cursor()} | sdl:error().
+create(Surface, HotX, HotY) ->
+ esdl2:create_color_cursor(Surface, HotX, HotY),
+ receive {'_nif_thread_ret_', Ret} -> Ret end.
+
+-spec create(binary(), binary(), integer(), integer(), integer(), integer())
+ -> {ok, cursor()} | sdl:error().
+create(Data, Mask, W, H, HotX, HotY) ->
+ esdl2:create_cursor(Data, Mask, W, H, HotX, HotY),
+ receive {'_nif_thread_ret_', Ret} -> Ret end.
+
+-spec get_current() -> cursor().
+get_current() ->
+ esdl2:get_cursor(),
+ receive {'_nif_thread_ret_', Ret} -> Ret end.
+
+-spec get_default() -> cursor().
+get_default() ->
+ esdl2:get_default_cursor(),
+ receive {'_nif_thread_ret_', Ret} -> Ret end.
+
+-spec hide() -> ok.
+hide() ->
+ esdl2:show_cursor(0),
+ receive {'_nif_thread_ret_', _} -> ok end.
+
+-spec is_visible() -> ok.
+is_visible() ->
+ esdl2:show_cursor(-1),
+ receive
+ {'_nif_thread_ret_', 0} -> false;
+ {'_nif_thread_ret_', 1} -> true
+ end.
+
+-spec set(cursor()) -> ok.
+set(Cursor) ->
+ esdl2:set_cursor(Cursor).
+
+-spec show() -> ok.
+show() ->
+ esdl2:show_cursor(1),
+ receive {'_nif_thread_ret_', _} -> ok end.