]> git.jsancho.org Git - guile-irrlicht.git/blob - src/gui-skin.cpp
get-font get-skin-font
[guile-irrlicht.git] / src / gui-skin.cpp
1 /* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine
2
3    Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
4
5    This file is part of guile-irrlicht.
6
7    guile-irrlicht is free software; you can redistribute it and/or modify
8    it under the terms of the GNU Lesser General Public License as
9    published by the Free Software Foundation; either version 3 of the
10    License, or (at your option) any later version.
11
12    guile-irrlicht is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16
17    You should have received a copy of the GNU Lesser General Public
18    License along with guile-irrlicht. If not, see
19    <http://www.gnu.org/licenses/>.
20 */
21
22 #include <irrlicht/irrlicht.h>
23 #include <libguile.h>
24
25 #include "gsubr.h"
26 #include "gui-font.h"
27 #include "gui-skin.h"
28 #include "wrapped.h"
29
30 extern "C" {
31
32   void
33   init_gui_skin (void)
34   {
35     init_gui_skin_type ();
36     DEFINE_GSUBR ("get-skin-font", 1, 0, 1, irr_gui_getSkinFont);
37   }
38
39   DEFINE_WRAPPED_TYPE (irr::gui::IGUISkin*, "gui-skin",
40                        init_gui_skin_type, gui_skin_p,
41                        wrap_gui_skin, unwrap_gui_skin);
42
43   SCM
44   irr_gui_getSkinFont (SCM wrapped_gui_skin,
45                        SCM rest)
46   {
47     SCM which = scm_from_utf8_symbol ("default");
48
49     scm_c_bind_keyword_arguments ("get-skin-font", rest, (scm_t_keyword_arguments_flags)0,
50                                   scm_from_utf8_keyword ("which"), &which,
51                                   SCM_UNDEFINED);
52
53     irr::gui::IGUISkin* skin = unwrap_gui_skin (wrapped_gui_skin);
54     irr::gui::IGUIFont* font = skin->getFont (scm_to_default_font (which));
55     return wrap_gui_font (font);
56   }
57
58   irr::gui::EGUI_DEFAULT_FONT
59   scm_to_default_font (SCM default_font)
60   {
61     char* font = scm_to_utf8_stringn (scm_symbol_to_string (default_font), NULL);
62     if (!strcmp (font, "default"))
63       {
64         return irr::gui::EGDF_DEFAULT;
65       }
66     else if (!strcmp (font, "button"))
67       {
68         return irr::gui::EGDF_BUTTON;
69       }
70     else if (!strcmp (font, "window"))
71       {
72         return irr::gui::EGDF_WINDOW;
73       }
74     else if (!strcmp (font, "menu"))
75       {
76         return irr::gui::EGDF_MENU;
77       }
78     else if (!strcmp (font, "tooltip"))
79       {
80         return irr::gui::EGDF_TOOLTIP;
81       }
82     else
83       {
84         scm_error (scm_arg_type_key, NULL, "Wrong default font: ~S",
85                    scm_list_1 (default_font), scm_list_1 (default_font));
86       }
87   }
88 }