]> git.jsancho.org Git - guile-irrlicht.git/blob - src/device.cpp
GOOPS and POC with create-device
[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 "timer.h"
31 #include "wchar.h"
32 #include "wrapped.h"
33
34 extern "C" {
35
36   void
37   init_device (void)
38   {
39     init_device_type ();
40     DEFINE_GSUBR ("irr_createDevice", 7, 0, 0, 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);
48   }
49
50   DEFINE_WRAPPED_TYPE (irr::IrrlichtDevice*, "device",
51                        init_device_type, device_p,
52                        wrap_device, unwrap_device);
53
54   SCM
55   irr_createDevice (SCM device_type,
56                     SCM window_size,
57                     SCM bits,
58                     SCM fullscreen,
59                     SCM stencilbuffer,
60                     SCM vsync,
61                     SCM receiver)
62   {
63     UNWRAP (receiver);
64
65     irr::IrrlichtDevice* device =
66       irr::createDevice (scm_to_driver_type (device_type),
67                          scm_to_dimension2d_u32 (window_size),
68                          scm_to_uint32 (bits),
69                          scm_to_bool (fullscreen),
70                          scm_to_bool (stencilbuffer),
71                          scm_to_bool (vsync),
72                          UNWRAPPED (receiver));
73     return scm_from_pointer (device, NULL);
74   }
75
76   SCM
77   irr_getTimer (SCM wrapped_device)
78   {
79     irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
80     return wrap_timer (device->getTimer ());
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_setEventReceiver (SCM wrapped_device,
99                         SCM receiver)
100   {
101     irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
102     device->setEventReceiver (unwrap_event_receiver (receiver));
103     return SCM_UNSPECIFIED;
104   }
105
106   SCM
107   irr_setResizable (SCM wrapped_device,
108                     SCM resize)
109   {
110     irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
111     device->setResizable (scm_to_bool (resize));
112     return SCM_UNSPECIFIED;
113   }
114
115   SCM
116   irr_setWindowCaption (SCM wrapped_device,
117                         SCM text)
118   {
119     irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
120     device->setWindowCaption (scm_to_wide_char_string (text));
121     return SCM_UNSPECIFIED;
122   }
123
124   SCM
125   irr_yield (SCM wrapped_device)
126   {
127     irr::IrrlichtDevice* device = unwrap_device (wrapped_device);
128     device->yield ();
129     return SCM_UNSPECIFIED;
130   }
131
132 }