129 lines
2.6 KiB
C
129 lines
2.6 KiB
C
#include <stddef.h>
|
|
#include "../headers/glut_input.h"
|
|
#include "../headers/input/input_events.h"
|
|
|
|
#include <stdio.h> /* a single printf */
|
|
|
|
void ( *keyboard_callback) ( unsigned char key, int x, int y) = NULL;
|
|
void ( *mouse_motion_callback) ( int x, int y) = NULL;
|
|
|
|
void warp_pointer_implementation( int x, int y){}
|
|
|
|
void assignKeyboardCallback( void ( *callback) (unsigned char key, int x, int y)){
|
|
if(keyboard_callback != NULL){
|
|
return;
|
|
}
|
|
keyboard_callback = callback;
|
|
}
|
|
|
|
void assignMouseMotionCallback( void ( *callback) (int x, int y)){
|
|
if(mouse_motion_callback != NULL){
|
|
return;
|
|
}
|
|
mouse_motion_callback = callback;
|
|
}
|
|
|
|
void process_inputs(){
|
|
int count, index;
|
|
device_event *events, current;
|
|
|
|
count = device_handler_poll_events(&events);
|
|
|
|
if( count){
|
|
printf("glut will dispatch %d events\n", count);
|
|
}
|
|
for( index = 0; index < count; index++){
|
|
current = events[index];
|
|
dispatch_input_event(current);
|
|
}
|
|
|
|
device_handler_destroy_events(events);
|
|
process_key_events();
|
|
process_cursor_events();
|
|
}
|
|
|
|
static void process_cursor_events(){
|
|
}
|
|
|
|
static void process_key_events(){
|
|
int index, remapped_index;
|
|
char key_ascii_code;
|
|
|
|
for( index = 0; index < KEY_CNT; index++){
|
|
if( buffered_keys[index]){
|
|
remapped_index = index;
|
|
/*
|
|
printf("this key counts as pressed! %x\n", index);
|
|
*/
|
|
/* could add here the selection between classic GLUT and custom keymap */
|
|
/* for now bad case MAPPING */
|
|
if(
|
|
( remapped_index >= BTN_GAMEPAD && remapped_index <= BTN_THUMBR)
|
|
||
|
|
( remapped_index >= BTN_DPAD_UP && remapped_index <= BTN_DPAD_RIGHT)
|
|
){
|
|
printf("should remap\n");
|
|
remapped_index = remap_joypad_to_keyboard( remapped_index);
|
|
}
|
|
|
|
key_ascii_code = get_ascii_code(remapped_index);
|
|
|
|
/*
|
|
printf("going to keyCB %d\n", key_ascii_code);
|
|
*/
|
|
|
|
/* NULL character would be zero */
|
|
if( 0 < key_ascii_code){
|
|
keyboard_callback( key_ascii_code, 0, 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
unsigned short remap_joypad_to_keyboard( unsigned short linux_key){
|
|
switch( linux_key){
|
|
case BTN_DPAD_DOWN:
|
|
/* return KEY_DOWN; */
|
|
return KEY_S;
|
|
case BTN_DPAD_UP:
|
|
/* return KEY_UP; */
|
|
return KEY_W;
|
|
case BTN_DPAD_LEFT:
|
|
return KEY_A;
|
|
/* return KEY_LEFT; */
|
|
case BTN_DPAD_RIGHT:
|
|
return KEY_D;
|
|
/* return KEY_RIGHT; */
|
|
|
|
case BTN_NORTH:
|
|
return KEY_0;
|
|
case BTN_WEST:
|
|
return KEY_1;
|
|
case BTN_SOUTH:
|
|
return KEY_2;
|
|
case BTN_EAST:
|
|
return KEY_3;
|
|
|
|
case BTN_TL:
|
|
return KEY_4;
|
|
case BTN_TL2:
|
|
return KEY_5;
|
|
case BTN_TR2:
|
|
return KEY_6;
|
|
case BTN_TR:
|
|
return KEY_7;
|
|
|
|
case BTN_START:
|
|
return KEY_SPACE;
|
|
case BTN_SELECT:
|
|
return KEY_ESC;
|
|
/*
|
|
case BTN_THUMBL:
|
|
case BTN_THUMBR:
|
|
*/
|
|
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|