2014-02-10 18:54:46 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
2014-02-17 10:18:15 +00:00
|
|
|
#include <map>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/Thread.h"
|
|
|
|
#include "InputCommon/ControllerInterface/Device.h"
|
2014-02-19 01:17:31 +00:00
|
|
|
#include "InputCommon/ControllerInterface/ExpressionParser.h"
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
// enable disable sources
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define CIFACE_USE_XINPUT
|
2010-07-03 08:04:10 +00:00
|
|
|
#define CIFACE_USE_DINPUT
|
2010-07-16 19:17:35 +00:00
|
|
|
#endif
|
|
|
|
#if defined(HAVE_X11) && HAVE_X11
|
|
|
|
#define CIFACE_USE_XLIB
|
2013-07-10 06:49:58 +00:00
|
|
|
#if defined(HAVE_X11_XINPUT2) && HAVE_X11_XINPUT2
|
|
|
|
#define CIFACE_USE_X11_XINPUT2
|
|
|
|
#endif
|
2010-07-16 19:17:35 +00:00
|
|
|
#endif
|
2010-04-02 09:41:43 +00:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
#define CIFACE_USE_OSX
|
|
|
|
#endif
|
2013-04-15 04:02:53 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
#define CIFACE_USE_ANDROID
|
|
|
|
#endif
|
2014-05-05 00:41:02 +00:00
|
|
|
#if defined(HAVE_SDL) && HAVE_SDL
|
|
|
|
#define CIFACE_USE_SDL
|
|
|
|
#endif
|
2013-06-17 00:07:10 +00:00
|
|
|
|
2010-04-02 02:48:24 +00:00
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// ControllerInterface
|
2010-04-02 02:48:24 +00:00
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// Some crazy shit I made to control different device inputs and outputs
|
|
|
|
// from lots of different sources, hopefully more easily.
|
2010-04-02 02:48:24 +00:00
|
|
|
//
|
2014-09-05 00:41:42 +00:00
|
|
|
class ControllerInterface : public ciface::Core::DeviceContainer
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// ControlReference
|
2010-04-02 02:48:24 +00:00
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// These are what you create to actually use the inputs, InputReference or OutputReference.
|
2010-04-02 02:48:24 +00:00
|
|
|
//
|
2014-01-31 00:51:21 +00: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
|
2010-04-02 02:48:24 +00:00
|
|
|
//
|
|
|
|
class ControlReference
|
|
|
|
{
|
2010-06-21 03:12:16 +00:00
|
|
|
friend class ControllerInterface;
|
2010-04-02 02:48:24 +00:00
|
|
|
public:
|
2010-06-21 03:12:16 +00:00
|
|
|
virtual ControlState State(const ControlState state = 0) = 0;
|
2014-09-05 00:41:42 +00:00
|
|
|
virtual ciface::Core::Device::Control* Detect(const unsigned int ms, ciface::Core::Device* const device) = 0;
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2013-06-14 03:09:55 +00:00
|
|
|
ControlState range;
|
2014-01-31 00:51:21 +00:00
|
|
|
std::string expression;
|
|
|
|
const bool is_input;
|
2013-07-22 06:36:26 +00:00
|
|
|
ciface::ExpressionParser::ExpressionParseStatus parse_error;
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-01-31 00:51:21 +00:00
|
|
|
virtual ~ControlReference()
|
|
|
|
{
|
2013-06-14 03:09:55 +00:00
|
|
|
delete parsed_expression;
|
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-01-31 00:51:21 +00:00
|
|
|
int BoundCount()
|
|
|
|
{
|
2013-06-14 03:09:55 +00:00
|
|
|
if (parsed_expression)
|
|
|
|
return parsed_expression->num_controls;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2013-06-14 03:09:55 +00:00
|
|
|
protected:
|
2014-03-09 20:14:26 +00:00
|
|
|
ControlReference(const bool _is_input) : range(1), is_input(_is_input), parsed_expression(nullptr) {}
|
2013-06-14 03:09:55 +00:00
|
|
|
ciface::ExpressionParser::Expression *parsed_expression;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// InputReference
|
2010-04-02 02:48:24 +00:00
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// Control reference for inputs
|
2010-04-02 02:48:24 +00:00
|
|
|
//
|
|
|
|
class InputReference : public ControlReference
|
|
|
|
{
|
|
|
|
public:
|
2010-06-21 03:12:16 +00:00
|
|
|
InputReference() : ControlReference(true) {}
|
2014-03-08 00:54:44 +00:00
|
|
|
ControlState State(const ControlState state) override;
|
2014-09-05 00:41:42 +00:00
|
|
|
ciface::Core::Device::Control* Detect(const unsigned int ms, ciface::Core::Device* const device) override;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// OutputReference
|
2010-04-02 02:48:24 +00:00
|
|
|
//
|
2014-01-31 00:51:21 +00:00
|
|
|
// Control reference for outputs
|
2010-04-02 02:48:24 +00:00
|
|
|
//
|
|
|
|
class OutputReference : public ControlReference
|
|
|
|
{
|
|
|
|
public:
|
2010-06-21 03:12:16 +00:00
|
|
|
OutputReference() : ControlReference(false) {}
|
2014-03-08 00:54:44 +00:00
|
|
|
ControlState State(const ControlState state) override;
|
2014-09-05 00:41:42 +00:00
|
|
|
ciface::Core::Device::Control* Detect(const unsigned int ms, ciface::Core::Device* const device) override;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
|
2014-03-09 20:14:26 +00:00
|
|
|
ControllerInterface() : m_is_init(false), m_hwnd(nullptr) {}
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2014-10-13 16:45:47 +00:00
|
|
|
void Initialize(void* const hwnd);
|
|
|
|
void Reinitialize();
|
2010-10-12 19:42:29 +00:00
|
|
|
void Shutdown();
|
2010-06-21 03:12:16 +00:00
|
|
|
bool IsInit() const { return m_is_init; }
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2014-09-05 00:41:42 +00:00
|
|
|
void UpdateReference(ControlReference* control, const ciface::Core::DeviceQualifier& default_device) const;
|
2014-11-13 08:55:14 +00:00
|
|
|
void UpdateInput();
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-03-07 00:16:38 +00:00
|
|
|
std::recursive_mutex update_lock;
|
2010-07-26 05:30:50 +00:00
|
|
|
|
2010-04-02 02:48:24 +00:00
|
|
|
private:
|
2014-01-31 00:51:21 +00:00
|
|
|
bool m_is_init;
|
|
|
|
void* m_hwnd;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
|
2010-10-12 19:42:29 +00:00
|
|
|
extern ControllerInterface g_controller_interface;
|