Added SDL2 optional checks to CMake + barebones SDL2 input
This commit is contained in:
@@ -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})
|
||||
|
||||
46
src/input_common/sdl_input/sdl_input.cpp
Normal file
46
src/input_common/sdl_input/sdl_input.cpp
Normal 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
|
||||
43
src/input_common/sdl_input/sdl_input.h
Normal file
43
src/input_common/sdl_input/sdl_input.h
Normal 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user