source: trunk/src/core/io_event.cc @ 493

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