29 #include "nomlib/system/Input.hpp"
33 Input::Input (
void ) :
34 joystick_ { Input::JoystickUniquePtr (
nullptr, priv::Free_Joystick ) },
37 NOM_LOG_TRACE ( NOM );
39 if ( SDL_WasInit( SDL_INIT_JOYSTICK ) ==
false )
41 if ( SDL_InitSubSystem ( SDL_INIT_JOYSTICK ) < 0 )
43 NOM_LOG_ERR ( NOM, SDL_GetError() );
48 NOM_LOG_INFO ( NOM, std::to_string ( SDL_NumJoysticks() ) +
" joysticks were found" );
50 if ( SDL_NumJoysticks() > 0 )
52 this->joystick_.reset ( SDL_JoystickOpen ( 0 ) );
54 if ( this->joystick_.get() )
56 for(
int idx = 0; idx < SDL_NumJoysticks(); idx++ )
58 NOM_LOG_INFO ( NOM, SDL_JoystickNameForIndex ( idx ) );
61 SDL_JoystickEventState ( SDL_ENABLE );
63 this->joystick_id_ = SDL_JoystickInstanceID ( this->joystick_.get() );
68 Input::~Input (
void )
70 NOM_LOG_TRACE ( NOM );
74 void Input::HandleInput ( EventType* event )
76 switch ( event->type )
80 case SDL_QUIT: this->onQuit();
break;
84 switch ( event->window.event )
88 case SDL_WINDOWEVENT_CLOSE: this->onQuit();
break;
108 this->onUserEvent ( event->user.type, event->user.code, event->user.data1,
113 case SDL_SYSWMEVENT:
break;
116 this->onKeyDown ( event->key.keysym.sym, event->key.keysym.mod, event->button.windowID );
120 this->onKeyUp ( event->key.keysym.sym, event->key.keysym.mod, event->button.windowID );
123 case SDL_MOUSEMOTION:
124 this->onMouseMotion ( event->motion.x, event->motion.y, event->motion.windowID );
127 case SDL_MOUSEBUTTONDOWN:
129 switch ( event->button.button )
131 case SDL_BUTTON_LEFT:
132 this->onMouseLeftButtonDown ( event->button.x, event->button.y, event->button.windowID );
135 case SDL_BUTTON_MIDDLE:
136 this->onMouseMiddleButtonDown ( event->button.x, event->button.y, event->button.windowID );
139 case SDL_BUTTON_RIGHT:
140 this->onMouseRightButtonDown ( event->button.x, event->button.y, event->button.windowID );
144 this->onMouseButtonSixDown ( event->button.x, event->button.y, event->button.windowID );
148 this->onMouseButtonSevenDown ( event->button.x, event->button.y, event->button.windowID );
154 case SDL_MOUSEBUTTONUP:
155 switch ( event->button.button )
157 case SDL_BUTTON_LEFT:
158 this->onMouseLeftButtonUp ( event->button.x, event->button.y, event->button.windowID );
161 case SDL_BUTTON_MIDDLE:
162 this->onMouseMiddleButtonUp ( event->button.x, event->button.y, event->button.windowID );
165 case SDL_BUTTON_RIGHT:
166 this->onMouseRightButtonUp ( event->button.x, event->button.y, event->button.windowID );
170 this->onMouseButtonSixUp ( event->button.x, event->button.y, event->button.windowID );
174 this->onMouseButtonSevenUp ( event->button.x, event->button.y, event->button.windowID );
181 this->onMouseWheel ( event->wheel.x, event->wheel.y, event->wheel.windowID );
185 case SDL_JOYBUTTONDOWN:
186 this->onJoyButtonDown ( this->joystick_id_, event->jbutton.button );
189 case SDL_JOYBUTTONUP:
190 this->onJoyButtonUp ( this->joystick_id_, event->jbutton.button );
193 case SDL_JOYAXISMOTION:
194 this->onJoyAxis ( this->joystick_id_, event->jaxis.axis, event->jaxis.value );
199 char* file =
event->drop.file;
200 this->
onDragDrop ( file, event->drop.timestamp );
211 void Input::onUserEvent ( uint32 type, int32 code,
void* data1,
void* data2 )
216 void Input::onQuit (
void )
221 void Input::onResize ( int32 width, int32 height )
226 void Input::onRestore (
void )
231 void Input::onMinimize (
void )
236 void Input::onInputFocus (
void )
241 void Input::onInputBlur (
void )
246 void Input::onMouseFocus (
void )
251 void Input::onMouseBlur (
void )
256 void Input::onExpose (
void )
261 void Input::onKeyDown ( int32 key, int32 mod, uint32 window_id )
263 #if defined ( NOM_DEBUG_SDL2_KEYBOARD_INPUT )
264 NOM_LOG_TRACE ( NOM );
265 NOM_DUMP_VAR ( key );
266 NOM_DUMP_VAR ( mod );
267 NOM_DUMP_VAR ( window_id );
271 void Input::onKeyUp ( int32 key, int32 mod, uint32 window_id )
273 #if defined ( NOM_DEBUG_SDL2_KEYBOARD_INPUT )
274 NOM_LOG_TRACE ( NOM );
275 NOM_DUMP_VAR ( key );
276 NOM_DUMP_VAR ( mod );
277 NOM_DUMP_VAR ( window_id );
281 void Input::onMouseMotion ( int32 x, int32 y, uint32 window_id )
283 #if defined ( NOM_DEBUG_SDL2_MOUSE_INPUT )
284 NOM_LOG_TRACE ( NOM );
287 NOM_DUMP_VAR ( window_id );
291 void Input::onMouseWheel ( int32 x, int32 y, uint32 window_id )
293 #if defined ( NOM_DEBUG_SDL2_MOUSE_INPUT )
294 NOM_LOG_TRACE ( NOM );
297 NOM_DUMP_VAR ( window_id );
301 void Input::onMouseLeftButtonDown ( int32 x, int32 y, uint32 window_id )
303 #if defined ( NOM_DEBUG_SDL2_MOUSE_INPUT )
304 NOM_LOG_TRACE ( NOM );
307 NOM_DUMP_VAR ( window_id );
311 void Input::onMouseMiddleButtonDown ( int32 x, int32 y, uint32 window_id )
313 #if defined ( NOM_DEBUG_SDL2_MOUSE_INPUT )
314 NOM_LOG_TRACE ( NOM );
317 NOM_DUMP_VAR ( window_id );
321 void Input::onMouseRightButtonDown ( int32 x, int32 y, uint32 window_id )
323 #if defined ( NOM_DEBUG_SDL2_MOUSE_INPUT )
324 NOM_LOG_TRACE ( NOM );
327 NOM_DUMP_VAR ( window_id );
331 void Input::onMouseButtonSixDown ( int32 x, int32 y, uint32 window_id )
333 #if defined ( NOM_DEBUG_SDL2_MOUSE_INPUT )
334 NOM_LOG_TRACE ( NOM );
337 NOM_DUMP_VAR ( window_id );
341 void Input::onMouseButtonSevenDown ( int32 x, int32 y, uint32 window_id )
343 #if defined ( NOM_DEBUG_SDL2_MOUSE_INPUT )
344 NOM_LOG_TRACE ( NOM );
347 NOM_DUMP_VAR ( window_id );
351 void Input::onMouseLeftButtonUp ( int32 x, int32 y, uint32 window_id )
353 #if defined ( NOM_DEBUG_SDL2_MOUSE_INPUT )
354 NOM_LOG_TRACE ( NOM );
357 NOM_DUMP_VAR ( window_id );
361 void Input::onMouseMiddleButtonUp ( int32 x, int32 y, uint32 window_id )
363 #if defined ( NOM_DEBUG_SDL2_MOUSE_INPUT )
364 NOM_LOG_TRACE ( NOM );
367 NOM_DUMP_VAR ( window_id );
371 void Input::onMouseRightButtonUp ( int32 x, int32 y, uint32 window_id )
373 #if defined ( NOM_DEBUG_SDL2_MOUSE_INPUT )
374 NOM_LOG_TRACE ( NOM );
377 NOM_DUMP_VAR ( window_id );
381 void Input::onMouseButtonSixUp ( int32 x, int32 y, uint32 window_id )
383 #if defined ( NOM_DEBUG_SDL2_MOUSE_INPUT )
384 NOM_LOG_TRACE ( NOM );
387 NOM_DUMP_VAR ( window_id );
391 void Input::onMouseButtonSevenUp ( int32 x, int32 y, uint32 window_id )
393 #if defined ( NOM_DEBUG_SDL2_MOUSE_INPUT )
394 NOM_LOG_TRACE ( NOM );
397 NOM_DUMP_VAR ( window_id );
401 void Input::onJoyButtonDown ( int32 which, int32 button )
403 #if defined ( NOM_DEBUG_SDL2_JOYSTICK_BUTTON_INPUT )
404 NOM_LOG_TRACE ( NOM );
405 NOM_DUMP_VAR ( which );
406 NOM_DUMP_VAR ( button );
410 void Input::onJoyButtonUp ( int32 which, int32 button )
412 #if defined ( NOM_DEBUG_SDL2_JOYSTICK_BUTTON_INPUT )
413 NOM_LOG_TRACE ( NOM );
414 NOM_DUMP_VAR ( which );
415 NOM_DUMP_VAR ( button );
419 void Input::onJoyAxis ( int32 which, int32 axis, uint16 value )
421 #if defined ( NOM_DEBUG_SDL2_JOYSTICK_AXIS_INPUT )
422 NOM_LOG_TRACE ( NOM );
423 NOM_DUMP_VAR ( which );
424 NOM_DUMP_VAR ( axis );
425 NOM_DUMP_VAR ( value );
431 #if defined ( NOM_DEBUG_SDL2_DRAG_DROP_INPUT )
432 NOM_LOG_TRACE ( NOM );
433 NOM_DUMP_VAR ( file_path );
434 NOM_DUMP_VAR ( timestamp );