]> git.jsancho.org Git - guile-irrlicht.git/blob - src/gui-environment.cpp
Some doc
[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 #include "gsubr.h"
25 #include "gui-environment.h"
26 #include "position2d.h"
27 #include "rect.h"
28 #include "wchar.h"
29 #include "wrapped.h"
30
31 using namespace irr;
32
33 template <typename TParent>
34 SCM
35 IGUIEnvironment_addButton (SCM gui_environment,
36                            SCM rectangle,
37                            SCM parent,
38                            SCM id,
39                            SCM text,
40                            SCM tooltiptext)
41 {
42   wchar_t* wtext = (wchar_t*) scm_to_utf32_string (text);
43   wchar_t* wtooltiptext = (wchar_t*) scm_to_utf32_string (tooltiptext);
44
45   gui::IGUIButton* button =
46     ((gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment))->
47     addButton (scm_to_rect_s32 (rectangle),
48                (TParent)scm_to_irr_pointer (parent),
49                scm_to_int32 (id),
50                wtext,
51                wtooltiptext);
52
53   free (wtext);
54   free (wtooltiptext);
55   return scm_from_irr_pointer ("<gui-button>", (void*) button);
56 }
57
58 template <typename TParent>
59 SCM
60 IGUIEnvironment_addEditBox (SCM gui_environment,
61                             SCM text,
62                             SCM rectangle,
63                             SCM border,
64                             SCM parent,
65                             SCM id)
66 {
67   wchar_t* wtext = (wchar_t*) scm_to_utf32_string (text);
68
69   gui::IGUIEditBox* editbox =
70     ((gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment))->
71     addEditBox (wtext,
72                 scm_to_rect_s32 (rectangle),
73                 scm_to_bool (border),
74                 (TParent)scm_to_irr_pointer (parent),
75                 scm_to_int32 (id));
76
77   free (wtext);
78   return scm_from_irr_pointer ("<gui-editbox>", (void*) editbox);
79 }
80
81 template <typename TParent>
82 SCM
83 IGUIEnvironment_addFileOpenDialog (SCM gui_environment,
84                                    SCM title,
85                                    SCM modal,
86                                    SCM parent,
87                                    SCM id,
88                                    SCM restore_cwd,
89                                    SCM start_dir)
90 {
91   gui::IGUIEnvironment* guienv = (gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment);
92   wchar_t* wtitle = (wchar_t*) scm_to_utf32_string (title);
93   io::path::char_type* cstartDir = scm_to_utf8_string (start_dir);
94
95   gui::IGUIFileOpenDialog* dialog =
96     guienv->addFileOpenDialog (wtitle,
97                                scm_to_bool (modal),
98                                (TParent)scm_to_irr_pointer (parent),
99                                scm_to_int32 (id),
100                                scm_to_bool (restore_cwd),
101                                cstartDir);
102
103   free (wtitle);
104   free (cstartDir);
105   return scm_from_irr_pointer ("<gui-file-open-dialog>", (void*) dialog);
106 }
107
108 template <typename TParent>
109 SCM
110 IGUIEnvironment_addImage (SCM gui_environment,
111                           SCM image,
112                           SCM position,
113                           SCM use_alpha_channel,
114                           SCM parent,
115                           SCM id,
116                           SCM text)
117 {
118   gui::IGUIEnvironment* guienv = (gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment);
119   wchar_t* wtext = (wchar_t*) scm_to_utf32_string (text);
120
121   gui::IGUIImage* new_image =
122     guienv->addImage ((video::ITexture*)scm_to_irr_pointer (image),
123                       scm_to_position2d_s32 (position),
124                       scm_to_bool (use_alpha_channel),
125                       (TParent)scm_to_irr_pointer (parent),
126                       scm_to_int32 (id),
127                       wtext);
128
129   free (wtext);
130   return scm_from_irr_pointer ("<gui-image>", (void*) new_image);
131 }
132
133 template <typename TParent>
134 SCM
135 IGUIEnvironment_addListBox (SCM gui_environment,
136                             SCM rectangle,
137                             SCM parent,
138                             SCM id,
139                             SCM draw_background)
140 {
141   gui::IGUIListBox* listbox =
142     ((gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment))->
143     addListBox (scm_to_rect_s32 (rectangle),
144                 (TParent)scm_to_irr_pointer (parent),
145                 scm_to_int32 (id),
146                 scm_to_bool (draw_background));
147   return scm_from_irr_pointer ("<gui-listbox>", (void*) listbox);
148 }
149
150 template <typename TParent>
151 SCM
152 IGUIEnvironment_addScrollBar (SCM gui_environment,
153                               SCM horizontal,
154                               SCM rectangle,
155                               SCM parent,
156                               SCM id)
157 {
158   gui::IGUIScrollBar* scrollbar =
159     ((gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment))->
160     addScrollBar (scm_to_bool (horizontal),
161                   scm_to_rect_s32 (rectangle),
162                   (TParent)scm_to_irr_pointer (parent),
163                   scm_to_int32 (id));
164   return scm_from_irr_pointer ("<gui-scrollbar>", (void*) scrollbar);
165 }
166
167 template <typename TParent>
168 SCM
169 IGUIEnvironment_addStaticText (SCM gui_environment,
170                                SCM text,
171                                SCM rectangle,
172                                SCM border,
173                                SCM word_wrap,
174                                SCM parent,
175                                SCM id,
176                                SCM fill_background)
177 {
178   wchar_t* wtext = (wchar_t*) scm_to_utf32_string (text);
179
180   gui::IGUIStaticText* static_text =
181     ((gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment))->
182     addStaticText (wtext,
183                    scm_to_rect_s32 (rectangle),
184                    scm_to_bool (border),
185                    scm_to_bool (word_wrap),
186                    (TParent)scm_to_irr_pointer (parent),
187                    scm_to_int32 (id),
188                    scm_to_bool (fill_background));
189
190   free (wtext);
191   return scm_from_irr_pointer ("<gui-static-text>", (void*) static_text);
192 }
193
194 template <typename TParent>
195 SCM
196 IGUIEnvironment_addWindow (SCM gui_environment,
197                            SCM rectangle,
198                            SCM modal,
199                            SCM text,
200                            SCM parent,
201                            SCM id)
202 {
203   wchar_t* wtext = (wchar_t*) scm_to_utf32_string (text);
204
205   gui::IGUIWindow* window =
206     ((gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment))->
207     addWindow (scm_to_rect_s32 (rectangle),
208                scm_to_bool (modal),
209                wtext,
210                (TParent)scm_to_irr_pointer (parent),
211                scm_to_int32 (id));
212
213   free (wtext);
214   return scm_from_irr_pointer ("<gui-window>", (void*) window);
215 }
216
217 SCM
218 IGUIEnvironment_drawAll (SCM gui_environment)
219 {
220   ((gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment))->drawAll ();
221   return SCM_UNSPECIFIED;
222 }
223
224 SCM
225 IGUIEnvironment_getBuiltInFont (SCM gui_environment)
226 {
227   gui::IGUIFont* font =
228     ((gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment))->getBuiltInFont ();
229   return scm_from_irr_pointer ("<gui-font>", (void*) font);
230 }
231
232 SCM
233 IGUIEnvironment_getFont (SCM gui_environment,
234                          SCM filename)
235 {
236   char* cfilename = scm_to_utf8_string (filename);
237   gui::IGUIFont* font =
238     ((gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment))->getFont (cfilename);
239   free (cfilename);
240   return scm_from_irr_pointer ("<gui-font>", (void*) font);
241 }
242
243 SCM
244 IGUIEnvironment_getSkin (SCM gui_environment)
245 {
246   gui::IGUISkin* skin =
247     ((gui::IGUIEnvironment*)scm_to_irr_pointer (gui_environment))->getSkin ();
248   return scm_from_irr_pointer ("<gui-skin>", (void*) skin);
249 }
250
251 void
252 init_gui_environment (void)
253 {
254   DEFINE_GSUBR ("IGUIEnvironment_addButton_IGUIElement", 6, 0, 0,
255                 IGUIEnvironment_addButton<gui::IGUIElement*>);
256   DEFINE_GSUBR ("IGUIEnvironment_addEditBox_IGUIElement", 6, 0, 0,
257                 IGUIEnvironment_addEditBox<gui::IGUIElement*>);
258   DEFINE_GSUBR ("IGUIEnvironment_addFileOpenDialog_IGUIElement", 7, 0, 0,
259                 IGUIEnvironment_addFileOpenDialog<gui::IGUIElement*>);
260   DEFINE_GSUBR ("IGUIEnvironment_addImage_IGUIElement", 7, 0, 0,
261                 IGUIEnvironment_addImage<gui::IGUIElement*>);
262   DEFINE_GSUBR ("IGUIEnvironment_addListBox_IGUIElement", 5, 0, 0,
263                 IGUIEnvironment_addListBox<gui::IGUIElement*>);
264   DEFINE_GSUBR ("IGUIEnvironment_addScrollBar_IGUIElement", 5, 0, 0,
265                 IGUIEnvironment_addScrollBar<gui::IGUIElement*>);
266   DEFINE_GSUBR ("IGUIEnvironment_addStaticText_IGUIElement", 8, 0, 0,
267                 IGUIEnvironment_addStaticText<gui::IGUIElement*>);
268   DEFINE_GSUBR ("IGUIEnvironment_addStaticText_IGUIWindow", 8, 0, 0,
269                 IGUIEnvironment_addStaticText<gui::IGUIWindow*>);
270   DEFINE_GSUBR ("IGUIEnvironment_addWindow_IGUIElement", 6, 0, 0,
271                 IGUIEnvironment_addWindow<gui::IGUIElement*>);
272   DEFINE_GSUBR ("IGUIEnvironment_drawAll", 1, 0, 0, IGUIEnvironment_drawAll);
273   DEFINE_GSUBR ("IGUIEnvironment_getBuiltInFont", 1, 0, 0, IGUIEnvironment_getBuiltInFont);
274   DEFINE_GSUBR ("IGUIEnvironment_getFont", 2, 0, 0, IGUIEnvironment_getFont);
275   DEFINE_GSUBR ("IGUIEnvironment_getSkin", 1, 0, 0, IGUIEnvironment_getSkin);
276 }