]> git.jsancho.org Git - guile-irrlicht.git/blob - src/gui-environment.cpp
add-static-text!
[guile-irrlicht.git] / src / gui-environment.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 "device.h"
26 #include "gsubr.h"
27 #include "gui-button.h"
28 #include "gui-editbox.h"
29 #include "gui-element.h"
30 #include "gui-environment.h"
31 #include "gui-font.h"
32 #include "gui-image.h"
33 #include "gui-listbox.h"
34 #include "gui-scrollbar.h"
35 #include "gui-skin.h"
36 #include "gui-static-text.h"
37 #include "gui-window.h"
38 #include "position2d.h"
39 #include "rect.h"
40 #include "texture.h"
41 #include "wchar.h"
42 #include "wrapped.h"
43
44 using namespace irr;
45
46 extern "C" {
47
48   void
49   init_gui_environment (void)
50   {
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);
61   }
62
63   DEFINE_WRAPPED_TYPE (irr::gui::IGUIEnvironment*, "gui-environment",
64                        init_gui_environment_type, gui_environment_p,
65                        wrap_gui_environment, unwrap_gui_environment);
66
67   SCM
68   irr_gui_IGUIEnvironment_addStaticText (SCM gui_environment,
69                                          SCM text,
70                                          SCM rectangle,
71                                          SCM border,
72                                          SCM word_wrap,
73                                          SCM parent,
74                                          SCM id,
75                                          SCM fill_background)
76   {
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),
81                      scm_to_bool (border),
82                      scm_to_bool (word_wrap),
83                      (gui::IGUIElement*)scm_to_pointer (parent),
84                      scm_to_int32 (id),
85                      scm_to_bool (fill_background));
86     return scm_from_pointer ((void*)static_text, NULL);
87   }
88
89   SCM
90   irr_gui_addImage (SCM wrapped_gui_environment,
91                     SCM image,
92                     SCM position,
93                     SCM rest)
94   {
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;
99
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,
105                                   SCM_UNDEFINED);
106
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),
113                         scm_to_int32 (id),
114                         text == SCM_UNDEFINED ? 0 : scm_to_wide_char_string (text));
115     return wrap_gui_image (guiImage);
116   }
117
118   SCM
119   irr_gui_addEditBox (SCM wrapped_gui_environment,
120                       SCM text,
121                       SCM rectangle,
122                       SCM rest)
123   {
124     SCM border = SCM_BOOL_T;
125     SCM parent = SCM_UNDEFINED;
126     SCM id = scm_from_int32 (-1);
127
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,
132                                   SCM_UNDEFINED);
133
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),
140                           scm_to_int32 (id));
141     return wrap_gui_editbox (editbox);
142   }
143
144   SCM
145   irr_gui_addListBox (SCM wrapped_gui_environment,
146                       SCM rectangle,
147                       SCM rest)
148   {
149     SCM parent = SCM_UNDEFINED;
150     SCM id = scm_from_int32 (-1);
151     SCM draw_background = SCM_BOOL_F;
152
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,
157                                   SCM_UNDEFINED);
158
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),
163                           scm_to_int32 (id),
164                           scm_to_bool (draw_background));
165     return wrap_gui_listbox (listbox);
166   }
167
168   SCM
169   irr_gui_addScrollBar (SCM wrapped_gui_environment,
170                         SCM horizontal,
171                         SCM rectangle,
172                         SCM rest)
173   {
174     SCM parent = SCM_UNDEFINED;
175     SCM id = scm_from_int32 (-1);
176
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,
180                                   SCM_UNDEFINED);
181
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),
187                             scm_to_int32 (id));
188     return wrap_gui_scrollbar (scrollbar);
189   }
190
191   SCM
192   irr_gui_addWindow (SCM wrapped_gui_environment,
193                      SCM rectangle,
194                      SCM rest)
195   {
196     SCM modal = SCM_BOOL_F;
197     SCM text = SCM_UNDEFINED;
198     SCM parent = SCM_UNDEFINED;
199     SCM id = scm_from_int32 (-1);
200
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,
206                                   SCM_UNDEFINED);
207
208     irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
209     irr::gui::IGUIWindow* window =
210       guienv->addWindow (scm_to_rect_s32 (rectangle),
211                          scm_to_bool (modal),
212                          text == SCM_UNDEFINED ? 0 : scm_to_wide_char_string (text),
213                          parent == SCM_UNDEFINED ? 0 : unwrap_gui_element (parent),
214                          scm_to_int32 (id));
215     return wrap_gui_window (window);
216   }
217
218   SCM
219   irr_gui_getBuiltInFont (SCM wrapped_gui_environment)
220   {
221     irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
222     irr::gui::IGUIFont* font = guienv->getBuiltInFont ();
223     return wrap_gui_font (font);
224   }
225
226   SCM
227   irr_gui_getSkin (SCM wrapped_gui_environment)
228   {
229     irr::gui::IGUIEnvironment* guienv = unwrap_gui_environment (wrapped_gui_environment);
230     irr::gui::IGUISkin* skin = guienv->getSkin ();
231     return wrap_gui_skin (skin);
232   }
233
234   SCM
235   irr_gui_IGUIEnvironment_addButton (SCM wrapped_gui_environment,
236                                      SCM rectangle,
237                                      SCM rest)
238   {
239     SCM parent = SCM_UNDEFINED;
240     SCM id = scm_from_int32 (-1);
241     SCM text = SCM_UNDEFINED;
242     SCM tooltiptext = SCM_UNDEFINED;
243
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,
249                                   SCM_UNDEFINED);
250
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),
255                          scm_to_int32 (id),
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);
259   }
260
261   SCM
262   irr_gui_IGUIEnvironment_getFont (SCM wrapped_gui_environment,
263                                    SCM filename)
264   {
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);
268   }
269
270 }