[395] | 1 | // Copyright (C) 2012-2015 ChaosForge Ltd
|
---|
[67] | 2 | // http://chaosforge.org/
|
---|
| 3 | //
|
---|
[395] | 4 | // This file is part of Nova libraries.
|
---|
| 5 | // For conditions of distribution and use, see copying.txt file in root folder.
|
---|
[67] | 6 |
|
---|
[319] | 7 | #include "nv/core/io_event.hh"
|
---|
[67] | 8 |
|
---|
[338] | 9 | #include "nv/core/logging.hh"
|
---|
[447] | 10 | #include "nv/core/types.hh"
|
---|
[338] | 11 |
|
---|
[67] | 12 | using namespace nv;
|
---|
| 13 |
|
---|
[121] | 14 | const char* nv::get_key_name( key_code key )
|
---|
[67] | 15 | {
|
---|
| 16 | switch ( key )
|
---|
| 17 | {
|
---|
| 18 | # define NV_KEY( id, val ) case id : return #id;
|
---|
| 19 | # include <nv/detail/key_list.inc>
|
---|
| 20 | # undef NV_KEY
|
---|
[121] | 21 | NV_RETURN_COVERED_DEFAULT( "KEY_UNKNOWN" );
|
---|
[67] | 22 | };
|
---|
| 23 | }
|
---|
| 24 |
|
---|
[121] | 25 | const char* nv::get_mouse_name( mouse_code button )
|
---|
[67] | 26 | {
|
---|
| 27 | switch ( button )
|
---|
| 28 | {
|
---|
| 29 | # define NV_MOUSE( id, val ) case id : return #id;
|
---|
| 30 | # include <nv/detail/mouse_list.inc>
|
---|
| 31 | # undef NV_MOUSE
|
---|
[121] | 32 | NV_RETURN_COVERED_DEFAULT( "MOUSE_UNKNOWN" );
|
---|
[67] | 33 | };
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[121] | 36 | const char* nv::get_io_event_name( io_event_code event )
|
---|
[67] | 37 | {
|
---|
| 38 | switch ( event )
|
---|
| 39 | {
|
---|
| 40 | # define NV_IO_EVENT( id ) case id : return #id;
|
---|
| 41 | # include <nv/detail/io_event_list.inc>
|
---|
| 42 | # undef NV_IO_EVENT
|
---|
[121] | 43 | NV_RETURN_COVERED_DEFAULT( "EV_UNKNOWN" );
|
---|
[67] | 44 | };
|
---|
| 45 | }
|
---|
| 46 |
|
---|
[338] | 47 | void nv::log_event( const io_event& e )
|
---|
| 48 | {
|
---|
[365] | 49 | NV_LOG_INFO( "Event: ", get_io_event_name( e.type ) );
|
---|
[338] | 50 | }
|
---|
| 51 |
|
---|
[121] | 52 | void nv::register_io_types( type_database* db )
|
---|
[67] | 53 | {
|
---|
[447] | 54 | db->create_type<key_code>()
|
---|
| 55 | # define NV_KEY( id, val ) .value( #id, val )
|
---|
[67] | 56 | # include <nv/detail/key_list.inc>
|
---|
| 57 | # undef NV_KEY
|
---|
[447] | 58 | ;
|
---|
[67] | 59 |
|
---|
[447] | 60 | db->create_type<mouse_code>()
|
---|
| 61 | # define NV_MOUSE( id, val ) .value( #id, val )
|
---|
[67] | 62 | # include <nv/detail/mouse_list.inc>
|
---|
| 63 | # undef NV_MOUSE
|
---|
[447] | 64 | ;
|
---|
[67] | 65 |
|
---|
[447] | 66 | uint32 counter = 0;
|
---|
| 67 | db->create_type<io_event_code>()
|
---|
| 68 | # define NV_IO_EVENT( id ) .value( #id, counter++ )
|
---|
[67] | 69 | # include <nv/detail/io_event_list.inc>
|
---|
| 70 | # undef NV_IO_EVENT
|
---|
[447] | 71 | ;
|
---|
[67] | 72 |
|
---|
[447] | 73 | db->create_type<key_event>()
|
---|
| 74 | .field( "ascii", &key_event::ascii )
|
---|
| 75 | .field( "code", &key_event::code )
|
---|
| 76 | .field( "shift", &key_event::shift )
|
---|
| 77 | .field( "control", &key_event::control )
|
---|
| 78 | .field( "alt", &key_event::alt )
|
---|
| 79 | .field( "pressed", &key_event::pressed );
|
---|
[67] | 80 |
|
---|
[447] | 81 | db->create_type<mouse_button_event>()
|
---|
| 82 | .field( "x", &mouse_button_event::x )
|
---|
| 83 | .field( "y", &mouse_button_event::y )
|
---|
| 84 | .field( "button", &mouse_button_event::button )
|
---|
| 85 | .field( "pressed", &mouse_button_event::pressed )
|
---|
| 86 | .field( "code", &mouse_button_event::code );
|
---|
[67] | 87 |
|
---|
[447] | 88 | db->create_type<mouse_move_event>()
|
---|
| 89 | .field( "x", &mouse_move_event::x )
|
---|
| 90 | .field( "y", &mouse_move_event::y )
|
---|
| 91 | .field( "rx", &mouse_move_event::rx )
|
---|
| 92 | .field( "ry", &mouse_move_event::ry )
|
---|
| 93 | .field( "pressed", &mouse_move_event::pressed )
|
---|
| 94 | .field( "code", &mouse_move_event::code );
|
---|
[67] | 95 |
|
---|
[447] | 96 | db->create_type<mouse_wheel_event>()
|
---|
| 97 | .field( "x", &mouse_wheel_event::x )
|
---|
| 98 | .field( "y", &mouse_wheel_event::y );
|
---|
[304] | 99 |
|
---|
[447] | 100 | db->create_type<pad_button_event>()
|
---|
| 101 | .field( "id", &pad_button_event::id )
|
---|
| 102 | .field( "button", &pad_button_event::button )
|
---|
| 103 | .field( "pressed", &pad_button_event::pressed );
|
---|
[184] | 104 |
|
---|
[447] | 105 | db->create_type<pad_axis_event>()
|
---|
| 106 | .field( "id", &pad_axis_event::id )
|
---|
| 107 | .field( "axis", &pad_axis_event::axis )
|
---|
| 108 | .field( "value", &pad_axis_event::value );
|
---|
[184] | 109 |
|
---|
[447] | 110 | db->create_type<joy_button_event>()
|
---|
| 111 | .field( "id", &joy_button_event::id )
|
---|
| 112 | .field( "button", &joy_button_event::button )
|
---|
| 113 | .field( "pressed", &joy_button_event::pressed );
|
---|
[184] | 114 |
|
---|
[447] | 115 | db->create_type<joy_axis_event>()
|
---|
| 116 | .field( "id", &joy_axis_event::id )
|
---|
| 117 | .field( "axis", &joy_axis_event::axis )
|
---|
| 118 | .field( "value", &joy_axis_event::value );
|
---|
[184] | 119 |
|
---|
[447] | 120 | db->create_type<joy_hat_event>()
|
---|
| 121 | .field( "id", &joy_hat_event::id )
|
---|
| 122 | .field( "hat", &joy_hat_event::hat )
|
---|
| 123 | .field( "value", &joy_hat_event::value );
|
---|
| 124 |
|
---|
| 125 | db->create_type<joy_ball_event>()
|
---|
| 126 | .field( "id", &joy_ball_event::id )
|
---|
| 127 | .field( "ball", &joy_ball_event::ball )
|
---|
| 128 | .field( "rx", &joy_ball_event::rx )
|
---|
| 129 | .field( "ry", &joy_ball_event::ry );
|
---|
| 130 |
|
---|
| 131 | db->create_type<resize_event>()
|
---|
| 132 | .field( "x", &resize_event::x )
|
---|
| 133 | .field( "y", &resize_event::y );
|
---|
| 134 |
|
---|
| 135 | db->create_type<active_event>()
|
---|
| 136 | .field( "gain", &active_event::gain );
|
---|
| 137 |
|
---|
| 138 | db->create_type<system_event>()
|
---|
| 139 | .field( "sys_type", &system_event::sys_type )
|
---|
| 140 | .field( "param1", &system_event::param1 )
|
---|
| 141 | .field( "param2", &system_event::param2 );
|
---|
| 142 |
|
---|
[450] | 143 | db->create_type<io_event>()
|
---|
| 144 | .field( "type", &io_event::type )
|
---|
| 145 | .union_field( "key", &io_event::key, "type", EV_KEY )
|
---|
| 146 | .union_field( "mbutton", &io_event::mbutton,"type", EV_MOUSE_BUTTON )
|
---|
| 147 | .union_field( "mmove", &io_event::mmove, "type", EV_MOUSE_MOVE )
|
---|
| 148 | .union_field( "mwheel", &io_event::mwheel, "type", EV_MOUSE_WHEEL )
|
---|
| 149 | .union_field( "pbutton", &io_event::pbutton,"type", EV_PAD_BUTTON )
|
---|
| 150 | .union_field( "paxis", &io_event::paxis, "type", EV_PAD_AXIS )
|
---|
| 151 | .union_field( "jbutton", &io_event::jbutton,"type", EV_JOY_BUTTON )
|
---|
| 152 | .union_field( "jaxis", &io_event::jaxis, "type", EV_JOY_AXIS )
|
---|
| 153 | .union_field( "jhat", &io_event::jhat, "type", EV_JOY_HAT )
|
---|
| 154 | .union_field( "jball", &io_event::jball, "type", EV_JOY_BALL )
|
---|
| 155 | .union_field( "resize", &io_event::resize, "type", EV_ACTIVE )
|
---|
| 156 | .union_field( "active", &io_event::active, "type", EV_RESIZE )
|
---|
| 157 | .union_field( "system", &io_event::system, "type", EV_SYSTEM );
|
---|
| 158 |
|
---|
[67] | 159 | }
|
---|