]> git.jsancho.org Git - guile-irrlicht.git/blob - src/device.cpp
fixing bugs
[guile-irrlicht.git] / src / device.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 "device.h"
25 #include "dimension2d.h"
26 #include "driver-types.h"
27 #include "gsubr.h"
28 #include "wchar.h"
29
30
31 using namespace irr;
32
33
34 template <typename TEventReceiver>
35 SCM
36 createDevice (SCM device_type,
37               SCM window_size,
38               SCM bits,
39               SCM fullscreen,
40               SCM stencilbuffer,
41               SCM vsync,
42               SCM receiver)
43 {
44   IrrlichtDevice* device =
45     createDevice (scm_to_driver_type (device_type),
46                   scm_to_dimension2d_u32 (window_size),
47                   scm_to_uint32 (bits),
48                   scm_to_bool (fullscreen),
49                   scm_to_bool (stencilbuffer),
50                   scm_to_bool (vsync),
51                   (TEventReceiver)scm_to_pointer (receiver));
52   return scm_from_pointer ((void*)device, NULL);
53 }
54
55
56 SCM
57 IrrlichtDevice_getCursorControl (SCM device)
58 {
59   gui::ICursorControl* cursor_control =
60     ((IrrlichtDevice*)scm_to_pointer (device))->getCursorControl ();
61   return scm_from_pointer ((void*)cursor_control, NULL);
62 }
63
64
65 SCM
66 IrrlichtDevice_getFileSystem (SCM device)
67 {
68   io::IFileSystem* file_system =
69     ((IrrlichtDevice*)scm_to_pointer (device))->getFileSystem ();
70   return scm_from_pointer ((void*)file_system, NULL);
71 }
72
73
74 SCM
75 IrrlichtDevice_getGUIEnvironment (SCM device)
76 {
77   gui::IGUIEnvironment* gui_env =
78     ((IrrlichtDevice*)scm_to_pointer (device))->getGUIEnvironment ();
79   return scm_from_pointer ((void*)gui_env, NULL);
80 }
81
82
83 SCM
84 IrrlichtDevice_getSceneManager (SCM device)
85 {
86   scene::ISceneManager* manager =
87     ((IrrlichtDevice*)scm_to_pointer (device))->getSceneManager ();
88   return scm_from_pointer ((void*)manager, NULL);
89 }
90
91
92 SCM
93 IrrlichtDevice_getTimer (SCM device)
94 {
95   ITimer* timer =
96     ((IrrlichtDevice*)scm_to_pointer (device))->getTimer ();
97   return scm_from_pointer ((void*)timer, NULL);
98 }
99
100
101 SCM
102 IrrlichtDevice_getVideoDriver (SCM device)
103 {
104   video::IVideoDriver* driver =
105     ((IrrlichtDevice*)scm_to_pointer (device))->getVideoDriver ();
106   return scm_from_pointer ((void*)driver, NULL);
107 }
108
109
110 SCM
111 IrrlichtDevice_isWindowActive (SCM device)
112 {
113   return scm_from_bool
114     (((IrrlichtDevice*)scm_to_pointer (device))->isWindowActive ());
115 }
116
117
118 SCM
119 IrrlichtDevice_run (SCM device)
120 {
121   return scm_from_bool
122     (((IrrlichtDevice*)scm_to_pointer (device))->run ());
123 }
124
125
126 template <typename TEventReceiver>
127 SCM
128 IrrlichtDevice_setEventReceiver (SCM device,
129                                  SCM receiver)
130 {
131   ((IrrlichtDevice*)scm_to_pointer (device))->
132     setEventReceiver ((TEventReceiver)scm_to_pointer (receiver));
133   return SCM_UNSPECIFIED;
134 }
135
136
137 SCM
138 IrrlichtDevice_setResizable (SCM device,
139                              SCM resize)
140 {
141   ((IrrlichtDevice*)scm_to_pointer (device))->
142     setResizable (scm_to_bool (resize));
143   return SCM_UNSPECIFIED;
144 }
145
146
147 SCM
148 IrrlichtDevice_setWindowCaption (SCM device,
149                                  SCM text)
150 {
151   ((IrrlichtDevice*)scm_to_pointer (device))->
152     setWindowCaption (scm_to_wide_char_string (text));
153   return SCM_UNSPECIFIED;
154 }
155
156
157 SCM
158 IrrlichtDevice_yield (SCM device)
159 {
160   ((IrrlichtDevice*)scm_to_pointer (device))->yield ();
161   return SCM_UNSPECIFIED;
162 }
163
164
165 extern "C" {
166
167   void
168   init_device (void)
169   {
170     DEFINE_GSUBR ("createDevice_IEventReceiver", 7, 0, 0, createDevice<IEventReceiver*>);
171     DEFINE_GSUBR ("IrrlichtDevice_getCursorControl", 1, 0, 0, IrrlichtDevice_getCursorControl);
172     DEFINE_GSUBR ("IrrlichtDevice_getFileSystem", 1, 0, 0, IrrlichtDevice_getFileSystem);
173     DEFINE_GSUBR ("IrrlichtDevice_getGUIEnvironment", 1, 0, 0, IrrlichtDevice_getGUIEnvironment);
174     DEFINE_GSUBR ("IrrlichtDevice_getSceneManager", 1, 0, 0, IrrlichtDevice_getSceneManager);
175     DEFINE_GSUBR ("IrrlichtDevice_getTimer", 1, 0, 0, IrrlichtDevice_getTimer);
176     DEFINE_GSUBR ("IrrlichtDevice_getVideoDriver", 1, 0, 0, IrrlichtDevice_getVideoDriver);
177     DEFINE_GSUBR ("IrrlichtDevice_isWindowActive", 1, 0, 0, IrrlichtDevice_isWindowActive);
178     DEFINE_GSUBR ("IrrlichtDevice_run", 1, 0, 0, IrrlichtDevice_run);
179     DEFINE_GSUBR ("IrrlichtDevice_setEventReceiver_IEventReceiver", 2, 0, 0,
180                   IrrlichtDevice_setEventReceiver<IEventReceiver*>);
181     DEFINE_GSUBR ("IrrlichtDevice_setResizable", 2, 0, 0, IrrlichtDevice_setResizable);
182     DEFINE_GSUBR ("IrrlichtDevice_setWindowCaption", 2, 0, 0, IrrlichtDevice_setWindowCaption);
183     DEFINE_GSUBR ("IrrlichtDevice_yield", 1, 0, 0, IrrlichtDevice_yield);
184   }
185
186 }