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

Last change on this file since 487 was 487, checked in by epyon, 9 years ago
File size: 5.0 KB
RevLine 
[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]12using namespace nv;
13
[121]14const 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]25const 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]36const 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]47void nv::log_event( const io_event& e )
48{
[365]49        NV_LOG_INFO( "Event: ", get_io_event_name( e.type ) );
[338]50}
51
[121]52void 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        db->create_type<io_event_code>()
[487]67#       define NV_IO_EVENT( id ) .value( #id, id )
[67]68#               include <nv/detail/io_event_list.inc>
69#       undef NV_IO_EVENT
[447]70        ;
[67]71
[447]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 );
[67]79
[447]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 );
[67]86
[447]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 );
[67]94
[447]95        db->create_type<mouse_wheel_event>()
96                .field( "x",       &mouse_wheel_event::x )
97                .field( "y",       &mouse_wheel_event::y );
[304]98
[447]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 );
[184]103
[447]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 );
[184]108
[447]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 );
[184]113
[447]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 );
[184]118
[447]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
[450]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
[67]158}
Note: See TracBrowser for help on using the repository browser.