]> git.jsancho.org Git - guile-irrlicht.git/blob - src/guile-irrlicht.cpp
get-skin
[guile-irrlicht.git] / src / guile-irrlicht.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 <libguile.h>
23
24 #include "animated-mesh.h"
25 #include "animated-mesh-scene-node.h"
26 #include "box3d.h"
27 #include "camera-scene-node.h"
28 #include "cursor-control.h"
29 #include "device.h"
30 #include "event-receiver.h"
31 #include "file-archive.h"
32 #include "file-system.h"
33 #include "gsubr.h"
34 #include "gui.h"
35 #include "gui-edit-box.h"
36 #include "gui-element.h"
37 #include "gui-environment.h"
38 #include "gui-image.h"
39 #include "gui-skin.h"
40 #include "gui-static-text.h"
41 #include "guile-irrlicht.h"
42 #include "keymap.h"
43 #include "material.h"
44 #include "mesh.h"
45 #include "mesh-scene-node.h"
46 #include "reference-counted.h"
47 #include "scene-manager.h"
48 #include "scene-node.h"
49 #include "scene-node-animator.h"
50 #include "texture.h"
51 #include "timer.h"
52 #include "vertex3d.h"
53 #include "video-driver.h"
54 #include "wchar.h"
55
56 extern "C" {
57
58   void
59   init_guile_irrlicht (void)
60   {
61     // Init modules
62     init_animated_mesh ();
63     init_animated_mesh_scene_node ();
64     init_box3d ();
65     init_camera_scene_node ();
66     init_cursor_control ();
67     init_device ();
68     init_event_receiver ();
69     init_file_archive ();
70     init_file_system ();
71     init_gui ();
72     init_gui_edit_box ();
73     init_gui_element ();
74     init_gui_environment ();
75     init_gui_image ();
76     init_gui_skin ();
77     init_gui_static_text ();
78     init_keymap ();
79     init_material ();
80     init_mesh ();
81     init_mesh_scene_node ();
82     init_reference_counted ();
83     init_scene_manager ();
84     init_scene_node ();
85     init_scene_node_animator ();
86     init_texture ();
87     init_timer ();
88     init_vertex3d ();
89     init_video_driver ();
90
91     // Shared procedures (used by two or more objects)
92     DEFINE_GSUBR ("draw-all", 1, 0, 0, irr_drawAll);
93     DEFINE_GSUBR ("get-position", 1, 1, 0, irr_getPosition);
94     DEFINE_GSUBR ("get-name", 1, 0, 0, irr_getName);
95     DEFINE_GSUBR ("set-material!", 2, 0, 0, irr_setMaterial);
96     DEFINE_GSUBR ("set-material-flag!", 3, 0, 0, irr_setMaterialFlag);
97     DEFINE_GSUBR ("set-position!", 2, 0, 0, irr_setPosition);
98     DEFINE_GSUBR ("set-visible!", 2, 0, 0, irr_setVisible);
99   }
100
101   SCM
102   irr_drawAll (SCM wrapped_obj)
103   {
104     if (gui_environment_p (wrapped_obj))
105       {
106         unwrap_gui_environment (wrapped_obj)->drawAll ();
107       }
108     else if (scene_manager_p (wrapped_obj))
109       {
110         unwrap_scene_manager (wrapped_obj)->drawAll ();
111       }
112     else
113       {
114         scm_error (scm_arg_type_key, NULL, "Cannot draw all elements from object: ~S",
115                    scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
116       }
117     return SCM_UNSPECIFIED;
118   }
119
120   SCM
121   irr_getName (SCM wrapped_obj)
122   {
123     if (video_driver_p (wrapped_obj))
124       {
125         return scm_from_wide_char_string (unwrap_video_driver (wrapped_obj)->getName ());
126       }
127     else
128       {
129         scm_error (scm_arg_type_key, NULL, "Cannot get name from object: ~S",
130                    scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
131       }
132   }
133
134   SCM
135   irr_getPosition (SCM wrapped_obj,
136                    SCM i)
137   {
138     if (cursor_control_p (wrapped_obj))
139       {
140         return irr_gui_getPosition (wrapped_obj);
141       }
142     else if (is_scene_node_object (wrapped_obj))
143       {
144         return irr_scene_getPosition (wrapped_obj);
145       }
146     else
147       {
148         scm_error (scm_arg_type_key, NULL, "Cannot get position from object: ~S",
149                    scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
150       }
151   }
152
153   SCM
154   irr_setMaterial (SCM wrapped_obj,
155                    SCM material)
156   {
157     if (video_driver_p (wrapped_obj))
158       {
159         return irr_video_setMaterial (wrapped_obj, material);
160       }
161     else
162       {
163         scm_error (scm_arg_type_key, NULL, "Cannot set material to object: ~S",
164                    scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
165       }
166   }
167
168   SCM
169   irr_setMaterialFlag (SCM wrapped_obj,
170                        SCM flag,
171                        SCM newvalue)
172   {
173     if (is_scene_node_object (wrapped_obj))
174       {
175         return irr_scene_ISceneNode_setMaterialFlag (wrapped_obj, flag, newvalue);
176       }
177     else
178       {
179         scm_error (scm_arg_type_key, NULL, "Cannot set material flag to object: ~S",
180                    scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
181       }
182   }
183
184   SCM
185   irr_setPosition (SCM wrapped_obj,
186                    SCM position)
187   {
188     if (cursor_control_p (wrapped_obj))
189       {
190         return irr_gui_setPosition (wrapped_obj, position);
191       }
192     else if (is_scene_node_object (wrapped_obj))
193       {
194         return irr_scene_setPosition (wrapped_obj, position);
195       }
196     else
197       {
198         scm_error (scm_arg_type_key, NULL, "Cannot set position to object: ~S",
199                    scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
200       }
201   }
202
203   SCM
204   irr_setVisible (SCM wrapped_obj,
205                   SCM visible)
206   {
207 #define SET_VISIBLE(OBJ) OBJ->setVisible (scm_to_bool (visible));
208
209     if (cursor_control_p (wrapped_obj))
210       {
211         SET_VISIBLE (unwrap_cursor_control (wrapped_obj));
212       }
213     else if (gui_element_p (wrapped_obj))
214       {
215         SET_VISIBLE (unwrap_gui_element (wrapped_obj));
216       }
217     else if (is_scene_node_object (wrapped_obj))
218       {
219         SET_VISIBLE (unwrap_scene_node (wrapped_obj));
220       }
221     else
222       {
223         scm_error (scm_arg_type_key, NULL, "Cannot set visibility to object: ~S",
224                    scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
225       }
226     return SCM_UNSPECIFIED;
227   }
228
229 }