1 /* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine
3 Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
5 This file is part of guile-irrlicht.
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.
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.
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/>.
22 #include <irrlicht/irrlicht.h>
26 #include "dimension2d.h"
27 #include "driver-types.h"
28 #include "event-receiver.h"
40 DEFINE_GSUBR ("create-device", 0, 0, 1, irr_createDevice);
41 DEFINE_GSUBR ("get-timer", 1, 0, 0, irr_getTimer);
42 DEFINE_GSUBR ("is-window-active?", 1, 0, 0, irr_isWindowActive);
43 DEFINE_GSUBR ("run", 1, 0, 0, irr_run);
44 DEFINE_GSUBR ("set-event-receiver!", 2, 0, 0, irr_setEventReceiver);
45 DEFINE_GSUBR ("set-resizable!", 2, 0, 0, irr_setResizable);
46 DEFINE_GSUBR ("set-window-caption!", 2, 0, 0, irr_setWindowCaption);
47 DEFINE_GSUBR ("yield", 1, 0, 0, irr_yield);
50 DEFINE_WRAPPED_TYPE (irr::IrrlichtDevice*, "device",
51 init_device_type, device_p,
52 wrap_device, unwrap_device);
55 irr_createDevice (SCM rest)
57 SCM device_type = scm_from_utf8_symbol ("software");
58 SCM window_size = scm_list_2 (scm_from_uint32 (640),
59 scm_from_uint32 (480));
60 SCM bits = scm_from_uint32 (16);
61 SCM fullscreen = SCM_BOOL_F;
62 SCM stencilbuffer = SCM_BOOL_F;
63 SCM vsync = SCM_BOOL_F;
64 SCM receiver = SCM_UNDEFINED;
66 scm_c_bind_keyword_arguments ("create-device", rest, (scm_t_keyword_arguments_flags)0,
67 scm_from_utf8_keyword ("device-type"), &device_type,
68 scm_from_utf8_keyword ("window-size"), &window_size,
69 scm_from_utf8_keyword ("bits"), &bits,
70 scm_from_utf8_keyword ("fullscreen"), &fullscreen,
71 scm_from_utf8_keyword ("stencilbuffer"), &stencilbuffer,
72 scm_from_utf8_keyword ("vsync"), &vsync,
73 scm_from_utf8_keyword ("receiver"), &receiver,
76 irr::IrrlichtDevice* device =
77 irr::createDevice (scm_to_driver_type (device_type),
78 scm_to_dimension2d_u32 (window_size),
80 scm_to_bool (fullscreen),
81 scm_to_bool (stencilbuffer),
83 receiver == SCM_UNDEFINED ? 0 : unwrap_event_receiver (receiver));
84 return wrap_device (device);
88 irr_getTimer (SCM wrapped_device)
90 irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
91 return wrap_timer (device->getTimer ());
95 irr_isWindowActive (SCM wrapped_device)
97 irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
98 return scm_from_bool (device->isWindowActive ());
102 irr_run (SCM wrapped_device)
104 irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
105 return scm_from_bool (device->run ());
109 irr_setEventReceiver (SCM wrapped_device,
112 irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
113 device->setEventReceiver (unwrap_event_receiver (receiver));
114 return SCM_UNSPECIFIED;
118 irr_setResizable (SCM wrapped_device,
121 irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
122 device->setResizable (scm_to_bool (resize));
123 return SCM_UNSPECIFIED;
127 irr_setWindowCaption (SCM wrapped_device,
130 irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
131 device->setWindowCaption (scm_to_wide_char_string (text));
132 return SCM_UNSPECIFIED;
136 irr_yield (SCM wrapped_device)
138 irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
140 return SCM_UNSPECIFIED;