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"
32 IEventReceiver_make (SCM proc_on_event)
34 class CustomReceiver : public IEventReceiver
39 CustomReceiver (SCM on_event)
41 scm_on_event = on_event;
44 virtual bool OnEvent (const SEvent& event)
46 SCM wrapped_event = scm_from_irr_pointer ("<event>", (void*) &event);
47 return scm_to_bool (scm_call_1 (scm_on_event, wrapped_event));
51 CustomReceiver* receiver = new CustomReceiver (proc_on_event);
52 return scm_from_irr_pointer ("<event-receiver>", (void*) receiver);
56 SEvent_EventType (SCM event)
58 return scm_from_event_type
59 (((SEvent*)scm_to_irr_pointer (event))->EventType);
63 SEvent_SGUIEvent_Caller (SCM event)
65 gui::IGUIElement* caller =
66 ((SEvent*)scm_to_irr_pointer (event))->GUIEvent.Caller;
67 return scm_from_irr_pointer ("<gui-element>", (void*) caller);
71 SEvent_SGUIEvent_EventType (SCM event)
73 return scm_from_gui_event_type
74 (((SEvent*)scm_to_irr_pointer (event))->GUIEvent.EventType);
78 SEvent_SKeyInput_Key (SCM event)
80 return scm_from_key_code
81 (((SEvent*)scm_to_irr_pointer (event))->KeyInput.Key);
85 SEvent_SKeyInput_PressedDown (SCM event)
88 (((SEvent*)scm_to_irr_pointer (event))->KeyInput.PressedDown);
92 init_event_receiver (void)
94 DEFINE_GSUBR ("IEventReceiver_make", 1, 0, 0, IEventReceiver_make);
95 DEFINE_GSUBR ("SEvent_EventType", 1, 0, 0, SEvent_EventType);
96 DEFINE_GSUBR ("SEvent_SGUIEvent_Caller", 1, 0, 0, SEvent_SGUIEvent_Caller);
97 DEFINE_GSUBR ("SEvent_SGUIEvent_EventType", 1, 0, 0, SEvent_SGUIEvent_EventType);
98 DEFINE_GSUBR ("SEvent_SKeyInput_Key", 1, 0, 0, SEvent_SKeyInput_Key);
99 DEFINE_GSUBR ("SEvent_SKeyInput_PressedDown", 1, 0, 0, SEvent_SKeyInput_PressedDown);
103 scm_from_event_type (EEVENT_TYPE event_type)
108 return scm_from_utf8_symbol ("gui-event");
111 case EET_MOUSE_INPUT_EVENT:
112 return scm_from_utf8_symbol ("mouse-input-event");
115 case EET_KEY_INPUT_EVENT:
116 return scm_from_utf8_symbol ("key-input-event");
119 case EET_JOYSTICK_INPUT_EVENT:
120 return scm_from_utf8_symbol ("joystick-input-event");
123 case EET_LOG_TEXT_EVENT:
124 return scm_from_utf8_symbol ("log-text-event");
128 return scm_from_utf8_symbol ("user-event");
132 SCM type = scm_from_uint (event_type);
133 scm_error (scm_arg_type_key, NULL, "Wrong event type: ~S",
134 scm_list_1 (type), scm_list_1 (type));
139 scm_from_gui_event_type (gui::EGUI_EVENT_TYPE gui_event_type)
141 switch (gui_event_type)
143 case gui::EGET_ELEMENT_FOCUS_LOST:
144 return scm_from_utf8_symbol ("element-focus-lost");
147 case gui::EGET_ELEMENT_FOCUSED:
148 return scm_from_utf8_symbol ("element-focused");
151 case gui::EGET_ELEMENT_HOVERED:
152 return scm_from_utf8_symbol ("element-hovered");
155 case gui::EGET_ELEMENT_LEFT:
156 return scm_from_utf8_symbol ("element-left");
159 case gui::EGET_ELEMENT_CLOSED:
160 return scm_from_utf8_symbol ("element-closed");
163 case gui::EGET_BUTTON_CLICKED:
164 return scm_from_utf8_symbol ("button-clicked");
167 case gui::EGET_SCROLL_BAR_CHANGED:
168 return scm_from_utf8_symbol ("scrollbar-changed");
171 case gui::EGET_CHECKBOX_CHANGED:
172 return scm_from_utf8_symbol ("checkbox-changed");
175 case gui::EGET_LISTBOX_CHANGED:
176 return scm_from_utf8_symbol ("listbox-changed");
179 case gui::EGET_LISTBOX_SELECTED_AGAIN:
180 return scm_from_utf8_symbol ("listbox-selected-again");
183 case gui::EGET_FILE_SELECTED:
184 return scm_from_utf8_symbol ("file-selected");
187 case gui::EGET_DIRECTORY_SELECTED:
188 return scm_from_utf8_symbol ("directory-selected");
191 case gui::EGET_FILE_CHOOSE_DIALOG_CANCELLED:
192 return scm_from_utf8_symbol ("file-choose-dialog-cancelled");
195 case gui::EGET_MESSAGEBOX_YES:
196 return scm_from_utf8_symbol ("messagebox-yes");
199 case gui::EGET_MESSAGEBOX_NO:
200 return scm_from_utf8_symbol ("messagebox-no");
203 case gui::EGET_MESSAGEBOX_OK:
204 return scm_from_utf8_symbol ("messagebox-ok");
207 case gui::EGET_MESSAGEBOX_CANCEL:
208 return scm_from_utf8_symbol ("messagebox-cancel");
211 case gui::EGET_EDITBOX_ENTER:
212 return scm_from_utf8_symbol ("editbox-enter");
215 case gui::EGET_EDITBOX_CHANGED:
216 return scm_from_utf8_symbol ("editbox-changed");
219 case gui::EGET_EDITBOX_MARKING_CHANGED:
220 return scm_from_utf8_symbol ("editbox-marking-changed");
223 case gui::EGET_TAB_CHANGED:
224 return scm_from_utf8_symbol ("tab-changed");
227 case gui::EGET_MENU_ITEM_SELECTED:
228 return scm_from_utf8_symbol ("menu-item-selected");
231 case gui::EGET_COMBO_BOX_CHANGED:
232 return scm_from_utf8_symbol ("combo-box-changed");
235 case gui::EGET_SPINBOX_CHANGED:
236 return scm_from_utf8_symbol ("spinbox-changed");
239 case gui::EGET_TABLE_CHANGED:
240 return scm_from_utf8_symbol ("table-changed");
243 case gui::EGET_TABLE_HEADER_CHANGED:
244 return scm_from_utf8_symbol ("table-header-changed");
247 case gui::EGET_TABLE_SELECTED_AGAIN:
248 return scm_from_utf8_symbol ("table-selected-again");
251 case gui::EGET_TREEVIEW_NODE_DESELECT:
252 return scm_from_utf8_symbol ("treeview-node-deselect");
255 case gui::EGET_TREEVIEW_NODE_SELECT:
256 return scm_from_utf8_symbol ("treeview-node-select");
259 case gui::EGET_TREEVIEW_NODE_EXPAND:
260 return scm_from_utf8_symbol ("treeview-node-expand");
263 case gui::EGET_TREEVIEW_NODE_COLLAPSE:
264 return scm_from_utf8_symbol ("treeview-node-collapse");
268 SCM type = scm_from_uint (gui_event_type);
269 scm_error (scm_arg_type_key, NULL, "Wrong GUI event type: ~S",
270 scm_list_1 (type), scm_list_1 (type));