void process_event(RAWINPUT &rawinput) override { // If this data was intended for a rawinput lightgun if (rawinput.data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE) { // update the X/Y positions lightgun.lX = normalize_absolute_axis(rawinput.data.mouse.lLastX, 0, INPUT_ABSOLUTE_MAX); lightgun.lY = normalize_absolute_axis(rawinput.data.mouse.lLastY, 0, INPUT_ABSOLUTE_MAX); // update zaxis if (rawinput.data.mouse.usButtonFlags & RI_MOUSE_WHEEL) lightgun.lZ += static_cast<int16_t>(rawinput.data.mouse.usButtonData) * INPUT_RELATIVE_PER_PIXEL; // update the button states; always update the corresponding mouse buttons if (rawinput.data.mouse.usButtonFlags & RI_MOUSE_BUTTON_1_DOWN) lightgun.rgbButtons[0] = 0x80; if (rawinput.data.mouse.usButtonFlags & RI_MOUSE_BUTTON_1_UP) lightgun.rgbButtons[0] = 0x00; if (rawinput.data.mouse.usButtonFlags & RI_MOUSE_BUTTON_2_DOWN) lightgun.rgbButtons[1] = 0x80; if (rawinput.data.mouse.usButtonFlags & RI_MOUSE_BUTTON_2_UP) lightgun.rgbButtons[1] = 0x00; if (rawinput.data.mouse.usButtonFlags & RI_MOUSE_BUTTON_3_DOWN) lightgun.rgbButtons[2] = 0x80; if (rawinput.data.mouse.usButtonFlags & RI_MOUSE_BUTTON_3_UP) lightgun.rgbButtons[2] = 0x00; if (rawinput.data.mouse.usButtonFlags & RI_MOUSE_BUTTON_4_DOWN) lightgun.rgbButtons[3] = 0x80; if (rawinput.data.mouse.usButtonFlags & RI_MOUSE_BUTTON_4_UP) lightgun.rgbButtons[3] = 0x00; if (rawinput.data.mouse.usButtonFlags & RI_MOUSE_BUTTON_5_DOWN) lightgun.rgbButtons[4] = 0x80; if (rawinput.data.mouse.usButtonFlags & RI_MOUSE_BUTTON_5_UP) lightgun.rgbButtons[4] = 0x00; } }
void poll() override { event_based_device::poll(); INT32 xpos = 0, ypos = 0; POINT mousepos; // if we are using the shared axis hack, the data is updated via Windows messages only if (m_lightgun_shared_axis_mode) return; // get the cursor position and transform into final results GetCursorPos(&mousepos); if (!osd_common_t::s_window_list.empty()) { RECT client_rect; // get the position relative to the window GetClientRect(osd_common_t::s_window_list.front()->platform_window<HWND>(), &client_rect); ScreenToClient(osd_common_t::s_window_list.front()->platform_window<HWND>(), &mousepos); // convert to absolute coordinates xpos = normalize_absolute_axis(mousepos.x, client_rect.left, client_rect.right); ypos = normalize_absolute_axis(mousepos.y, client_rect.top, client_rect.bottom); } // update the X/Y positions mouse.lX = xpos; mouse.lY = ypos; }
void process_event(XEvent &xevent) override { if (xevent.type == motion_type) { XDeviceMotionEvent *motion = (XDeviceMotionEvent *)&xevent; print_motion_event(motion); /* * We have to check with axis will start on array index 0. * We have also to check the number of axes that are stored in the array. */ switch (motion->first_axis) { /* * Starting with x, check number of axis, if there is also the y axis stored. */ case 0: if (motion->axes_count >= 1) { lightgun.lX = normalize_absolute_axis(motion->axis_data[0], x11_state.minx, x11_state.maxx); if (motion->axes_count >= 2) { lightgun.lY = normalize_absolute_axis(motion->axis_data[1], x11_state.miny, x11_state.maxy); } } break; /* * Starting with y, ... */ case 1: if (motion->axes_count >= 1) { lightgun.lY = normalize_absolute_axis(motion->axis_data[0], x11_state.miny, x11_state.maxy); } break; } } else if (xevent.type == button_press_type || xevent.type == button_release_type) { XDeviceButtonEvent *button = (XDeviceButtonEvent *)&xevent; lightgun.buttons[button->button] = (xevent.type == button_press_type) ? 0x80 : 0; } }
void handle_shared_axis_mode(MouseButtonEventArgs &args) { int button = args.button; // We only handle the first four buttons in shared axis mode if (button > 3) return; // First gun doesn't handle buttons 2 & 3 if (button >= 2 && m_gun_index == 0) return; // Second gun doesn't handle buttons 0 & 1 if (button < 2 && m_gun_index == 1) return; // Adjust the button if we're the second lightgun int logical_button = m_gun_index == 1 ? button - 2 : button; // set the button state mouse.rgbButtons[logical_button] = args.keydown ? 0x80 : 0x00; if (args.keydown) { RECT client_rect; POINT mousepos; // get the position relative to the window GetClientRect(osd_common_t::s_window_list.front()->platform_window<HWND>(), &client_rect); mousepos.x = args.xpos; mousepos.y = args.ypos; ScreenToClient(osd_common_t::s_window_list.front()->platform_window<HWND>(), &mousepos); // convert to absolute coordinates mouse.lX = normalize_absolute_axis(mousepos.x, client_rect.left, client_rect.right); mouse.lY = normalize_absolute_axis(mousepos.y, client_rect.top, client_rect.bottom); } }
void xinput_joystick_device::poll() { if (!m_configured) return; // poll the device first HRESULT result = m_xinput_helper->xinput_get_state(xinput_state.player_index, &xinput_state.xstate); // If we can't poll the device, skip if (FAILED(result)) return; // Copy the XState into State // Start with the POV (DPAD) for (int povindex = 0; povindex < XINPUT_MAX_POV; povindex++) { int currentPov = xinput_pov_dir[povindex]; gamepad.povs[povindex] = (xinput_state.xstate.Gamepad.wButtons & currentPov) ? 0xFF : 0; } // Now do the buttons for (int buttonindex = 0; buttonindex < XINPUT_MAX_BUTTONS; buttonindex++) { int currentButton = xinput_buttons[buttonindex]; gamepad.buttons[buttonindex] = (xinput_state.xstate.Gamepad.wButtons & currentButton) ? 0xFF : 0; } // Now grab the axis values // Each of the thumbstick axis members is a signed value between -32768 and 32767 describing the position of the thumbstick // However, the Y axis values are inverted from what MAME expects, so negate the value gamepad.left_thumb_x = normalize_absolute_axis(xinput_state.xstate.Gamepad.sThumbLX, XINPUT_AXIS_MINVALUE, XINPUT_AXIS_MAXVALUE); gamepad.left_thumb_y = normalize_absolute_axis(-xinput_state.xstate.Gamepad.sThumbLY, XINPUT_AXIS_MINVALUE, XINPUT_AXIS_MAXVALUE); gamepad.right_thumb_x = normalize_absolute_axis(xinput_state.xstate.Gamepad.sThumbRX, XINPUT_AXIS_MINVALUE, XINPUT_AXIS_MAXVALUE); gamepad.right_thumb_y = normalize_absolute_axis(-xinput_state.xstate.Gamepad.sThumbRY, XINPUT_AXIS_MINVALUE, XINPUT_AXIS_MAXVALUE); // Now the triggers gamepad.left_trigger = normalize_absolute_axis(xinput_state.xstate.Gamepad.bLeftTrigger, 0, 255); gamepad.right_trigger = normalize_absolute_axis(xinput_state.xstate.Gamepad.bRightTrigger, 0, 255); }