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-skin", 1, 0, 0, irr_gui_getSkin);
60 DEFINE_WRAPPED_TYPE (irr::gui::IGUIEnvironment*, "gui-environment",
61 init_gui_environment_type, gui_environment_p,
62 wrap_gui_environment, unwrap_gui_environment);
65 irr_gui_addImage (SCM wrapped_gui_environment,
70 SCM use_alpha_channel = SCM_BOOL_T;
71 SCM parent = SCM_UNDEFINED;
72 SCM id = scm_from_int32 (-1);
73 SCM text = SCM_UNDEFINED;
75 scm_c_bind_keyword_arguments ("add-image!", rest, (scm_t_keyword_arguments_flags)0,
76 scm_from_utf8_keyword ("use_alpha_channel"), &use_alpha_channel,
77 scm_from_utf8_keyword ("parent"), &parent,
78 scm_from_utf8_keyword ("id"), &id,
79 scm_from_utf8_keyword ("text"), &text,
82 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
83 irr::gui::IGUIImage* guiImage =
84 guienv->addImage (unwrap_texture (image),
85 scm_to_position2d_s32 (position),
86 scm_to_bool (use_alpha_channel),
87 parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
89 text == SCM_UNDEFINED ? 0 : scm_to_wide_char_string (text));
90 return wrap_gui_image (guiImage);
94 irr_gui_addEditBox (SCM wrapped_gui_environment,
99 SCM border = SCM_BOOL_T;
100 SCM parent = SCM_UNDEFINED;
101 SCM id = scm_from_int32 (-1);
103 scm_c_bind_keyword_arguments ("add-editbox!", rest, (scm_t_keyword_arguments_flags)0,
104 scm_from_utf8_keyword ("border"), &border,
105 scm_from_utf8_keyword ("parent"), &parent,
106 scm_from_utf8_keyword ("id"), &id,
109 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
110 irr::gui::IGUIEditBox* editbox =
111 guienv->addEditBox (scm_to_wide_char_string (text),
112 scm_to_rect_s32 (rectangle),
113 scm_to_bool (border),
114 parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
116 return wrap_gui_editbox (editbox);
120 irr_gui_addListBox (SCM wrapped_gui_environment,
124 SCM parent = SCM_UNDEFINED;
125 SCM id = scm_from_int32 (-1);
126 SCM draw_background = SCM_BOOL_F;
128 scm_c_bind_keyword_arguments ("add-listbox!", rest, (scm_t_keyword_arguments_flags)0,
129 scm_from_utf8_keyword ("parent"), &parent,
130 scm_from_utf8_keyword ("id"), &id,
131 scm_from_utf8_keyword ("draw-background"), &draw_background,
134 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
135 irr::gui::IGUIListBox* listbox =
136 guienv->addListBox (scm_to_rect_s32 (rectangle),
137 parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
139 scm_to_bool (draw_background));
140 return wrap_gui_listbox (listbox);
144 irr_gui_addScrollBar (SCM wrapped_gui_environment,
149 SCM parent = SCM_UNDEFINED;
150 SCM id = scm_from_int32 (-1);
152 scm_c_bind_keyword_arguments ("add-scrollbar!", rest, (scm_t_keyword_arguments_flags)0,
153 scm_from_utf8_keyword ("parent"), &parent,
154 scm_from_utf8_keyword ("id"), &id,
157 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
158 irr::gui::IGUIScrollBar* scrollbar =
159 guienv->addScrollBar (scm_to_bool (horizontal),
160 scm_to_rect_s32 (rectangle),
161 parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
163 return wrap_gui_scrollbar (scrollbar);
167 irr_gui_addStaticText (SCM wrapped_gui_environment,
172 SCM border = SCM_BOOL_F;
173 SCM word_wrap = SCM_BOOL_T;
174 SCM parent = SCM_UNDEFINED;
175 SCM id = scm_from_int32 (-1);
176 SCM fill_background = SCM_BOOL_F;
178 scm_c_bind_keyword_arguments ("add-static-text!", rest, (scm_t_keyword_arguments_flags)0,
179 scm_from_utf8_keyword ("border"), &border,
180 scm_from_utf8_keyword ("word-wrap"), &word_wrap,
181 scm_from_utf8_keyword ("parent"), &parent,
182 scm_from_utf8_keyword ("id"), &id,
183 scm_from_utf8_keyword ("fill-background"), &fill_background,
186 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
187 irr::gui::IGUIStaticText* staticText =
188 guienv->addStaticText (scm_to_wide_char_string (text),
189 scm_to_rect_s32 (rectangle),
190 scm_to_bool (border),
191 scm_to_bool (word_wrap),
192 parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
194 scm_to_bool (fill_background));
195 return wrap_gui_static_text (staticText);
199 irr_gui_addWindow (SCM wrapped_gui_environment,
203 SCM modal = SCM_BOOL_F;
204 SCM text = SCM_UNDEFINED;
205 SCM parent = SCM_UNDEFINED;
206 SCM id = scm_from_int32 (-1);
208 scm_c_bind_keyword_arguments ("add-window!", rest, (scm_t_keyword_arguments_flags)0,
209 scm_from_utf8_keyword ("modal"), &modal,
210 scm_from_utf8_keyword ("text"), &text,
211 scm_from_utf8_keyword ("parent"), &parent,
212 scm_from_utf8_keyword ("id"), &id,
215 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
216 irr::gui::IGUIWindow* window =
217 guienv->addWindow (scm_to_rect_s32 (rectangle),
219 text == SCM_UNDEFINED ? 0 : scm_to_wide_char_string (text),
220 parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
222 return wrap_gui_window (window);
226 irr_gui_getBuiltInFont (SCM wrapped_gui_environment)
228 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
229 irr::gui::IGUIFont* font = guienv->getBuiltInFont ();
230 return wrap_gui_font (font);
234 irr_gui_getSkin (SCM wrapped_gui_environment)
236 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
237 irr::gui::IGUISkin* skin = guienv->getSkin ();
238 return wrap_gui_skin (skin);
242 irr_gui_IGUIEnvironment_addButton (SCM wrapped_gui_environment,
246 SCM parent = SCM_UNDEFINED;
247 SCM id = scm_from_int32 (-1);
248 SCM text = SCM_UNDEFINED;
249 SCM tooltiptext = SCM_UNDEFINED;
251 scm_c_bind_keyword_arguments ("add-button!", rest, (scm_t_keyword_arguments_flags)0,
252 scm_from_utf8_keyword ("parent"), &parent,
253 scm_from_utf8_keyword ("id"), &id,
254 scm_from_utf8_keyword ("text"), &text,
255 scm_from_utf8_keyword ("tooltiptext"), &tooltiptext,
258 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
259 irr::gui::IGUIButton* button =
260 guienv->addButton (scm_to_rect_s32 (rectangle),
261 parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
263 text == SCM_UNDEFINED ? 0 : scm_to_wide_char_string (text),
264 tooltiptext == SCM_UNDEFINED ? 0 : scm_to_wide_char_string (tooltiptext));
265 return wrap_gui_button (button);
269 irr_gui_IGUIEnvironment_getFont (SCM wrapped_gui_environment,
272 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
273 irr::gui::IGUIFont* font = guienv->getFont (scm_to_utf8_stringn (filename, NULL));
274 return wrap_gui_font (font);