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