void UIScreen::primary_timer_func() { if (use_joystick_as_mouse) { if (Framework::joystick) { float sensitivity = 8.0; ALLEGRO_MOUSE_STATE mouse_state; al_get_mouse_state(&mouse_state); ALLEGRO_JOYSTICK_STATE joystick_state; al_get_joystick_state(Framework::joystick, &joystick_state); // TODO: // right now the joystick axis to use for the mouse emulation is static, // this should be fixed so that an axis might be chosen by the user // and/or multiple joysticks could also be used if (joystick_state.stick[0].axis[0] != 0.0 || joystick_state.stick[0].axis[1] != 0.0) { al_set_mouse_xy(display->al_display, mouse_state.x + joystick_state.stick[0].axis[0]*sensitivity, mouse_state.y + joystick_state.stick[0].axis[1]*sensitivity); } } } // call the parent's usual functions UIWidget::primary_timer_func(); UIWidget::draw_func(); on_draw_after_children(); }
static void setup_joystick_values(ALLEGRO_JOYSTICK *joy) { ALLEGRO_JOYSTICK_STATE jst; int i, j; if (joy == NULL) { num_sticks = 0; num_buttons = 0; return; } al_get_joystick_state(joy, &jst); num_sticks = al_get_joystick_num_sticks(joy); if (num_sticks > MAX_STICKS) num_sticks = MAX_STICKS; for (i = 0; i < num_sticks; i++) { num_axes[i] = al_get_joystick_num_axes(joy, i); for (j = 0; j < num_axes[i]; ++j) joys[i][j] = jst.stick[i].axis[j]; } num_buttons = al_get_joystick_num_buttons(joy); if (num_buttons > MAX_BUTTONS) { num_buttons = MAX_BUTTONS; } for (i = 0; i < num_buttons; i++) { joys_buttons[i] = (jst.button[i] >= 16384); } }
static void draw(ALLEGRO_JOYSTICK *curr_joy) { int x = 100; int y = 100; ALLEGRO_JOYSTICK_STATE joystate; int i; al_clear_to_color(al_map_rgb(0, 0, 0)); if (curr_joy) { al_get_joystick_state(curr_joy, &joystate); for (i = 0; i < al_get_joystick_num_sticks(curr_joy); i++) { al_draw_filled_circle( x+joystate.stick[i].axis[0]*20 + i * 80, y+joystate.stick[i].axis[1]*20, 20, al_map_rgb(255, 255, 255) ); } for (i = 0; i < al_get_joystick_num_buttons(curr_joy); i++) { if (joystate.button[i]) { al_draw_filled_circle( i*20+10, 400, 9, al_map_rgb(255, 255, 255) ); } } } al_flip_display(); }
/** Reads the given joystick's state. @param stick joystick. */ void retrieve(const Joystick &stick) { al_get_joystick_state(stick.get(), &get()); }