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 <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
#include <map>
|
|
|
|
#include <algorithm>
|
2010-07-26 05:30:50 +00:00
|
|
|
|
2010-04-10 20:44:56 +00:00
|
|
|
#include "Common.h"
|
2010-07-26 05:30:50 +00:00
|
|
|
#include "Thread.h"
|
2013-06-14 03:09:55 +00:00
|
|
|
#include "ExpressionParser.h"
|
2013-06-17 00:07:10 +00:00
|
|
|
#include "Device.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-04-02 02:48:24 +00:00
|
|
|
#define CIFACE_USE_SDL
|
2010-07-16 19:17:35 +00:00
|
|
|
#endif
|
|
|
|
#if defined(HAVE_X11) && HAVE_X11
|
|
|
|
#define CIFACE_USE_XLIB
|
|
|
|
#define CIFACE_USE_SDL
|
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
|
2013-06-17 00:07:10 +00:00
|
|
|
|
|
|
|
using namespace ciface::Core;
|
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
|
|
|
//
|
2013-06-17 00:07:10 +00:00
|
|
|
class ControllerInterface : public 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;
|
|
|
|
virtual Device::Control* Detect(const unsigned int ms, 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:
|
|
|
|
ControlReference(const bool _is_input) : range(1), is_input(_is_input), parsed_expression(NULL) {}
|
|
|
|
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) {}
|
|
|
|
ControlState State(const ControlState state);
|
|
|
|
Device::Control* Detect(const unsigned int ms, Device* const device);
|
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) {}
|
|
|
|
ControlState State(const ControlState state);
|
|
|
|
Device::Control* Detect(const unsigned int ms, Device* const device);
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
|
2010-07-10 06:48:24 +00:00
|
|
|
ControllerInterface() : m_is_init(false), m_hwnd(NULL) {}
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
void SetHwnd(void* const hwnd);
|
2010-10-12 19:42:29 +00:00
|
|
|
void Initialize();
|
|
|
|
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
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
void UpdateReference(ControlReference* control, const DeviceQualifier& default_device) const;
|
2010-07-26 05:30:50 +00:00
|
|
|
bool UpdateInput(const bool force = false);
|
|
|
|
bool UpdateOutput(const bool force = false);
|
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;
|