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