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>
25 #include "event-receiver.h"
26 #include "gui-element.h"
34 init_event_receiver (void)
36 init_event_receiver_type ();
38 DEFINE_GSUBR ("event-gui-caller", 1, 0, 0, event_gui_caller);
39 DEFINE_GSUBR ("event-key-input-key", 1, 0, 0, event_key_input_key);
40 DEFINE_GSUBR ("event-key-input-pressed", 1, 0, 0, event_key_input_pressed);
41 DEFINE_GSUBR ("event-type", 1, 0, 0, event_type);
42 DEFINE_GSUBR ("make-event-receiver", 1, 0, 0, make_event_receiver);
45 DEFINE_WRAPPED_TYPE (irr::IEventReceiver*, "event-receiver",
46 init_event_receiver_type, event_receiver_p,
47 wrap_event_receiver, unwrap_event_receiver);
49 DEFINE_WRAPPED_TYPE (irr::SEvent*, "event",
50 init_event_type, event_p,
51 wrap_event, unwrap_event);
54 event_gui_caller (SCM event)
56 return wrap_gui_element (unwrap_event (event)->GUIEvent.Caller);
60 event_key_input_key (SCM event)
62 return scm_from_key_code (unwrap_event (event)->KeyInput.Key);
66 event_key_input_pressed (SCM event)
68 return scm_from_bool (unwrap_event (event)->KeyInput.PressedDown);
72 event_type (SCM event)
74 return scm_from_event_type (unwrap_event (event)->EventType);
78 make_event_receiver (SCM proc_on_event)
80 class CustomReceiver : public irr::IEventReceiver
85 CustomReceiver (SCM on_event)
87 scm_on_event = on_event;
90 virtual bool OnEvent (const irr::SEvent& event)
92 return scm_to_bool (scm_call_1 (scm_on_event, wrap_event ((irr::SEvent*)&event)));
96 CustomReceiver* receiver = new CustomReceiver (proc_on_event);
97 return wrap_event_receiver (receiver);
101 scm_from_event_type (irr::EEVENT_TYPE event_type)
105 case irr::EET_GUI_EVENT:
106 return scm_from_utf8_symbol ("gui-event");
109 case irr::EET_MOUSE_INPUT_EVENT:
110 return scm_from_utf8_symbol ("mouse-input-event");
113 case irr::EET_KEY_INPUT_EVENT:
114 return scm_from_utf8_symbol ("key-input-event");
117 case irr::EET_JOYSTICK_INPUT_EVENT:
118 return scm_from_utf8_symbol ("joystick-input-event");
121 case irr::EET_LOG_TEXT_EVENT:
122 return scm_from_utf8_symbol ("log-text-event");
125 case irr::EET_USER_EVENT:
126 return scm_from_utf8_symbol ("user-event");
130 SCM type = scm_from_uint (event_type);
131 scm_error (scm_arg_type_key, NULL, "Wrong event type: ~S",
132 scm_list_1 (type), scm_list_1 (type));