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