]> git.jsancho.org Git - guile-irrlicht.git/blob - src/gui-environment.cpp
call remote procs from guile code
[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
30
31 using namespace irr;
32
33
34 template <typename TParent>
35 SCM
36 IGUIEnvironment_addButton (SCM gui_environment,
37                            SCM rectangle,
38                            SCM parent,
39                            SCM id,
40                            SCM text,
41                            SCM tooltiptext)
42 {
43   gui::IGUIButton* button =
44     ((gui::IGUIEnvironment*)scm_to_pointer (gui_environment))->
45     addButton (scm_to_rect_s32 (rectangle),
46                (TParent)scm_to_pointer (parent),
47                scm_to_int32 (id),
48                scm_to_wide_char_string (text),
49                scm_to_wide_char_string (tooltiptext));
50   return scm_from_pointer ((void*)button, NULL);
51 }
52
53
54 template <typename TParent>
55 SCM
56 IGUIEnvironment_addEditBox (SCM gui_environment,
57                             SCM text,
58                             SCM rectangle,
59                             SCM border,
60                             SCM parent,
61                             SCM id)
62 {
63   gui::IGUIEditBox* editbox =
64     ((gui::IGUIEnvironment*)scm_to_pointer (gui_environment))->
65     addEditBox (scm_to_wide_char_string (text),
66                 scm_to_rect_s32 (rectangle),
67                 scm_to_bool (border),
68                 (TParent)scm_to_pointer (parent),
69                 scm_to_int32 (id));
70   return scm_from_pointer ((void*)editbox, NULL);
71 }
72
73
74 template <typename TParent>
75 SCM
76 IGUIEnvironment_addImage (SCM gui_environment,
77                           SCM image,
78                           SCM position,
79                           SCM use_alpha_channel,
80                           SCM parent,
81                           SCM id,
82                           SCM text)
83 {
84   gui::IGUIEnvironment* guienv = (gui::IGUIEnvironment*)scm_to_pointer (gui_environment);
85   gui::IGUIImage* new_image =
86     guienv->addImage ((video::ITexture*)scm_to_pointer (image),
87                       scm_to_position2d_s32 (position),
88                       scm_to_bool (use_alpha_channel),
89                       (TParent)scm_to_pointer (parent),
90                       scm_to_int32 (id),
91                       scm_to_wide_char_string (text));
92   return scm_from_pointer ((void*) new_image, NULL);
93 }
94
95
96 template <typename TParent>
97 SCM
98 IGUIEnvironment_addListBox (SCM gui_environment,
99                             SCM rectangle,
100                             SCM parent,
101                             SCM id,
102                             SCM draw_background)
103 {
104   gui::IGUIListBox* listbox =
105     ((gui::IGUIEnvironment*)scm_to_pointer (gui_environment))->
106     addListBox (scm_to_rect_s32 (rectangle),
107                 (TParent)scm_to_pointer (parent),
108                 scm_to_int32 (id),
109                 scm_to_bool (draw_background));
110   return scm_from_pointer ((void*)listbox, NULL);
111 }
112
113
114 template <typename TParent>
115 SCM
116 IGUIEnvironment_addScrollBar (SCM gui_environment,
117                               SCM horizontal,
118                               SCM rectangle,
119                               SCM parent,
120                               SCM id)
121 {
122   gui::IGUIScrollBar* scrollbar =
123     ((gui::IGUIEnvironment*)scm_to_pointer (gui_environment))->
124     addScrollBar (scm_to_bool (horizontal),
125                   scm_to_rect_s32 (rectangle),
126                   (TParent)scm_to_pointer (parent),
127                   scm_to_int32 (id));
128   return scm_from_pointer ((void*)scrollbar, NULL);
129 }
130
131
132 template <typename TParent>
133 SCM
134 IGUIEnvironment_addStaticText (SCM gui_environment,
135                                SCM text,
136                                SCM rectangle,
137                                SCM border,
138                                SCM word_wrap,
139                                SCM parent,
140                                SCM id,
141                                SCM fill_background)
142 {
143   gui::IGUIStaticText* static_text =
144     ((gui::IGUIEnvironment*)scm_to_pointer (gui_environment))->
145     addStaticText (scm_to_wide_char_string (text),
146                    scm_to_rect_s32 (rectangle),
147                    scm_to_bool (border),
148                    scm_to_bool (word_wrap),
149                    (TParent)scm_to_pointer (parent),
150                    scm_to_int32 (id),
151                    scm_to_bool (fill_background));
152   return scm_from_pointer ((void*)static_text, NULL);
153 }
154
155
156 template <typename TParent>
157 SCM
158 IGUIEnvironment_addWindow (SCM gui_environment,
159                            SCM rectangle,
160                            SCM modal,
161                            SCM text,
162                            SCM parent,
163                            SCM id)
164 {
165   gui::IGUIWindow* window =
166     ((gui::IGUIEnvironment*)scm_to_pointer (gui_environment))->
167     addWindow (scm_to_rect_s32 (rectangle),
168                scm_to_bool (modal),
169                scm_to_wide_char_string (text),
170                (TParent)scm_to_pointer (parent),
171                scm_to_int32 (id));
172   return scm_from_pointer ((void*)window, NULL);
173 }
174
175
176 SCM
177 IGUIEnvironment_drawAll (SCM gui_environment)
178 {
179   ((gui::IGUIEnvironment*)scm_to_pointer (gui_environment))->drawAll ();
180   return SCM_UNSPECIFIED;
181 }
182
183
184 SCM
185 IGUIEnvironment_getBuiltInFont (SCM gui_environment)
186 {
187   gui::IGUIFont* font =
188     ((gui::IGUIEnvironment*)scm_to_pointer (gui_environment))->getBuiltInFont ();
189   return scm_from_pointer ((void*)font, NULL);
190 }
191
192
193 SCM
194 IGUIEnvironment_getFont (SCM gui_environment,
195                          SCM filename)
196 {
197   gui::IGUIFont* font =
198     ((gui::IGUIEnvironment*)scm_to_pointer (gui_environment))->
199     getFont (scm_to_utf8_stringn (filename, NULL));
200   return scm_from_pointer ((void*)font, NULL);
201 }
202
203
204 SCM
205 IGUIEnvironment_getSkin (SCM gui_environment)
206 {
207   gui::IGUISkin* skin =
208     ((gui::IGUIEnvironment*)scm_to_pointer (gui_environment))->getSkin ();
209   return scm_from_pointer ((void*)skin, NULL);
210 }
211
212
213 extern "C" {
214
215   void
216   init_gui_environment (void)
217   {
218     DEFINE_GSUBR ("IGUIEnvironment_addButton_IGUIElement", 6, 0, 0,
219                   IGUIEnvironment_addButton<gui::IGUIElement*>);
220     DEFINE_GSUBR ("IGUIEnvironment_addEditBox_IGUIElement", 6, 0, 0,
221                   IGUIEnvironment_addEditBox<gui::IGUIElement*>);
222     DEFINE_GSUBR ("IGUIEnvironment_addImage_IGUIElement", 7, 0, 0,
223                   IGUIEnvironment_addImage<gui::IGUIElement*>);
224     DEFINE_GSUBR ("IGUIEnvironment_addListBox_IGUIElement", 5, 0, 0,
225                   IGUIEnvironment_addListBox<gui::IGUIElement*>);
226     DEFINE_GSUBR ("IGUIEnvironment_addScrollBar_IGUIElement", 5, 0, 0,
227                   IGUIEnvironment_addScrollBar<gui::IGUIElement*>);
228     DEFINE_GSUBR ("IGUIEnvironment_addStaticText_IGUIElement", 8, 0, 0,
229                   IGUIEnvironment_addStaticText<gui::IGUIElement*>);
230     DEFINE_GSUBR ("IGUIEnvironment_addWindow_IGUIElement", 6, 0, 0,
231                   IGUIEnvironment_addWindow<gui::IGUIElement*>);
232     DEFINE_GSUBR ("IGUIEnvironment_drawAll", 1, 0, 0, IGUIEnvironment_drawAll);
233     DEFINE_GSUBR ("IGUIEnvironment_getBuiltInFont", 1, 0, 0, IGUIEnvironment_getBuiltInFont);
234     DEFINE_GSUBR ("IGUIEnvironment_getFont", 2, 0, 0, IGUIEnvironment_getFont);
235     DEFINE_GSUBR ("IGUIEnvironment_getSkin", 1, 0, 0, IGUIEnvironment_getSkin);
236   }
237
238 }