+/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine
+
+ Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
+
+ This file is part of guile-irrlicht.
+
+ guile-irrlicht is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 3 of the
+ License, or (at your option) any later version.
+
+ guile-irrlicht is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with guile-irrlicht. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <irrlicht/irrlicht.h>
+#include <libguile.h>
+#include <wchar.h>
+#include "EDriverTypes.h"
+#include "IrrlichtDevice.h"
+#include "dimension2d.h"
+
+extern "C" {
+
+ void
+ init_irrlicht_device (void)
+ {
+ init_irrlicht_device_object ();
+ scm_c_define_gsubr ("create-device", 7, 0, 0, (scm_t_subr)irr_createDevice);
+ scm_c_define_gsubr ("set-window-caption!", 2, 0, 0, (scm_t_subr)irr_setWindowCaption);
+ }
+
+ static SCM irrlicht_device;
+
+ void
+ init_irrlicht_device_object (void)
+ {
+ SCM name, slots;
+ scm_t_struct_finalize finalizer;
+
+ name = scm_from_utf8_symbol ("device");
+ slots = scm_list_1 (scm_from_utf8_symbol ("data"));
+ finalizer = NULL;
+
+ irrlicht_device =
+ scm_make_foreign_object_type (name, slots, finalizer);
+ }
+
+ SCM
+ irr_createDevice (SCM deviceType,
+ SCM windowSize,
+ SCM bits,
+ SCM fullscreen,
+ SCM stencilbuffer,
+ SCM vsync,
+ SCM receiver)
+ {
+ irr::IrrlichtDevice* device =
+ irr::createDevice (scm_to_driver_type (deviceType),
+ scm_to_dimension2d_u32 (windowSize),
+ scm_to_uint32 (bits),
+ scm_to_bool (fullscreen),
+ scm_to_bool (stencilbuffer),
+ scm_to_bool (vsync));
+ return scm_make_foreign_object_1 (irrlicht_device, device);
+ }
+
+ SCM
+ irr_setWindowCaption (SCM device_obj,
+ SCM text)
+ {
+ irr::IrrlichtDevice* device;
+ char* ctext;
+ wchar_t* wtext;
+
+ scm_assert_foreign_object_type (irrlicht_device, device_obj);
+ device = (irr::IrrlichtDevice*)scm_foreign_object_ref (device_obj, 0);
+
+ ctext = scm_to_utf8_stringn (text, NULL);
+ wtext = (wchar_t*)malloc ((strlen (ctext) + 1) * sizeof (wchar_t));
+ mbstowcs (wtext, ctext, strlen (ctext) + 1);
+
+ device->setWindowCaption (wtext);
+ return SCM_UNSPECIFIED;
+ }
+
+}