]> git.jsancho.org Git - guile-irrlicht.git/blob - src/device.cpp
Macro for defining guile procedures
[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
25 #include "device.h"
26 #include "dimension2d.h"
27 #include "driver-types.h"
28 #include "event-receiver.h"
29 #include "gsubr.h"
30 #include "wchar.h"
31 #include "wrapped.h"
32
33 extern "C" {
34
35   void
36   init_device (void)
37   {
38     init_device_type ();
39     DEFINE_GSUBR ("create-device", 0, 0, 1, irr_createDevice);
40     DEFINE_GSUBR ("is-window-active?", 1, 0, 0, irr_isWindowActive);
41     DEFINE_GSUBR ("run", 1, 0, 0, irr_run);
42     DEFINE_GSUBR ("set-window-caption!", 2, 0, 0, irr_setWindowCaption);
43     DEFINE_GSUBR ("yield", 1, 0, 0, irr_yield);
44   }
45
46   DEFINE_WRAPPED_TYPE (irr::IrrlichtDevice*, "device",
47                        init_device_type, device_p,
48                        wrap_device, unwrap_device);
49
50   SCM
51   irr_createDevice (SCM rest)
52   {
53     SCM device_type = scm_from_utf8_symbol ("software");
54     SCM window_size = scm_list_2 (scm_from_uint32 (640),
55                                   scm_from_uint32 (480));
56     SCM bits = scm_from_uint32 (16);
57     SCM fullscreen = scm_from_bool (0);
58     SCM stencilbuffer = scm_from_bool (0);
59     SCM vsync = scm_from_bool (0);
60     SCM receiver = scm_from_bool (0);
61
62     scm_c_bind_keyword_arguments ("create-device", rest, (scm_t_keyword_arguments_flags)0,
63                                   scm_from_utf8_keyword ("device-type"), &device_type,
64                                   scm_from_utf8_keyword ("window-size"), &window_size,
65                                   scm_from_utf8_keyword ("bits"), &bits,
66                                   scm_from_utf8_keyword ("fullscreen"), &fullscreen,
67                                   scm_from_utf8_keyword ("stencilbuffer"), &stencilbuffer,
68                                   scm_from_utf8_keyword ("vsync"), &vsync,
69                                   scm_from_utf8_keyword ("receiver"), &receiver,
70                                   SCM_UNDEFINED);
71
72     irr::IrrlichtDevice* device =
73       irr::createDevice (scm_to_driver_type (device_type),
74                          scm_to_dimension2d_u32 (window_size),
75                          scm_to_uint32 (bits),
76                          scm_to_bool (fullscreen),
77                          scm_to_bool (stencilbuffer),
78                          scm_to_bool (vsync),
79                          scm_is_false (receiver) ? 0 : unwrap_event_receiver (receiver));
80     return wrap_device (device);
81   }
82
83   SCM
84   irr_isWindowActive (SCM wrapped_device)
85   {
86     irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
87     return scm_from_bool (device->isWindowActive ());
88   }
89
90   SCM
91   irr_run (SCM wrapped_device)
92   {
93     irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
94     return scm_from_bool (device->run ());
95   }
96
97   SCM
98   irr_setWindowCaption (SCM wrapped_device,
99                         SCM text)
100   {
101     irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
102     device->setWindowCaption (scm_to_wide_char_string (text));
103     return SCM_UNSPECIFIED;
104   }
105
106   SCM
107   irr_yield (SCM wrapped_device)
108   {
109     irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
110     device->yield ();
111     return SCM_UNSPECIFIED;
112   }
113
114 }