Files
Ishiiruka/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h

131 lines
3.2 KiB
C
Raw Normal View History

2014-06-03 18:14:53 -03:00
// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#pragma once
#include <algorithm>
2014-06-03 18:14:53 -03:00
#include <map>
#include <sstream>
#include <string>
#include <vector>
2014-10-04 12:11:42 -03:00
#include "Common/CommonTypes.h"
#include "Common/Thread.h"
2014-06-03 18:14:53 -03:00
#include "InputCommon/ControllerInterface/Device.h"
#include "InputCommon/ControllerInterface/ExpressionParser.h"
// enable disable sources
#ifdef _WIN32
#define CIFACE_USE_XINPUT
#define CIFACE_USE_DINPUT
#endif
#if defined(HAVE_X11) && HAVE_X11
#define CIFACE_USE_XLIB
#if defined(HAVE_X11_XINPUT2) && HAVE_X11_XINPUT2
#define CIFACE_USE_X11_XINPUT2
#endif
#endif
#if defined(__APPLE__)
#define CIFACE_USE_OSX
#endif
#ifdef ANDROID
#define CIFACE_USE_ANDROID
#endif
2014-06-03 18:14:53 -03:00
#if defined(HAVE_SDL) && HAVE_SDL
#define CIFACE_USE_SDL
#endif
//
2014-06-03 18:14:53 -03:00
// ControllerInterface
//
2014-06-03 18:14:53 -03:00
// Some crazy shit I made to control different device inputs and outputs
// from lots of different sources, hopefully more easily.
//
2014-10-04 12:11:42 -03:00
class ControllerInterface : public ciface::Core::DeviceContainer
{
public:
//
2014-06-03 18:14:53 -03:00
// ControlReference
//
2014-06-03 18:14:53 -03:00
// These are what you create to actually use the inputs, InputReference or OutputReference.
//
2014-06-03 18:14:53 -03:00
// After being bound to devices and controls with ControllerInterface::UpdateReference,
// each one can link to multiple devices and controls
// when you change a ControlReference's expression,
// you must use ControllerInterface::UpdateReference on it to rebind controls
//
class ControlReference
{
friend class ControllerInterface;
public:
virtual ControlState State(const ControlState state = 0) = 0;
2014-10-04 12:11:42 -03:00
virtual ciface::Core::Device::Control* Detect(const unsigned int ms, ciface::Core::Device* const device) = 0;
ControlState range;
2014-06-03 18:14:53 -03:00
std::string expression;
const bool is_input;
ciface::ExpressionParser::ExpressionParseStatus parse_error;
2014-06-03 18:14:53 -03:00
virtual ~ControlReference()
{
delete parsed_expression;
}
2014-06-03 18:14:53 -03:00
int BoundCount()
{
if (parsed_expression)
return parsed_expression->num_controls;
else
return 0;
}
protected:
2014-06-03 18:14:53 -03:00
ControlReference(const bool _is_input) : range(1), is_input(_is_input), parsed_expression(nullptr) {}
ciface::ExpressionParser::Expression *parsed_expression;
};
//
2014-06-03 18:14:53 -03:00
// InputReference
//
2014-06-03 18:14:53 -03:00
// Control reference for inputs
//
class InputReference : public ControlReference
{
public:
InputReference() : ControlReference(true) {}
2014-06-03 18:14:53 -03:00
ControlState State(const ControlState state) override;
2014-10-04 12:11:42 -03:00
ciface::Core::Device::Control* Detect(const unsigned int ms, ciface::Core::Device* const device) override;
};
//
2014-06-03 18:14:53 -03:00
// OutputReference
//
2014-06-03 18:14:53 -03:00
// Control reference for outputs
//
class OutputReference : public ControlReference
{
public:
OutputReference() : ControlReference(false) {}
2014-06-03 18:14:53 -03:00
ControlState State(const ControlState state) override;
2014-10-04 12:11:42 -03:00
ciface::Core::Device::Control* Detect(const unsigned int ms, ciface::Core::Device* const device) override;
};
2014-06-03 18:14:53 -03:00
ControllerInterface() : m_is_init(false), m_hwnd(nullptr) {}
2013-11-09 18:40:00 -03:00
2014-10-26 23:02:05 -03:00
void Initialize(void* const hwnd);
void Reinitialize();
void Shutdown();
bool IsInit() const { return m_is_init; }
2014-10-04 12:11:42 -03:00
void UpdateReference(ControlReference* control, const ciface::Core::DeviceQualifier& default_device) const;
2014-12-09 23:10:45 -03:00
void UpdateInput();
private:
2014-06-03 18:14:53 -03:00
bool m_is_init;
void* m_hwnd;
};
extern ControllerInterface g_controller_interface;