/* Copyright 2020-2021 Brad Parker Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include "core.h" #include "../common/input.h" void Core::inputPoll() { } // The core is asking the frontend for the state of a specific button for a specific player. // Actually the core is constantly asking for the state of all the buttons it cares about by calling this function for every button on every frame. int16_t Core::inputState(unsigned port, unsigned device, unsigned index, unsigned id) { // we only support player 1 (port 0) for now if(port != 0) return 0; // core is asking for state of a joypad button, this is basically anything on a gamepad that's not analog (face buttons, d-pad directions, digital triggers like L/R etc.) if(device == RETRO_DEVICE_JOYPAD && index == 0) { if(id <= RETRO_DEVICE_ID_JOYPAD_R3) { return InputState::instance()->getInputState(id); } // core is asking for the state of analog axes (left analog, right analog) // libretro API also supports analog *buttons* (or triggers), but we don't }else if(device == RETRO_DEVICE_ANALOG && index == 0) { // we don't support the right analog for now if(index == RETRO_DEVICE_INDEX_ANALOG_LEFT) { if(id == RETRO_DEVICE_ID_ANALOG_X) { return InputState::instance()->getAnalogInputState(RETRO_DEVICE_ID_ANALOG_X); }else if(id == RETRO_DEVICE_ID_ANALOG_Y) { return InputState::instance()->getAnalogInputState(RETRO_DEVICE_ID_ANALOG_Y); } } // core is asking for the state of a mouse pointer (if it supports one) }else if(device == RETRO_DEVICE_MOUSE && index == 0) { switch(id) { case RETRO_DEVICE_ID_MOUSE_X: return InputState::instance()->getMousePosRelX(); case RETRO_DEVICE_ID_MOUSE_Y: return InputState::instance()->getMousePosRelY(); case RETRO_DEVICE_ID_MOUSE_LEFT: return InputState::instance()->getMouseButtonsState() & Qt::LeftButton; case RETRO_DEVICE_ID_MOUSE_RIGHT: return InputState::instance()->getMouseButtonsState() & Qt::RightButton; default: break; } } return 0; }