Added SDL2 optional checks to CMake + barebones SDL2 input

This commit is contained in:
Daniel Stuart Baxter
2015-05-24 00:37:30 -05:00
parent 82b9dff712
commit f1039f8b05
5 changed files with 281 additions and 1 deletions

View File

@@ -1,3 +1,7 @@
set(SRCS input_common.cpp)
set(SRCS input_common.cpp)
if(SDL2_FOUND)
set(SRCS sdl_input/sdl_input.cpp)
endif()
add_library(input_common STATIC ${SRCS})

View File

@@ -0,0 +1,46 @@
// Copyright 2015 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "input_common/sdl_input/sdl_input.h"
namespace InputCommon {
SDLController::SDLController() {
name = "SDL2::NONE";
j_pad = nullptr;
index = 0;
}
SDLController::~SDLController() {
ShutDown();
}
bool SDLController::Init() {
//Attempt to initialize SDL with joystick only
if(SDL_Init(SDL_INIT_JOYSTICK) != 0) {
return false;
}
//Attempt to open joystick with SDL
//TODO - Use DiscoverDevice to generate a list of available joysticks, then open the correct index
j_pad = SDL_JoystickOpen(index);
if(j_pad == nullptr) {
return false;
}
}
void SDLController::DiscoverDevices() {}
void SDLController::ShutDown() {
//Attempt to close joystick with SDL
if(j_pad != nullptr) {
SDL_JoystickClose(j_pad);
}
}
void SDLController::Poll() {}
}//namespace

View File

@@ -0,0 +1,43 @@
// Copyright 2015 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <SDL2/SDL.h>
#include <iostream>
#include "input_common/input_common.h"
namespace InputCommon {
class SDLController : virtual public ControllerBase {
public:
SDLController();
~SDLController();
///Initializes input via SDL2
bool Init();
///Grabs a list of devices supported by the backend
void DiscoverDevices();
///Grab and process input via SDL2
void Poll();
///Shuts down all joysticks opened by SDL2
void ShutDown();
///SDL event used for polling
SDL_Event input_event;
private:
std::string name;
SDL_Joystick* j_pad;
///Index of joystick, used for opening/closing a joystick
int index;
};
} //namespace