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>
24 #include "event-receiver.h"
31 init_event_receiver (void)
33 init_event_receiver_type ();
35 DEFINE_GSUBR ("event-type", 1, 0, 0, event_type);
36 DEFINE_GSUBR ("make-event-receiver", 1, 0, 0, make_event_receiver);
39 DEFINE_WRAPPED_TYPE (irr::IEventReceiver*, "event-receiver",
40 init_event_receiver_type, event_receiver_p,
41 wrap_event_receiver, unwrap_event_receiver);
43 DEFINE_WRAPPED_TYPE (irr::SEvent*, "event",
44 init_event_type, event_p,
45 wrap_event, unwrap_event);
48 event_type (SCM event)
50 return scm_from_event_type (unwrap_event (event)->EventType);
54 make_event_receiver (SCM proc_on_event)
56 class CustomReceiver : public irr::IEventReceiver
61 CustomReceiver (SCM on_event)
63 scm_on_event = on_event;
66 virtual bool OnEvent (const irr::SEvent& event)
68 return scm_to_bool (scm_call_1 (scm_on_event, wrap_event ((irr::SEvent*)&event)));
72 CustomReceiver* receiver = new CustomReceiver (proc_on_event);
73 return wrap_event_receiver (receiver);
77 scm_from_event_type (irr::EEVENT_TYPE event_type)
81 case irr::EET_GUI_EVENT:
82 return scm_from_utf8_symbol ("gui-event");
85 case irr::EET_MOUSE_INPUT_EVENT:
86 return scm_from_utf8_symbol ("mouse-input-event");
89 case irr::EET_KEY_INPUT_EVENT:
90 return scm_from_utf8_symbol ("key-input-event");
93 case irr::EET_JOYSTICK_INPUT_EVENT:
94 return scm_from_utf8_symbol ("joystick-input-event");
97 case irr::EET_LOG_TEXT_EVENT:
98 return scm_from_utf8_symbol ("log-text-event");
101 case irr::EET_USER_EVENT:
102 return scm_from_utf8_symbol ("user-event");
106 SCM type = scm_from_uint (event_type);
107 scm_error (scm_arg_type_key, NULL, "Wrong event type: ~S",
108 scm_list_1 (type), scm_list_1 (type));