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"
49 init_gui_environment (void)
51 init_gui_environment_type ();
52 DEFINE_GSUBR ("irr_gui_IGUIEnvironment_addStaticText", 8, 0, 0,
53 irr_gui_IGUIEnvironment_addStaticText);
54 DEFINE_GSUBR ("add-image!", 3, 0, 1, irr_gui_addImage);
55 DEFINE_GSUBR ("add-editbox!", 3, 0, 1, irr_gui_addEditBox);
56 DEFINE_GSUBR ("add-listbox!", 2, 0, 1, irr_gui_addListBox);
57 DEFINE_GSUBR ("add-scrollbar!", 3, 0, 1, irr_gui_addScrollBar);
58 DEFINE_GSUBR ("add-window!", 2, 0, 1, irr_gui_addWindow);
59 DEFINE_GSUBR ("get-built-in-font", 1, 0, 0, irr_gui_getBuiltInFont);
60 DEFINE_GSUBR ("get-skin", 1, 0, 0, irr_gui_getSkin);
63 DEFINE_WRAPPED_TYPE (irr::gui::IGUIEnvironment*, "gui-environment",
64 init_gui_environment_type, gui_environment_p,
65 wrap_gui_environment, unwrap_gui_environment);
68 irr_gui_IGUIEnvironment_addStaticText (SCM gui_environment,
77 gui::IGUIStaticText* static_text =
78 ((gui::IGUIEnvironment*)scm_to_pointer (gui_environment))->
79 addStaticText (scm_to_wide_char_string (text),
80 scm_to_rect_s32 (rectangle),
82 scm_to_bool (word_wrap),
83 (gui::IGUIElement*)scm_to_pointer (parent),
85 scm_to_bool (fill_background));
86 return scm_from_pointer ((void*)static_text, NULL);
90 irr_gui_addImage (SCM wrapped_gui_environment,
95 SCM use_alpha_channel = SCM_BOOL_T;
96 SCM parent = SCM_UNDEFINED;
97 SCM id = scm_from_int32 (-1);
98 SCM text = SCM_UNDEFINED;
100 scm_c_bind_keyword_arguments ("add-image!", rest, (scm_t_keyword_arguments_flags)0,
101 scm_from_utf8_keyword ("use_alpha_channel"), &use_alpha_channel,
102 scm_from_utf8_keyword ("parent"), &parent,
103 scm_from_utf8_keyword ("id"), &id,
104 scm_from_utf8_keyword ("text"), &text,
107 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
108 irr::gui::IGUIImage* guiImage =
109 guienv->addImage (unwrap_texture (image),
110 scm_to_position2d_s32 (position),
111 scm_to_bool (use_alpha_channel),
112 parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
114 text == SCM_UNDEFINED ? 0 : scm_to_wide_char_string (text));
115 return wrap_gui_image (guiImage);
119 irr_gui_addEditBox (SCM wrapped_gui_environment,
124 SCM border = SCM_BOOL_T;
125 SCM parent = SCM_UNDEFINED;
126 SCM id = scm_from_int32 (-1);
128 scm_c_bind_keyword_arguments ("add-editbox!", rest, (scm_t_keyword_arguments_flags)0,
129 scm_from_utf8_keyword ("border"), &border,
130 scm_from_utf8_keyword ("parent"), &parent,
131 scm_from_utf8_keyword ("id"), &id,
134 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
135 irr::gui::IGUIEditBox* editbox =
136 guienv->addEditBox (scm_to_wide_char_string (text),
137 scm_to_rect_s32 (rectangle),
138 scm_to_bool (border),
139 parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
141 return wrap_gui_editbox (editbox);
145 irr_gui_addListBox (SCM wrapped_gui_environment,
149 SCM parent = SCM_UNDEFINED;
150 SCM id = scm_from_int32 (-1);
151 SCM draw_background = SCM_BOOL_F;
153 scm_c_bind_keyword_arguments ("add-listbox!", rest, (scm_t_keyword_arguments_flags)0,
154 scm_from_utf8_keyword ("parent"), &parent,
155 scm_from_utf8_keyword ("id"), &id,
156 scm_from_utf8_keyword ("draw-background"), &draw_background,
159 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
160 irr::gui::IGUIListBox* listbox =
161 guienv->addListBox (scm_to_rect_s32 (rectangle),
162 parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
164 scm_to_bool (draw_background));
165 return wrap_gui_listbox (listbox);
169 irr_gui_addScrollBar (SCM wrapped_gui_environment,
174 SCM parent = SCM_UNDEFINED;
175 SCM id = scm_from_int32 (-1);
177 scm_c_bind_keyword_arguments ("add-scrollbar!", rest, (scm_t_keyword_arguments_flags)0,
178 scm_from_utf8_keyword ("parent"), &parent,
179 scm_from_utf8_keyword ("id"), &id,
182 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
183 irr::gui::IGUIScrollBar* scrollbar =
184 guienv->addScrollBar (scm_to_bool (horizontal),
185 scm_to_rect_s32 (rectangle),
186 parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
188 return wrap_gui_scrollbar (scrollbar);
192 irr_gui_addWindow (SCM wrapped_gui_environment,
196 SCM modal = SCM_BOOL_F;
197 SCM text = SCM_UNDEFINED;
198 SCM parent = SCM_UNDEFINED;
199 SCM id = scm_from_int32 (-1);
201 scm_c_bind_keyword_arguments ("add-window!", rest, (scm_t_keyword_arguments_flags)0,
202 scm_from_utf8_keyword ("modal"), &modal,
203 scm_from_utf8_keyword ("text"), &text,
204 scm_from_utf8_keyword ("parent"), &parent,
205 scm_from_utf8_keyword ("id"), &id,
208 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
209 irr::gui::IGUIWindow* window =
210 guienv->addWindow (scm_to_rect_s32 (rectangle),
212 text == SCM_UNDEFINED ? 0 : scm_to_wide_char_string (text),
213 parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
215 return wrap_gui_window (window);
219 irr_gui_getBuiltInFont (SCM wrapped_gui_environment)
221 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
222 irr::gui::IGUIFont* font = guienv->getBuiltInFont ();
223 return wrap_gui_font (font);
227 irr_gui_getSkin (SCM wrapped_gui_environment)
229 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
230 irr::gui::IGUISkin* skin = guienv->getSkin ();
231 return wrap_gui_skin (skin);
235 irr_gui_IGUIEnvironment_addButton (SCM wrapped_gui_environment,
239 SCM parent = SCM_UNDEFINED;
240 SCM id = scm_from_int32 (-1);
241 SCM text = SCM_UNDEFINED;
242 SCM tooltiptext = SCM_UNDEFINED;
244 scm_c_bind_keyword_arguments ("add-button!", rest, (scm_t_keyword_arguments_flags)0,
245 scm_from_utf8_keyword ("parent"), &parent,
246 scm_from_utf8_keyword ("id"), &id,
247 scm_from_utf8_keyword ("text"), &text,
248 scm_from_utf8_keyword ("tooltiptext"), &tooltiptext,
251 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
252 irr::gui::IGUIButton* button =
253 guienv->addButton (scm_to_rect_s32 (rectangle),
254 parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
256 text == SCM_UNDEFINED ? 0 : scm_to_wide_char_string (text),
257 tooltiptext == SCM_UNDEFINED ? 0 : scm_to_wide_char_string (tooltiptext));
258 return wrap_gui_button (button);
262 irr_gui_IGUIEnvironment_getFont (SCM wrapped_gui_environment,
265 irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
266 irr::gui::IGUIFont* font = guienv->getFont (scm_to_utf8_stringn (filename, NULL));
267 return wrap_gui_font (font);