1 | // Copyright (C) 2012-2014 ChaosForge Ltd
|
---|
2 | // http://chaosforge.org/
|
---|
3 | //
|
---|
4 | // This file is part of NV Libraries.
|
---|
5 | // For conditions of distribution and use, see copyright notice in nv.hh
|
---|
6 |
|
---|
7 | #include "nv/core/io_event.hh"
|
---|
8 |
|
---|
9 | #include "nv/core/logging.hh"
|
---|
10 |
|
---|
11 | using namespace nv;
|
---|
12 |
|
---|
13 | const char* nv::get_key_name( key_code key )
|
---|
14 | {
|
---|
15 | switch ( key )
|
---|
16 | {
|
---|
17 | # define NV_KEY( id, val ) case id : return #id;
|
---|
18 | # include <nv/detail/key_list.inc>
|
---|
19 | # undef NV_KEY
|
---|
20 | NV_RETURN_COVERED_DEFAULT( "KEY_UNKNOWN" );
|
---|
21 | };
|
---|
22 | }
|
---|
23 |
|
---|
24 | const char* nv::get_mouse_name( mouse_code button )
|
---|
25 | {
|
---|
26 | switch ( button )
|
---|
27 | {
|
---|
28 | # define NV_MOUSE( id, val ) case id : return #id;
|
---|
29 | # include <nv/detail/mouse_list.inc>
|
---|
30 | # undef NV_MOUSE
|
---|
31 | NV_RETURN_COVERED_DEFAULT( "MOUSE_UNKNOWN" );
|
---|
32 | };
|
---|
33 | }
|
---|
34 |
|
---|
35 | const char* nv::get_io_event_name( io_event_code event )
|
---|
36 | {
|
---|
37 | switch ( event )
|
---|
38 | {
|
---|
39 | # define NV_IO_EVENT( id ) case id : return #id;
|
---|
40 | # include <nv/detail/io_event_list.inc>
|
---|
41 | # undef NV_IO_EVENT
|
---|
42 | NV_RETURN_COVERED_DEFAULT( "EV_UNKNOWN" );
|
---|
43 | };
|
---|
44 | }
|
---|
45 |
|
---|
46 | void nv::log_event( const io_event& e )
|
---|
47 | {
|
---|
48 | NV_LOG_INFO( "Event: ", get_io_event_name( e.type ) );
|
---|
49 | }
|
---|
50 |
|
---|
51 | /************************************************************************
|
---|
52 | void nv::register_io_types( type_database* db )
|
---|
53 | {
|
---|
54 | type_enum key_enums[] = {
|
---|
55 | # define NV_KEY( id, val ) type_enum( #id, id ),
|
---|
56 | # include <nv/detail/key_list.inc>
|
---|
57 | # undef NV_KEY
|
---|
58 | };
|
---|
59 | db->create_type<key_code>("key_code").enums( key_enums );
|
---|
60 |
|
---|
61 | type_enum mouse_enums[] = {
|
---|
62 | # define NV_MOUSE( id, val ) type_enum( #id, id ),
|
---|
63 | # include <nv/detail/mouse_list.inc>
|
---|
64 | # undef NV_MOUSE
|
---|
65 | };
|
---|
66 | db->create_type<mouse_code>("mouse_code").enums( mouse_enums );
|
---|
67 |
|
---|
68 | type_enum io_event_enums[] = {
|
---|
69 | # define NV_IO_EVENT( id ) type_enum( #id, id ),
|
---|
70 | # include <nv/detail/io_event_list.inc>
|
---|
71 | # undef NV_IO_EVENT
|
---|
72 | };
|
---|
73 | db->create_type<io_event_code>("event_code").enums( io_event_enums );
|
---|
74 |
|
---|
75 | type_field key_fields[] = {
|
---|
76 | type_field( "ascii", &key_event::ascii ),
|
---|
77 | type_field( "code", &key_event::code ),
|
---|
78 | type_field( "shift", &key_event::shift ),
|
---|
79 | type_field( "control", &key_event::control ),
|
---|
80 | type_field( "alt", &key_event::alt ),
|
---|
81 | type_field( "pressed", &key_event::pressed ),
|
---|
82 | };
|
---|
83 | db->create_type<key_event>("key_event").fields( key_fields );
|
---|
84 |
|
---|
85 | type_field mouse_button_fields[] = {
|
---|
86 | type_field( "x", &mouse_button_event::x ),
|
---|
87 | type_field( "y", &mouse_button_event::y ),
|
---|
88 | type_field( "button", &mouse_button_event::button ),
|
---|
89 | type_field( "pressed", &mouse_button_event::pressed ),
|
---|
90 | type_field( "code", &mouse_button_event::code ),
|
---|
91 | };
|
---|
92 | db->create_type<mouse_button_event>("mouse_button_event").fields( mouse_button_fields );
|
---|
93 |
|
---|
94 | type_field mouse_move_fields[] = {
|
---|
95 | type_field( "x", &mouse_move_event::x ),
|
---|
96 | type_field( "y", &mouse_move_event::y ),
|
---|
97 | type_field( "rx", &mouse_move_event::rx ),
|
---|
98 | type_field( "ry", &mouse_move_event::ry ),
|
---|
99 | type_field( "pressed", &mouse_move_event::pressed ),
|
---|
100 | type_field( "code", &mouse_move_event::code ),
|
---|
101 | };
|
---|
102 | db->create_type<mouse_move_event>("mouse_move_event").fields( mouse_move_fields );
|
---|
103 |
|
---|
104 | type_field mouse_wheel_fields[] = {
|
---|
105 | type_field( "x", &mouse_wheel_event::x ),
|
---|
106 | type_field( "y", &mouse_wheel_event::y ),
|
---|
107 | };
|
---|
108 | db->create_type<mouse_wheel_event>("mouse_wheel_event").fields( mouse_wheel_fields );
|
---|
109 |
|
---|
110 | type_field joy_button_fields[] = {
|
---|
111 | type_field( "id", &joy_button_event::id ),
|
---|
112 | type_field( "button", &joy_button_event::button ),
|
---|
113 | type_field( "pressed", &joy_button_event::pressed ),
|
---|
114 | };
|
---|
115 | db->create_type<joy_button_event>("joy_button_event").fields( joy_button_fields );
|
---|
116 |
|
---|
117 | type_field joy_axis_fields[] = {
|
---|
118 | type_field( "id", &joy_axis_event::id ),
|
---|
119 | type_field( "axis", &joy_axis_event::axis ),
|
---|
120 | type_field( "value", &joy_axis_event::value ),
|
---|
121 | };
|
---|
122 | db->create_type<joy_axis_event>("joy_axis_event").fields( joy_axis_fields );
|
---|
123 |
|
---|
124 | type_field joy_hat_fields[] = {
|
---|
125 | type_field( "id", &joy_hat_event::id ),
|
---|
126 | type_field( "hat", &joy_hat_event::hat ),
|
---|
127 | type_field( "value", &joy_hat_event::value ),
|
---|
128 | };
|
---|
129 | db->create_type<joy_hat_event>("joy_hat_event").fields( joy_hat_fields );
|
---|
130 |
|
---|
131 | type_field joy_ball_fields[] = {
|
---|
132 | type_field( "id", &joy_ball_event::id ),
|
---|
133 | type_field( "ball", &joy_ball_event::ball ),
|
---|
134 | type_field( "rx", &joy_ball_event::rx ),
|
---|
135 | type_field( "ry", &joy_ball_event::ry ),
|
---|
136 | };
|
---|
137 | db->create_type<joy_ball_event>("joy_ball_event").fields( joy_ball_fields );
|
---|
138 |
|
---|
139 | type_field system_fields[] = {
|
---|
140 | type_field( "sys_type", &system_event::sys_type ),
|
---|
141 | type_field( "param1", &system_event::param1 ),
|
---|
142 | type_field( "param2", &system_event::param2 ),
|
---|
143 | };
|
---|
144 | db->create_type<system_event>("system_event").fields( system_fields );
|
---|
145 | }
|
---|
146 | ************************************************************************/
|
---|