]> git.jsancho.org Git - guile-irrlicht.git/blob - src/gui-skin.cpp
set-skin-font! get-built-in-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     DEFINE_GSUBR ("set-skin-font!", 2, 0, 1, irr_gui_setSkinFont);
38   }
39
40   DEFINE_WRAPPED_TYPE (irr::gui::IGUISkin*, "gui-skin",
41                        init_gui_skin_type, gui_skin_p,
42                        wrap_gui_skin, unwrap_gui_skin);
43
44   SCM
45   irr_gui_getSkinFont (SCM wrapped_gui_skin,
46                        SCM rest)
47   {
48     SCM which = scm_from_utf8_symbol ("default");
49
50     scm_c_bind_keyword_arguments ("get-skin-font", rest, (scm_t_keyword_arguments_flags)0,
51                                   scm_from_utf8_keyword ("which"), &which,
52                                   SCM_UNDEFINED);
53
54     irr::gui::IGUISkin* skin = unwrap_gui_skin (wrapped_gui_skin);
55     irr::gui::IGUIFont* font = skin->getFont (scm_to_default_font (which));
56     return wrap_gui_font (font);
57   }
58
59   SCM
60   irr_gui_setSkinFont (SCM wrapped_gui_skin,
61                        SCM font,
62                        SCM rest)
63   {
64     SCM which = scm_from_utf8_symbol ("default");
65
66     scm_c_bind_keyword_arguments ("get-skin-font", rest, (scm_t_keyword_arguments_flags)0,
67                                   scm_from_utf8_keyword ("which"), &which,
68                                   SCM_UNDEFINED);
69
70     irr::gui::IGUISkin* skin = unwrap_gui_skin (wrapped_gui_skin);
71     skin->setFont (unwrap_gui_font (font),
72                    scm_to_default_font (which));
73     return SCM_UNSPECIFIED;
74   }
75
76   irr::gui::EGUI_DEFAULT_FONT
77   scm_to_default_font (SCM default_font)
78   {
79     char* font = scm_to_utf8_stringn (scm_symbol_to_string (default_font), NULL);
80     if (!strcmp (font, "default"))
81       {
82         return irr::gui::EGDF_DEFAULT;
83       }
84     else if (!strcmp (font, "button"))
85       {
86         return irr::gui::EGDF_BUTTON;
87       }
88     else if (!strcmp (font, "window"))
89       {
90         return irr::gui::EGDF_WINDOW;
91       }
92     else if (!strcmp (font, "menu"))
93       {
94         return irr::gui::EGDF_MENU;
95       }
96     else if (!strcmp (font, "tooltip"))
97       {
98         return irr::gui::EGDF_TOOLTIP;
99       }
100     else
101       {
102         scm_error (scm_arg_type_key, NULL, "Wrong default font: ~S",
103                    scm_list_1 (default_font), scm_list_1 (default_font));
104       }
105   }
106 }