1 /* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine
3 Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
5 This file is part of guile-irrlicht.
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.
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.
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/>.
22 #include <irrlicht/irrlicht.h>
27 #include "gui-button.h"
28 #include "gui-editbox.h"
29 #include "gui-element.h"
30 #include "gui-environment.h"
32 #include "gui-image.h"
33 #include "gui-listbox.h"
34 #include "gui-scrollbar.h"
36 #include "gui-static-text.h"
37 #include "gui-window.h"
38 #include "position2d.h"
47 init_gui_environment (void)
49 init_gui_environment_type ();
50 DEFINE_GSUBR ("add-image!", 3, 0, 1, irr_gui_addImage);
51 DEFINE_GSUBR ("add-editbox!", 3, 0, 1, irr_gui_addEditBox);
52 DEFINE_GSUBR ("add-listbox!", 2, 0, 1, irr_gui_addListBox);
53 DEFINE_GSUBR ("add-scrollbar!", 3, 0, 1, irr_gui_addScrollBar);
54 DEFINE_GSUBR ("add-static-text!", 3, 0, 1, irr_gui_addStaticText);
55 DEFINE_GSUBR ("add-window!", 2, 0, 1, irr_gui_addWindow);
56 DEFINE_GSUBR ("get-built-in-font", 1, 0, 0, irr_gui_getBuiltInFont);
57 DEFINE_GSUBR ("get-gui-environment", 1, 0, 0, irr_getGUIEnvironment);
58 DEFINE_GSUBR ("get-skin", 1, 0, 0, irr_gui_getSkin);
61 DEFINE_WRAPPED_TYPE (irr::gui::IGUIEnvironment*, "gui-environment",
62 init_gui_environment_type, gui_environment_p,
63 wrap_gui_environment, unwrap_gui_environment);
66 irr_getGUIEnvironment (SCM wrapped_obj)
68 irr::gui::IGUIEnvironment* gui_environment;
69 if (device_p (wrapped_obj))
71 gui_environment = unwrap_device (wrapped_obj)->getGUIEnvironment ();
75 scm_error (scm_arg_type_key, NULL, "Cannot get GUI environment from object: ~S",
76 scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
78 return wrap_gui_environment (gui_environment);
82 irr_gui_addImage (SCM wrapped_gui_environment,
87 SCM use_alpha_channel = SCM_BOOL_T;
88 SCM parent = SCM_UNDEFINED;
89 SCM id = scm_from_int32 (-1);
90 SCM text = SCM_UNDEFINED;
92 scm_c_bind_keyword_arguments ("add-image!", rest, (scm_t_keyword_arguments_flags)0,
93 scm_from_utf8_keyword ("use_alpha_channel"), &use_alpha_channel,
94 scm_from_utf8_keyword ("parent"), &parent,
95 scm_from_utf8_keyword ("id"), &id,
96 scm_from_utf8_keyword ("text"), &text,
99 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
100 irr::gui::IGUIImage* guiImage =
101 guienv->addImage (unwrap_texture (image),
102 scm_to_position2d_s32 (position),
103 scm_to_bool (use_alpha_channel),
104 parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
106 text == SCM_UNDEFINED ? 0 : scm_to_wide_char_string (text));
107 return wrap_gui_image (guiImage);
111 irr_gui_addEditBox (SCM wrapped_gui_environment,
116 SCM border = SCM_BOOL_T;
117 SCM parent = SCM_UNDEFINED;
118 SCM id = scm_from_int32 (-1);
120 scm_c_bind_keyword_arguments ("add-editbox!", rest, (scm_t_keyword_arguments_flags)0,
121 scm_from_utf8_keyword ("border"), &border,
122 scm_from_utf8_keyword ("parent"), &parent,
123 scm_from_utf8_keyword ("id"), &id,
126 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
127 irr::gui::IGUIEditBox* editbox =
128 guienv->addEditBox (scm_to_wide_char_string (text),
129 scm_to_rect_s32 (rectangle),
130 scm_to_bool (border),
131 parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
133 return wrap_gui_editbox (editbox);
137 irr_gui_addListBox (SCM wrapped_gui_environment,
141 SCM parent = SCM_UNDEFINED;
142 SCM id = scm_from_int32 (-1);
143 SCM draw_background = SCM_BOOL_F;
145 scm_c_bind_keyword_arguments ("add-listbox!", rest, (scm_t_keyword_arguments_flags)0,
146 scm_from_utf8_keyword ("parent"), &parent,
147 scm_from_utf8_keyword ("id"), &id,
148 scm_from_utf8_keyword ("draw-background"), &draw_background,
151 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
152 irr::gui::IGUIListBox* listbox =
153 guienv->addListBox (scm_to_rect_s32 (rectangle),
154 parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
156 scm_to_bool (draw_background));
157 return wrap_gui_listbox (listbox);
161 irr_gui_addScrollBar (SCM wrapped_gui_environment,
166 SCM parent = SCM_UNDEFINED;
167 SCM id = scm_from_int32 (-1);
169 scm_c_bind_keyword_arguments ("add-scrollbar!", rest, (scm_t_keyword_arguments_flags)0,
170 scm_from_utf8_keyword ("parent"), &parent,
171 scm_from_utf8_keyword ("id"), &id,
174 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
175 irr::gui::IGUIScrollBar* scrollbar =
176 guienv->addScrollBar (scm_to_bool (horizontal),
177 scm_to_rect_s32 (rectangle),
178 parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
180 return wrap_gui_scrollbar (scrollbar);
184 irr_gui_addStaticText (SCM wrapped_gui_environment,
189 SCM border = SCM_BOOL_F;
190 SCM word_wrap = SCM_BOOL_T;
191 SCM parent = SCM_UNDEFINED;
192 SCM id = scm_from_int32 (-1);
193 SCM fill_background = SCM_BOOL_F;
195 scm_c_bind_keyword_arguments ("add-static-text!", rest, (scm_t_keyword_arguments_flags)0,
196 scm_from_utf8_keyword ("border"), &border,
197 scm_from_utf8_keyword ("word-wrap"), &word_wrap,
198 scm_from_utf8_keyword ("parent"), &parent,
199 scm_from_utf8_keyword ("id"), &id,
200 scm_from_utf8_keyword ("fill-background"), &fill_background,
203 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
204 irr::gui::IGUIStaticText* staticText =
205 guienv->addStaticText (scm_to_wide_char_string (text),
206 scm_to_rect_s32 (rectangle),
207 scm_to_bool (border),
208 scm_to_bool (word_wrap),
209 parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
211 scm_to_bool (fill_background));
212 return wrap_gui_static_text (staticText);
216 irr_gui_addWindow (SCM wrapped_gui_environment,
220 SCM modal = SCM_BOOL_F;
221 SCM text = SCM_UNDEFINED;
222 SCM parent = SCM_UNDEFINED;
223 SCM id = scm_from_int32 (-1);
225 scm_c_bind_keyword_arguments ("add-window!", rest, (scm_t_keyword_arguments_flags)0,
226 scm_from_utf8_keyword ("modal"), &modal,
227 scm_from_utf8_keyword ("text"), &text,
228 scm_from_utf8_keyword ("parent"), &parent,
229 scm_from_utf8_keyword ("id"), &id,
232 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
233 irr::gui::IGUIWindow* window =
234 guienv->addWindow (scm_to_rect_s32 (rectangle),
236 text == SCM_UNDEFINED ? 0 : scm_to_wide_char_string (text),
237 parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
239 return wrap_gui_window (window);
243 irr_gui_getBuiltInFont (SCM wrapped_gui_environment)
245 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
246 irr::gui::IGUIFont* font = guienv->getBuiltInFont ();
247 return wrap_gui_font (font);
251 irr_gui_getSkin (SCM wrapped_gui_environment)
253 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
254 irr::gui::IGUISkin* skin = guienv->getSkin ();
255 return wrap_gui_skin (skin);
259 irr_gui_IGUIEnvironment_addButton (SCM wrapped_gui_environment,
263 SCM parent = SCM_UNDEFINED;
264 SCM id = scm_from_int32 (-1);
265 SCM text = SCM_UNDEFINED;
266 SCM tooltiptext = SCM_UNDEFINED;
268 scm_c_bind_keyword_arguments ("add-button!", rest, (scm_t_keyword_arguments_flags)0,
269 scm_from_utf8_keyword ("parent"), &parent,
270 scm_from_utf8_keyword ("id"), &id,
271 scm_from_utf8_keyword ("text"), &text,
272 scm_from_utf8_keyword ("tooltiptext"), &tooltiptext,
275 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
276 irr::gui::IGUIButton* button =
277 guienv->addButton (scm_to_rect_s32 (rectangle),
278 parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
280 text == SCM_UNDEFINED ? 0 : scm_to_wide_char_string (text),
281 tooltiptext == SCM_UNDEFINED ? 0 : scm_to_wide_char_string (tooltiptext));
282 return wrap_gui_button (button);
286 irr_gui_IGUIEnvironment_getFont (SCM wrapped_gui_environment,
289 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
290 irr::gui::IGUIFont* font = guienv->getFont (scm_to_utf8_stringn (filename, NULL));
291 return wrap_gui_font (font);