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