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