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 IEventRecevier_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 return scm_to_bool (scm_call_1 (scm_on_event, scm_from_pointer ((void*)&event, NULL)));
50 CustomReceiver* receiver = new CustomReceiver (proc_on_event);
51 return scm_from_pointer ((void*)receiver, NULL);
55 SEvent_EventType (SCM event)
57 return scm_from_event_type
58 (((SEvent*)scm_to_irr_pointer (event))->EventType);
62 SEvent_SGUIEvent_Caller (SCM event)
64 gui::IGUIElement* caller =
65 ((SEvent*)scm_to_irr_pointer (event))->GUIEvent.Caller;
66 return scm_from_pointer ((void*)caller, NULL);
70 SEvent_SGUIEvent_EventType (SCM event)
72 return scm_from_gui_event_type
73 (((SEvent*)scm_to_irr_pointer (event))->GUIEvent.EventType);
77 SEvent_SKeyInput_Key (SCM event)
79 return scm_from_key_code
80 (((SEvent*)scm_to_irr_pointer (event))->KeyInput.Key);
84 SEvent_SKeyInput_PressedDown (SCM event)
87 (((SEvent*)scm_to_irr_pointer (event))->KeyInput.PressedDown);
91 init_event_receiver (void)
93 DEFINE_GSUBR ("IEventRecevier_make", 1, 0, 0, IEventRecevier_make);
94 DEFINE_GSUBR ("SEvent_EventType", 1, 0, 0, SEvent_EventType);
95 DEFINE_GSUBR ("SEvent_SGUIEvent_Caller", 1, 0, 0, SEvent_SGUIEvent_Caller);
96 DEFINE_GSUBR ("SEvent_SGUIEvent_EventType", 1, 0, 0, SEvent_SGUIEvent_EventType);
97 DEFINE_GSUBR ("SEvent_SKeyInput_Key", 1, 0, 0, SEvent_SKeyInput_Key);
98 DEFINE_GSUBR ("SEvent_SKeyInput_PressedDown", 1, 0, 0, SEvent_SKeyInput_PressedDown);
102 scm_from_event_type (EEVENT_TYPE event_type)
107 return scm_from_utf8_symbol ("gui-event");
110 case EET_MOUSE_INPUT_EVENT:
111 return scm_from_utf8_symbol ("mouse-input-event");
114 case EET_KEY_INPUT_EVENT:
115 return scm_from_utf8_symbol ("key-input-event");
118 case EET_JOYSTICK_INPUT_EVENT:
119 return scm_from_utf8_symbol ("joystick-input-event");
122 case EET_LOG_TEXT_EVENT:
123 return scm_from_utf8_symbol ("log-text-event");
127 return scm_from_utf8_symbol ("user-event");
131 SCM type = scm_from_uint (event_type);
132 scm_error (scm_arg_type_key, NULL, "Wrong event type: ~S",
133 scm_list_1 (type), scm_list_1 (type));
138 scm_from_gui_event_type (gui::EGUI_EVENT_TYPE gui_event_type)
140 switch (gui_event_type)
142 case gui::EGET_ELEMENT_FOCUS_LOST:
143 return scm_from_utf8_symbol ("element-focus-lost");
146 case gui::EGET_ELEMENT_FOCUSED:
147 return scm_from_utf8_symbol ("element-focused");
150 case gui::EGET_ELEMENT_HOVERED:
151 return scm_from_utf8_symbol ("element-hovered");
154 case gui::EGET_ELEMENT_LEFT:
155 return scm_from_utf8_symbol ("element-left");
158 case gui::EGET_ELEMENT_CLOSED:
159 return scm_from_utf8_symbol ("element-closed");
162 case gui::EGET_BUTTON_CLICKED:
163 return scm_from_utf8_symbol ("button-clicked");
166 case gui::EGET_SCROLL_BAR_CHANGED:
167 return scm_from_utf8_symbol ("scrollbar-changed");
170 case gui::EGET_CHECKBOX_CHANGED:
171 return scm_from_utf8_symbol ("checkbox-changed");
174 case gui::EGET_LISTBOX_CHANGED:
175 return scm_from_utf8_symbol ("listbox-changed");
178 case gui::EGET_LISTBOX_SELECTED_AGAIN:
179 return scm_from_utf8_symbol ("listbox-selected-again");
182 case gui::EGET_FILE_SELECTED:
183 return scm_from_utf8_symbol ("file-selected");
186 case gui::EGET_DIRECTORY_SELECTED:
187 return scm_from_utf8_symbol ("directory-selected");
190 case gui::EGET_FILE_CHOOSE_DIALOG_CANCELLED:
191 return scm_from_utf8_symbol ("file-choose-dialog-cancelled");
194 case gui::EGET_MESSAGEBOX_YES:
195 return scm_from_utf8_symbol ("messagebox-yes");
198 case gui::EGET_MESSAGEBOX_NO:
199 return scm_from_utf8_symbol ("messagebox-no");
202 case gui::EGET_MESSAGEBOX_OK:
203 return scm_from_utf8_symbol ("messagebox-ok");
206 case gui::EGET_MESSAGEBOX_CANCEL:
207 return scm_from_utf8_symbol ("messagebox-cancel");
210 case gui::EGET_EDITBOX_ENTER:
211 return scm_from_utf8_symbol ("editbox-enter");
214 case gui::EGET_EDITBOX_CHANGED:
215 return scm_from_utf8_symbol ("editbox-changed");
218 case gui::EGET_EDITBOX_MARKING_CHANGED:
219 return scm_from_utf8_symbol ("editbox-marking-changed");
222 case gui::EGET_TAB_CHANGED:
223 return scm_from_utf8_symbol ("tab-changed");
226 case gui::EGET_MENU_ITEM_SELECTED:
227 return scm_from_utf8_symbol ("menu-item-selected");
230 case gui::EGET_COMBO_BOX_CHANGED:
231 return scm_from_utf8_symbol ("combo-box-changed");
234 case gui::EGET_SPINBOX_CHANGED:
235 return scm_from_utf8_symbol ("spinbox-changed");
238 case gui::EGET_TABLE_CHANGED:
239 return scm_from_utf8_symbol ("table-changed");
242 case gui::EGET_TABLE_HEADER_CHANGED:
243 return scm_from_utf8_symbol ("table-header-changed");
246 case gui::EGET_TABLE_SELECTED_AGAIN:
247 return scm_from_utf8_symbol ("table-selected-again");
250 case gui::EGET_TREEVIEW_NODE_DESELECT:
251 return scm_from_utf8_symbol ("treeview-node-deselect");
254 case gui::EGET_TREEVIEW_NODE_SELECT:
255 return scm_from_utf8_symbol ("treeview-node-select");
258 case gui::EGET_TREEVIEW_NODE_EXPAND:
259 return scm_from_utf8_symbol ("treeview-node-expand");
262 case gui::EGET_TREEVIEW_NODE_COLLAPSE:
263 return scm_from_utf8_symbol ("treeview-node-collapse");
267 SCM type = scm_from_uint (gui_event_type);
268 scm_error (scm_arg_type_key, NULL, "Wrong GUI event type: ~S",
269 scm_list_1 (type), scm_list_1 (type));