aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/esdl2.erl28
-rw-r--r--src/sdl_pixels.erl8
-rw-r--r--src/sdl_surface.erl5
-rw-r--r--src/sdl_ttf.erl49
4 files changed, 90 insertions, 0 deletions
diff --git a/src/esdl2.erl b/src/esdl2.erl
index 2198d60..52a2ace 100644
--- a/src/esdl2.erl
+++ b/src/esdl2.erl
@@ -160,6 +160,7 @@
-export([get_num_allocations/0]).
%% sdl_surface
+-export([get_surface_dimensions/1]).
-export([img_load/1]).
%% sdl_texture
@@ -171,6 +172,13 @@
-export([set_texture_blend_mode/2]).
-export([set_texture_color_mod/4]).
+%% sdl_ttf
+-export([ttf_init/0]).
+-export([ttf_open_font/2]).
+-export([ttf_quit/0]).
+-export([ttf_render_utf8_solid/3]).
+-export([ttf_was_init/0]).
+
%% sdl_version
-export([get_version/0]).
-export([get_revision/0]).
@@ -622,6 +630,9 @@ get_num_allocations() ->
%% sdl_surface
+get_surface_dimensions(_) ->
+ erlang:nif_error({not_loaded, ?MODULE}).
+
img_load(_) ->
erlang:nif_error({not_loaded, ?MODULE}).
@@ -648,6 +659,23 @@ set_texture_blend_mode(_, _) ->
set_texture_color_mod(_, _, _, _) ->
erlang:nif_error({not_loaded, ?MODULE}).
+%% sdl_ttf
+
+ttf_init() ->
+ erlang:nif_error({not_loaded, ?MODULE}).
+
+ttf_open_font(_, _) ->
+ erlang:nif_error({not_loaded, ?MODULE}).
+
+ttf_quit() ->
+ erlang:nif_error({not_loaded, ?MODULE}).
+
+ttf_render_utf8_solid(_, _, _) ->
+ erlang:nif_error({not_loaded, ?MODULE}).
+
+ttf_was_init() ->
+ erlang:nif_error({not_loaded, ?MODULE}).
+
%% sdl_version
get_version() ->
diff --git a/src/sdl_pixels.erl b/src/sdl_pixels.erl
index fef9a55..f9ef96a 100644
--- a/src/sdl_pixels.erl
+++ b/src/sdl_pixels.erl
@@ -14,6 +14,14 @@
-module(sdl_pixels).
+-type color() :: #{
+ r := 0..255,
+ g := 0..255,
+ b := 0..255,
+ a := 0..255
+}.
+-export_type([color/0]).
+
-type pixel_format() :: unknown
| index1lsb | index1msb | index4lsb | index4msb | index8
| rgb332 | rgb444 | rgb555 | bgr555
diff --git a/src/sdl_surface.erl b/src/sdl_surface.erl
index a245b64..5740cc5 100644
--- a/src/sdl_surface.erl
+++ b/src/sdl_surface.erl
@@ -14,11 +14,16 @@
-module(sdl_surface).
+-export([get_dimensions/1]).
-export([load/1]).
-opaque surface() :: <<>>.
-export_type([surface/0]).
+-spec get_dimensions(surface()) -> {non_neg_integer(), non_neg_integer()}.
+get_dimensions(Surface) ->
+ esdl2:get_surface_dimensions(Surface).
+
-spec load(string()) -> {ok, surface()} | sdl:error().
load(Filename) ->
esdl2:img_load(Filename),
diff --git a/src/sdl_ttf.erl b/src/sdl_ttf.erl
new file mode 100644
index 0000000..64a84da
--- /dev/null
+++ b/src/sdl_ttf.erl
@@ -0,0 +1,49 @@
+%% Copyright (c) 2018, 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_ttf).
+
+-export([is_started/0]).
+-export([open_font/2]).
+-export([render_solid/3]).
+-export([start/0]).
+-export([stop/0]).
+
+-opaque font() :: reference().
+-export_type([font/0]).
+
+-spec is_started() -> boolean().
+is_started() ->
+ esdl2:ttf_was_init(),
+ receive {'_nif_thread_ret_', Ret} -> Ret end.
+
+-spec open_font(binary(), pos_integer()) -> {ok, font()} | sdl:error().
+open_font(Filename, PointSize) ->
+ esdl2:ttf_open_font(Filename, PointSize),
+ receive {'_nif_thread_ret_', Ret} -> Ret end.
+
+-spec render_solid(font(), binary(), sdl_pixels:color())
+ -> {ok, sdl_surface:surface()} | sdl:error().
+render_solid(Font, Text, Color) ->
+ esdl2:ttf_render_utf8_solid(Font, Text, Color),
+ receive {'_nif_thread_ret_', Ret} -> Ret end.
+
+-spec start() -> ok | sdl:error().
+start() ->
+ esdl2:ttf_init(),
+ receive {'_nif_thread_ret_', Ret} -> Ret end.
+
+-spec stop() -> ok.
+stop() ->
+ esdl2:ttf_quit().