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 ("get-event-gui-caller", 1, 0, 0, get_event_gui_caller);
39 DEFINE_GSUBR ("get-event-gui-type", 1, 0, 0, get_event_gui_type);
40 DEFINE_GSUBR ("get-event-key-input-key", 1, 0, 0, get_event_key_input_key);
41 DEFINE_GSUBR ("get-event-key-input-pressed", 1, 0, 0, get_event_key_input_pressed);
42 DEFINE_GSUBR ("get-event-type", 1, 0, 0, get_event_type);
43 DEFINE_GSUBR ("make-event-receiver", 1, 0, 0, make_event_receiver);
46 DEFINE_WRAPPED_TYPE (irr::IEventReceiver*, "event-receiver",
47 init_event_receiver_type, event_receiver_p,
48 wrap_event_receiver, unwrap_event_receiver);
50 DEFINE_WRAPPED_TYPE (irr::SEvent*, "event",
51 init_event_type, event_p,
52 wrap_event, unwrap_event);
55 get_event_gui_caller (SCM event)
57 return wrap_gui_element (unwrap_event (event)->GUIEvent.Caller);
61 get_event_gui_type (SCM event)
63 return scm_from_gui_event_type (unwrap_event (event)->GUIEvent.EventType);
67 get_event_key_input_key (SCM event)
69 return scm_from_key_code (unwrap_event (event)->KeyInput.Key);
73 get_event_key_input_pressed (SCM event)
75 return scm_from_bool (unwrap_event (event)->KeyInput.PressedDown);
79 get_event_type (SCM event)
81 return scm_from_event_type (unwrap_event (event)->EventType);
85 make_event_receiver (SCM proc_on_event)
87 class CustomReceiver : public irr::IEventReceiver
92 CustomReceiver (SCM on_event)
94 scm_on_event = on_event;
97 virtual bool OnEvent (const irr::SEvent& event)
99 return scm_to_bool (scm_call_1 (scm_on_event, wrap_event ((irr::SEvent*)&event)));
103 CustomReceiver* receiver = new CustomReceiver (proc_on_event);
104 return wrap_event_receiver (receiver);
108 scm_from_event_type (irr::EEVENT_TYPE event_type)
112 case irr::EET_GUI_EVENT:
113 return scm_from_utf8_symbol ("gui-event");
116 case irr::EET_MOUSE_INPUT_EVENT:
117 return scm_from_utf8_symbol ("mouse-input-event");
120 case irr::EET_KEY_INPUT_EVENT:
121 return scm_from_utf8_symbol ("key-input-event");
124 case irr::EET_JOYSTICK_INPUT_EVENT:
125 return scm_from_utf8_symbol ("joystick-input-event");
128 case irr::EET_LOG_TEXT_EVENT:
129 return scm_from_utf8_symbol ("log-text-event");
132 case irr::EET_USER_EVENT:
133 return scm_from_utf8_symbol ("user-event");
137 SCM type = scm_from_uint (event_type);
138 scm_error (scm_arg_type_key, NULL, "Wrong event type: ~S",
139 scm_list_1 (type), scm_list_1 (type));
144 scm_from_gui_event_type (irr::gui::EGUI_EVENT_TYPE gui_event_type)
146 switch (gui_event_type)
148 case irr::gui::EGET_ELEMENT_FOCUS_LOST:
149 return scm_from_utf8_symbol ("element-focus-lost");
152 case irr::gui::EGET_ELEMENT_FOCUSED:
153 return scm_from_utf8_symbol ("element-focused");
156 case irr::gui::EGET_ELEMENT_HOVERED:
157 return scm_from_utf8_symbol ("element-hovered");
160 case irr::gui::EGET_ELEMENT_LEFT:
161 return scm_from_utf8_symbol ("element-left");
164 case irr::gui::EGET_ELEMENT_CLOSED:
165 return scm_from_utf8_symbol ("element-closed");
168 case irr::gui::EGET_BUTTON_CLICKED:
169 return scm_from_utf8_symbol ("button-clicked");
172 case irr::gui::EGET_SCROLL_BAR_CHANGED:
173 return scm_from_utf8_symbol ("scrollbar-changed");
176 case irr::gui::EGET_CHECKBOX_CHANGED:
177 return scm_from_utf8_symbol ("checkbox-changed");
180 case irr::gui::EGET_LISTBOX_CHANGED:
181 return scm_from_utf8_symbol ("listbox-changed");
184 case irr::gui::EGET_LISTBOX_SELECTED_AGAIN:
185 return scm_from_utf8_symbol ("listbox-selected-again");
188 case irr::gui::EGET_FILE_SELECTED:
189 return scm_from_utf8_symbol ("file-selected");
192 case irr::gui::EGET_DIRECTORY_SELECTED:
193 return scm_from_utf8_symbol ("directory-selected");
196 case irr::gui::EGET_FILE_CHOOSE_DIALOG_CANCELLED:
197 return scm_from_utf8_symbol ("file-choose-dialog-cancelled");
200 case irr::gui::EGET_MESSAGEBOX_YES:
201 return scm_from_utf8_symbol ("messagebox-yes");
204 case irr::gui::EGET_MESSAGEBOX_NO:
205 return scm_from_utf8_symbol ("messagebox-no");
208 case irr::gui::EGET_MESSAGEBOX_OK:
209 return scm_from_utf8_symbol ("messagebox-ok");
212 case irr::gui::EGET_MESSAGEBOX_CANCEL:
213 return scm_from_utf8_symbol ("messagebox-cancel");
216 case irr::gui::EGET_EDITBOX_ENTER:
217 return scm_from_utf8_symbol ("editbox-enter");
220 case irr::gui::EGET_EDITBOX_CHANGED:
221 return scm_from_utf8_symbol ("editbox-changed");
224 case irr::gui::EGET_EDITBOX_MARKING_CHANGED:
225 return scm_from_utf8_symbol ("editbox-marking-changed");
228 case irr::gui::EGET_TAB_CHANGED:
229 return scm_from_utf8_symbol ("tab-changed");
232 case irr::gui::EGET_MENU_ITEM_SELECTED:
233 return scm_from_utf8_symbol ("menu-item-selected");
236 case irr::gui::EGET_COMBO_BOX_CHANGED:
237 return scm_from_utf8_symbol ("combo-box-changed");
240 case irr::gui::EGET_SPINBOX_CHANGED:
241 return scm_from_utf8_symbol ("spinbox-changed");
244 case irr::gui::EGET_TABLE_CHANGED:
245 return scm_from_utf8_symbol ("table-changed");
248 case irr::gui::EGET_TABLE_HEADER_CHANGED:
249 return scm_from_utf8_symbol ("table-header-changed");
252 case irr::gui::EGET_TABLE_SELECTED_AGAIN:
253 return scm_from_utf8_symbol ("table-selected-again");
256 case irr::gui::EGET_TREEVIEW_NODE_DESELECT:
257 return scm_from_utf8_symbol ("treeview-node-deselect");
260 case irr::gui::EGET_TREEVIEW_NODE_SELECT:
261 return scm_from_utf8_symbol ("treeview-node-select");
264 case irr::gui::EGET_TREEVIEW_NODE_EXPAND:
265 return scm_from_utf8_symbol ("treeview-node-expand");
268 case irr::gui::EGET_TREEVIEW_NODE_COLLAPSE:
269 return scm_from_utf8_symbol ("treeview-node-collapse");
273 SCM type = scm_from_uint (gui_event_type);
274 scm_error (scm_arg_type_key, NULL, "Wrong GUI event type: ~S",
275 scm_list_1 (type), scm_list_1 (type));