]> git.jsancho.org Git - guile-irrlicht.git/blob - src/gui-skin.cpp
set-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_IGUISkin_setColor (SCM wrapped_gui_skin,
70                              SCM which,
71                              SCM new_color)
72   {
73     irr::gui::IGUISkin* skin = unwrap_gui_skin (wrapped_gui_skin);
74     skin->setColor (scm_to_default_color (which),
75                     scm_to_color (new_color));
76     return SCM_UNSPECIFIED;
77   }
78
79   SCM
80   irr_gui_setFont (SCM wrapped_gui_skin,
81                    SCM font,
82                    SCM rest)
83   {
84     SCM which = scm_from_utf8_symbol ("default");
85
86     scm_c_bind_keyword_arguments ("set-font!", rest, (scm_t_keyword_arguments_flags)0,
87                                   scm_from_utf8_keyword ("which"), &which,
88                                   SCM_UNDEFINED);
89
90     irr::gui::IGUISkin* skin = unwrap_gui_skin (wrapped_gui_skin);
91     skin->setFont (unwrap_gui_font (font),
92                    scm_to_default_font (which));
93     return SCM_UNSPECIFIED;
94   }
95
96   irr::gui::EGUI_DEFAULT_COLOR
97   scm_to_default_color (SCM default_color)
98   {
99     char* color = scm_to_utf8_stringn (scm_symbol_to_string (default_color), NULL);
100     if (!strcmp (color, "3d-dark-shadow"))
101       {
102         return irr::gui::EGDC_3D_DARK_SHADOW;
103       }
104     else if (!strcmp (color, "3d-shadow"))
105       {
106         return irr::gui::EGDC_3D_SHADOW;
107       }
108     else if (!strcmp (color, "3d-face"))
109       {
110         return irr::gui::EGDC_3D_FACE;
111       }
112     else if (!strcmp (color, "3d-high-light"))
113       {
114         return irr::gui::EGDC_3D_HIGH_LIGHT;
115       }
116     else if (!strcmp (color, "3d-light"))
117       {
118         return irr::gui::EGDC_3D_LIGHT;
119       }
120     else if (!strcmp (color, "active-border"))
121       {
122         return irr::gui::EGDC_ACTIVE_BORDER;
123       }
124     else if (!strcmp (color, "active-caption"))
125       {
126         return irr::gui::EGDC_ACTIVE_CAPTION;
127       }
128     else if (!strcmp (color, "app-workspace"))
129       {
130         return irr::gui::EGDC_APP_WORKSPACE;
131       }
132     else if (!strcmp (color, "button-text"))
133       {
134         return irr::gui::EGDC_BUTTON_TEXT;
135       }
136     else if (!strcmp (color, "gray-text"))
137       {
138         return irr::gui::EGDC_GRAY_TEXT;
139       }
140     else if (!strcmp (color, "high-light"))
141       {
142         return irr::gui::EGDC_HIGH_LIGHT;
143       }
144     else if (!strcmp (color, "high-light-text"))
145       {
146         return irr::gui::EGDC_HIGH_LIGHT_TEXT;
147       }
148     else if (!strcmp (color, "inactive-border"))
149       {
150         return irr::gui::EGDC_INACTIVE_BORDER;
151       }
152     else if (!strcmp (color, "inactive-caption"))
153       {
154         return irr::gui::EGDC_INACTIVE_CAPTION;
155       }
156     else if (!strcmp (color, "tooltip"))
157       {
158         return irr::gui::EGDC_TOOLTIP;
159       }
160     else if (!strcmp (color, "tooltip-background"))
161       {
162         return irr::gui::EGDC_TOOLTIP_BACKGROUND;
163       }
164     else if (!strcmp (color, "scrollbar"))
165       {
166         return irr::gui::EGDC_SCROLLBAR;
167       }
168     else if (!strcmp (color, "window"))
169       {
170         return irr::gui::EGDC_WINDOW;
171       }
172     else if (!strcmp (color, "window-symbol"))
173       {
174         return irr::gui::EGDC_WINDOW_SYMBOL;
175       }
176     else if (!strcmp (color, "icon"))
177       {
178         return irr::gui::EGDC_ICON;
179       }
180     else if (!strcmp (color, "icon-high-light"))
181       {
182         return irr::gui::EGDC_ICON_HIGH_LIGHT;
183       }
184     else if (!strcmp (color, "gray-window-symbol"))
185       {
186         return irr::gui::EGDC_GRAY_WINDOW_SYMBOL;
187       }
188     else if (!strcmp (color, "editable"))
189       {
190         return irr::gui::EGDC_EDITABLE;
191       }
192     else if (!strcmp (color, "gray-editable"))
193       {
194         return irr::gui::EGDC_GRAY_EDITABLE;
195       }
196     else if (!strcmp (color, "focused-editable"))
197       {
198         return irr::gui::EGDC_FOCUSED_EDITABLE;
199       }
200     else
201       {
202         scm_error (scm_arg_type_key, NULL, "Wrong default color: ~S",
203                    scm_list_1 (default_color), scm_list_1 (default_color));
204       }
205   }
206
207   irr::gui::EGUI_DEFAULT_FONT
208   scm_to_default_font (SCM default_font)
209   {
210     char* font = scm_to_utf8_stringn (scm_symbol_to_string (default_font), NULL);
211     if (!strcmp (font, "default"))
212       {
213         return irr::gui::EGDF_DEFAULT;
214       }
215     else if (!strcmp (font, "button"))
216       {
217         return irr::gui::EGDF_BUTTON;
218       }
219     else if (!strcmp (font, "window"))
220       {
221         return irr::gui::EGDF_WINDOW;
222       }
223     else if (!strcmp (font, "menu"))
224       {
225         return irr::gui::EGDF_MENU;
226       }
227     else if (!strcmp (font, "tooltip"))
228       {
229         return irr::gui::EGDF_TOOLTIP;
230       }
231     else
232       {
233         scm_error (scm_arg_type_key, NULL, "Wrong default font: ~S",
234                    scm_list_1 (default_font), scm_list_1 (default_font));
235       }
236   }
237 }