diff options
author | Loïc Hoguin <[email protected]> | 2017-12-21 23:32:18 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2017-12-21 23:32:18 +0100 |
commit | 9a8a6bf9b8414470952b008c84515b9516ddc7f2 (patch) | |
tree | d7c69c3fc273e25a5e9f8c23e1750c42bd63d7e3 /src/sdl_cursor.erl | |
parent | b0950785e72d9d59c6fd816c01d203ecb083c663 (diff) | |
download | esdl2-9a8a6bf9b8414470952b008c84515b9516ddc7f2.tar.gz esdl2-9a8a6bf9b8414470952b008c84515b9516ddc7f2.tar.bz2 esdl2-9a8a6bf9b8414470952b008c84515b9516ddc7f2.zip |
Add sdl_cursor along with all its related functions
Diffstat (limited to 'src/sdl_cursor.erl')
-rw-r--r-- | src/sdl_cursor.erl | 80 |
1 files changed, 80 insertions, 0 deletions
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. |