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