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"
33 IEventRecevier_make (SCM proc_on_event)
35 class CustomReceiver : public IEventReceiver
40 CustomReceiver (SCM on_event)
42 scm_on_event = on_event;
45 virtual bool OnEvent (const SEvent& event)
47 return scm_to_bool (scm_call_1 (scm_on_event, scm_from_pointer ((void*)&event, NULL)));
51 CustomReceiver* receiver = new CustomReceiver (proc_on_event);
52 return scm_from_pointer ((void*)receiver, NULL);
57 SEvent_EventType (SCM event)
59 return scm_from_event_type
60 (((SEvent*)scm_to_pointer (event))->EventType);
65 SEvent_SGUIEvent_Caller (SCM event)
67 gui::IGUIElement* caller =
68 ((SEvent*)scm_to_pointer (event))->GUIEvent.Caller;
69 return scm_from_pointer ((void*)caller, NULL);
74 SEvent_SGUIEvent_EventType (SCM event)
76 return scm_from_gui_event_type
77 (((SEvent*)scm_to_pointer (event))->GUIEvent.EventType);
82 SEvent_SKeyInput_Key (SCM event)
84 return scm_from_key_code
85 (((SEvent*)scm_to_pointer (event))->KeyInput.Key);
90 SEvent_SKeyInput_PressedDown (SCM event)
93 (((SEvent*)scm_to_pointer (event))->KeyInput.PressedDown);
100 init_event_receiver (void)
102 DEFINE_GSUBR ("IEventRecevier_make", 1, 0, 0, IEventRecevier_make);
103 DEFINE_GSUBR ("SEvent_EventType", 1, 0, 0, SEvent_EventType);
104 DEFINE_GSUBR ("SEvent_SGUIEvent_Caller", 1, 0, 0, SEvent_SGUIEvent_Caller);
105 DEFINE_GSUBR ("SEvent_SGUIEvent_EventType", 1, 0, 0, SEvent_SGUIEvent_EventType);
106 DEFINE_GSUBR ("SEvent_SKeyInput_Key", 1, 0, 0, SEvent_SKeyInput_Key);
107 DEFINE_GSUBR ("SEvent_SKeyInput_PressedDown", 1, 0, 0, SEvent_SKeyInput_PressedDown);
113 scm_from_event_type (EEVENT_TYPE event_type)
118 return scm_from_utf8_symbol ("gui-event");
121 case EET_MOUSE_INPUT_EVENT:
122 return scm_from_utf8_symbol ("mouse-input-event");
125 case EET_KEY_INPUT_EVENT:
126 return scm_from_utf8_symbol ("key-input-event");
129 case EET_JOYSTICK_INPUT_EVENT:
130 return scm_from_utf8_symbol ("joystick-input-event");
133 case EET_LOG_TEXT_EVENT:
134 return scm_from_utf8_symbol ("log-text-event");
138 return scm_from_utf8_symbol ("user-event");
142 SCM type = scm_from_uint (event_type);
143 scm_error (scm_arg_type_key, NULL, "Wrong event type: ~S",
144 scm_list_1 (type), scm_list_1 (type));
150 scm_from_gui_event_type (gui::EGUI_EVENT_TYPE gui_event_type)
152 switch (gui_event_type)
154 case gui::EGET_ELEMENT_FOCUS_LOST:
155 return scm_from_utf8_symbol ("element-focus-lost");
158 case gui::EGET_ELEMENT_FOCUSED:
159 return scm_from_utf8_symbol ("element-focused");
162 case gui::EGET_ELEMENT_HOVERED:
163 return scm_from_utf8_symbol ("element-hovered");
166 case gui::EGET_ELEMENT_LEFT:
167 return scm_from_utf8_symbol ("element-left");
170 case gui::EGET_ELEMENT_CLOSED:
171 return scm_from_utf8_symbol ("element-closed");
174 case gui::EGET_BUTTON_CLICKED:
175 return scm_from_utf8_symbol ("button-clicked");
178 case gui::EGET_SCROLL_BAR_CHANGED:
179 return scm_from_utf8_symbol ("scrollbar-changed");
182 case gui::EGET_CHECKBOX_CHANGED:
183 return scm_from_utf8_symbol ("checkbox-changed");
186 case gui::EGET_LISTBOX_CHANGED:
187 return scm_from_utf8_symbol ("listbox-changed");
190 case gui::EGET_LISTBOX_SELECTED_AGAIN:
191 return scm_from_utf8_symbol ("listbox-selected-again");
194 case gui::EGET_FILE_SELECTED:
195 return scm_from_utf8_symbol ("file-selected");
198 case gui::EGET_DIRECTORY_SELECTED:
199 return scm_from_utf8_symbol ("directory-selected");
202 case gui::EGET_FILE_CHOOSE_DIALOG_CANCELLED:
203 return scm_from_utf8_symbol ("file-choose-dialog-cancelled");
206 case gui::EGET_MESSAGEBOX_YES:
207 return scm_from_utf8_symbol ("messagebox-yes");
210 case gui::EGET_MESSAGEBOX_NO:
211 return scm_from_utf8_symbol ("messagebox-no");
214 case gui::EGET_MESSAGEBOX_OK:
215 return scm_from_utf8_symbol ("messagebox-ok");
218 case gui::EGET_MESSAGEBOX_CANCEL:
219 return scm_from_utf8_symbol ("messagebox-cancel");
222 case gui::EGET_EDITBOX_ENTER:
223 return scm_from_utf8_symbol ("editbox-enter");
226 case gui::EGET_EDITBOX_CHANGED:
227 return scm_from_utf8_symbol ("editbox-changed");
230 case gui::EGET_EDITBOX_MARKING_CHANGED:
231 return scm_from_utf8_symbol ("editbox-marking-changed");
234 case gui::EGET_TAB_CHANGED:
235 return scm_from_utf8_symbol ("tab-changed");
238 case gui::EGET_MENU_ITEM_SELECTED:
239 return scm_from_utf8_symbol ("menu-item-selected");
242 case gui::EGET_COMBO_BOX_CHANGED:
243 return scm_from_utf8_symbol ("combo-box-changed");
246 case gui::EGET_SPINBOX_CHANGED:
247 return scm_from_utf8_symbol ("spinbox-changed");
250 case gui::EGET_TABLE_CHANGED:
251 return scm_from_utf8_symbol ("table-changed");
254 case gui::EGET_TABLE_HEADER_CHANGED:
255 return scm_from_utf8_symbol ("table-header-changed");
258 case gui::EGET_TABLE_SELECTED_AGAIN:
259 return scm_from_utf8_symbol ("table-selected-again");
262 case gui::EGET_TREEVIEW_NODE_DESELECT:
263 return scm_from_utf8_symbol ("treeview-node-deselect");
266 case gui::EGET_TREEVIEW_NODE_SELECT:
267 return scm_from_utf8_symbol ("treeview-node-select");
270 case gui::EGET_TREEVIEW_NODE_EXPAND:
271 return scm_from_utf8_symbol ("treeview-node-expand");
274 case gui::EGET_TREEVIEW_NODE_COLLAPSE:
275 return scm_from_utf8_symbol ("treeview-node-collapse");
279 SCM type = scm_from_uint (gui_event_type);
280 scm_error (scm_arg_type_key, NULL, "Wrong GUI event type: ~S",
281 scm_list_1 (type), scm_list_1 (type));