/* $Id: mouse.c,v 1.1.1.1 2006/03/17 19:53:41 zicodxx Exp $ */ /* * * SDL mouse driver. * */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include "fix.h" #include "timer.h" #include "event.h" #include "mouse.h" #ifdef _WIN32_WCE # define LANDSCAPE #endif #define MOUSE_MAX_BUTTONS 8 #define Z_SENSITIVITY 100 struct mousebutton { ubyte pressed; fix time_went_down; fix time_held_down; uint num_downs; uint num_ups; }; static struct mouseinfo { struct mousebutton buttons[MOUSE_MAX_BUTTONS]; int delta_x, delta_y, delta_z; int x,y,z; } Mouse; void d_mouse_init(void) { memset(&Mouse,0,sizeof(Mouse)); } void mouse_button_handler(SDL_MouseButtonEvent *mbe) { // to bad, SDL buttons use a different mapping as descent expects, // this is at least true and tested for the first three buttons int button_remap[11] = { MB_LEFT, MB_MIDDLE, MB_RIGHT, MB_Z_UP, MB_Z_DOWN, MB_PITCH_BACKWARD, MB_PITCH_FORWARD, MB_BANK_LEFT, MB_BANK_RIGHT, MB_HEAD_LEFT, MB_HEAD_RIGHT }; int button = button_remap[mbe->button - 1]; // -1 since SDL seems to start counting at 1 if (mbe->state == SDL_PRESSED) { Mouse.buttons[button].pressed = 1; Mouse.buttons[button].time_went_down = timer_get_fixed_seconds(); Mouse.buttons[button].num_downs++; if (button == MB_Z_UP) { Mouse.delta_z += Z_SENSITIVITY; Mouse.z += Z_SENSITIVITY; } else if (button == MB_Z_DOWN) { Mouse.delta_z -= Z_SENSITIVITY; Mouse.z -= Z_SENSITIVITY; } } else { Mouse.buttons[button].pressed = 0; Mouse.buttons[button].time_held_down += timer_get_fixed_seconds() - Mouse.buttons[button].time_went_down; Mouse.buttons[button].num_ups++; } } void mouse_motion_handler(SDL_MouseMotionEvent *mme) { #ifdef LANDSCAPE Mouse.delta_y += mme->xrel; Mouse.delta_x += mme->yrel; Mouse.y += mme->xrel; Mouse.x += mme->yrel; #else Mouse.delta_x += mme->xrel; Mouse.delta_y += mme->yrel; Mouse.x += mme->xrel; Mouse.y += mme->yrel; #endif } void mouse_flush() // clears all mice events... { int i; fix current_time; event_poll(); current_time = timer_get_fixed_seconds(); for (i=0; i