2014-02-10 11:54:46 -07:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// 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>
|
|
|
|
|
2010-07-25 23:30:50 -06:00
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/Common.h"
|
|
|
|
#include "Common/Thread.h"
|
|
|
|
#include "InputCommon/ControllerInterface/ExpressionParser.h"
|
|
|
|
#include "InputCommon/ControllerInterface/Device.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-04-01 20:48:24 -06:00
|
|
|
#define CIFACE_USE_SDL
|
2010-07-16 13:17:35 -06:00
|
|
|
#endif
|
|
|
|
#if defined(HAVE_X11) && HAVE_X11
|
|
|
|
#define CIFACE_USE_XLIB
|
|
|
|
#define CIFACE_USE_SDL
|
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
|
2013-04-14 22:02:53 -06:00
|
|
|
#ifdef ANDROID
|
|
|
|
#define CIFACE_USE_ANDROID
|
|
|
|
#endif
|
2013-06-16 18:07:10 -06:00
|
|
|
|
|
|
|
using namespace ciface::Core;
|
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
|
|
|
//
|
2013-06-16 18:07:10 -06:00
|
|
|
class ControllerInterface : public 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;
|
|
|
|
virtual Device::Control* Detect(const unsigned int ms, 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:
|
|
|
|
ControlReference(const bool _is_input) : range(1), is_input(_is_input), parsed_expression(NULL) {}
|
|
|
|
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) {}
|
|
|
|
ControlState State(const ControlState state);
|
|
|
|
Device::Control* Detect(const unsigned int ms, Device* const device);
|
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) {}
|
|
|
|
ControlState State(const ControlState state);
|
|
|
|
Device::Control* Detect(const unsigned int ms, Device* const device);
|
2010-04-01 20:48:24 -06:00
|
|
|
};
|
|
|
|
|
2010-07-10 00:48:24 -06:00
|
|
|
ControllerInterface() : m_is_init(false), m_hwnd(NULL) {}
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2010-06-20 21:12:16 -06:00
|
|
|
void SetHwnd(void* const hwnd);
|
2010-10-12 13:42:29 -06:00
|
|
|
void Initialize();
|
|
|
|
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
|
|
|
|
2010-06-20 21:12:16 -06:00
|
|
|
void UpdateReference(ControlReference* control, const DeviceQualifier& default_device) const;
|
2010-07-25 23:30:50 -06:00
|
|
|
bool UpdateInput(const bool force = false);
|
|
|
|
bool UpdateOutput(const bool force = false);
|
2010-04-01 20:48:24 -06:00
|
|
|
|
2011-03-06 17:16:38 -07:00
|
|
|
std::recursive_mutex update_lock;
|
2010-07-25 23:30:50 -06:00
|
|
|
|
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;
|