]> git.jsancho.org Git - guile-irrlicht.git/blob - src/gui-skin.cpp
get-color
[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 "color.h"
26 #include "gsubr.h"
27 #include "gui-font.h"
28 #include "gui-skin.h"
29 #include "wrapped.h"
30
31 extern "C" {
32
33   void
34   init_gui_skin (void)
35   {
36     init_gui_skin_type ();
37     DEFINE_GSUBR ("set-font!", 2, 0, 1, irr_gui_setFont);
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_IGUISkin_getColor (SCM wrapped_gui_skin,
46                              SCM color)
47   {
48     irr::gui::IGUISkin* skin = unwrap_gui_skin (wrapped_gui_skin);
49     irr::video::SColor scolor = skin->getColor (scm_to_default_color (color));
50     return scm_from_color (scolor);
51   }
52
53   SCM
54   irr_gui_IGUISkin_getFont (SCM wrapped_gui_skin,
55                             SCM rest)
56   {
57     SCM which = scm_from_utf8_symbol ("default");
58
59     scm_c_bind_keyword_arguments ("get-font", rest, (scm_t_keyword_arguments_flags)0,
60                                   scm_from_utf8_keyword ("which"), &which,
61                                   SCM_UNDEFINED);
62
63     irr::gui::IGUISkin* skin = unwrap_gui_skin (wrapped_gui_skin);
64     irr::gui::IGUIFont* font = skin->getFont (scm_to_default_font (which));
65     return wrap_gui_font (font);
66   }
67
68   SCM
69   irr_gui_setFont (SCM wrapped_gui_skin,
70                    SCM font,
71                    SCM rest)
72   {
73     SCM which = scm_from_utf8_symbol ("default");
74
75     scm_c_bind_keyword_arguments ("set-font!", rest, (scm_t_keyword_arguments_flags)0,
76                                   scm_from_utf8_keyword ("which"), &which,
77                                   SCM_UNDEFINED);
78
79     irr::gui::IGUISkin* skin = unwrap_gui_skin (wrapped_gui_skin);
80     skin->setFont (unwrap_gui_font (font),
81                    scm_to_default_font (which));
82     return SCM_UNSPECIFIED;
83   }
84
85   irr::gui::EGUI_DEFAULT_COLOR
86   scm_to_default_color (SCM default_color)
87   {
88     char* color = scm_to_utf8_stringn (scm_symbol_to_string (default_color), NULL);
89     if (!strcmp (color, "3d-dark-shadow"))
90       {
91         return irr::gui::EGDC_3D_DARK_SHADOW;
92       }
93     else if (!strcmp (color, "3d-shadow"))
94       {
95         return irr::gui::EGDC_3D_SHADOW;
96       }
97     else if (!strcmp (color, "3d-face"))
98       {
99         return irr::gui::EGDC_3D_FACE;
100       }
101     else if (!strcmp (color, "3d-high-light"))
102       {
103         return irr::gui::EGDC_3D_HIGH_LIGHT;
104       }
105     else if (!strcmp (color, "3d-light"))
106       {
107         return irr::gui::EGDC_3D_LIGHT;
108       }
109     else if (!strcmp (color, "active-border"))
110       {
111         return irr::gui::EGDC_ACTIVE_BORDER;
112       }
113     else if (!strcmp (color, "active-caption"))
114       {
115         return irr::gui::EGDC_ACTIVE_CAPTION;
116       }
117     else if (!strcmp (color, "app-workspace"))
118       {
119         return irr::gui::EGDC_APP_WORKSPACE;
120       }
121     else if (!strcmp (color, "button-text"))
122       {
123         return irr::gui::EGDC_BUTTON_TEXT;
124       }
125     else if (!strcmp (color, "gray-text"))
126       {
127         return irr::gui::EGDC_GRAY_TEXT;
128       }
129     else if (!strcmp (color, "high-light"))
130       {
131         return irr::gui::EGDC_HIGH_LIGHT;
132       }
133     else if (!strcmp (color, "high-light-text"))
134       {
135         return irr::gui::EGDC_HIGH_LIGHT_TEXT;
136       }
137     else if (!strcmp (color, "inactive-border"))
138       {
139         return irr::gui::EGDC_INACTIVE_BORDER;
140       }
141     else if (!strcmp (color, "inactive-caption"))
142       {
143         return irr::gui::EGDC_INACTIVE_CAPTION;
144       }
145     else if (!strcmp (color, "tooltip"))
146       {
147         return irr::gui::EGDC_TOOLTIP;
148       }
149     else if (!strcmp (color, "tooltip-background"))
150       {
151         return irr::gui::EGDC_TOOLTIP_BACKGROUND;
152       }
153     else if (!strcmp (color, "scrollbar"))
154       {
155         return irr::gui::EGDC_SCROLLBAR;
156       }
157     else if (!strcmp (color, "window"))
158       {
159         return irr::gui::EGDC_WINDOW;
160       }
161     else if (!strcmp (color, "window-symbol"))
162       {
163         return irr::gui::EGDC_WINDOW_SYMBOL;
164       }
165     else if (!strcmp (color, "icon"))
166       {
167         return irr::gui::EGDC_ICON;
168       }
169     else if (!strcmp (color, "icon-high-light"))
170       {
171         return irr::gui::EGDC_ICON_HIGH_LIGHT;
172       }
173     else if (!strcmp (color, "gray-window-symbol"))
174       {
175         return irr::gui::EGDC_GRAY_WINDOW_SYMBOL;
176       }
177     else if (!strcmp (color, "editable"))
178       {
179         return irr::gui::EGDC_EDITABLE;
180       }
181     else if (!strcmp (color, "gray-editable"))
182       {
183         return irr::gui::EGDC_GRAY_EDITABLE;
184       }
185     else if (!strcmp (color, "focused-editable"))
186       {
187         return irr::gui::EGDC_FOCUSED_EDITABLE;
188       }
189     else
190       {
191         scm_error (scm_arg_type_key, NULL, "Wrong default color: ~S",
192                    scm_list_1 (default_color), scm_list_1 (default_color));
193       }
194   }
195
196   irr::gui::EGUI_DEFAULT_FONT
197   scm_to_default_font (SCM default_font)
198   {
199     char* font = scm_to_utf8_stringn (scm_symbol_to_string (default_font), NULL);
200     if (!strcmp (font, "default"))
201       {
202         return irr::gui::EGDF_DEFAULT;
203       }
204     else if (!strcmp (font, "button"))
205       {
206         return irr::gui::EGDF_BUTTON;
207       }
208     else if (!strcmp (font, "window"))
209       {
210         return irr::gui::EGDF_WINDOW;
211       }
212     else if (!strcmp (font, "menu"))
213       {
214         return irr::gui::EGDF_MENU;
215       }
216     else if (!strcmp (font, "tooltip"))
217       {
218         return irr::gui::EGDF_TOOLTIP;
219       }
220     else
221       {
222         scm_error (scm_arg_type_key, NULL, "Wrong default font: ~S",
223                    scm_list_1 (default_font), scm_list_1 (default_font));
224       }
225   }
226 }