2010-04-02 02:48:24 +00:00
|
|
|
#ifndef _DEVICEINTERFACE_H_
|
|
|
|
#define _DEVICEINTERFACE_H_
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
#include <map>
|
|
|
|
#include <algorithm>
|
2010-04-10 20:44:56 +00:00
|
|
|
#include "Common.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_JOYSTICK
|
|
|
|
#define CIFACE_USE_DINPUT_KBM
|
|
|
|
#define CIFACE_USE_DINPUT
|
2010-04-02 02:48:24 +00:00
|
|
|
#endif
|
|
|
|
#if defined(HAVE_X11) && HAVE_X11
|
|
|
|
#define CIFACE_USE_XLIB
|
|
|
|
#endif
|
2010-06-05 05:30:23 +00:00
|
|
|
//#ifndef CIFACE_USE_DIRECTINPUT_JOYSTICK
|
|
|
|
// enable SDL 1.2 in addition to DirectInput on windows,
|
|
|
|
// to support a few gamepads that aren't behaving with DInput
|
2010-04-02 02:48:24 +00:00
|
|
|
#define CIFACE_USE_SDL
|
2010-06-05 05:30:23 +00:00
|
|
|
//#endif
|
2010-04-02 09:41:43 +00:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
#define CIFACE_USE_OSX
|
|
|
|
#endif
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
// idk in case i wanted to change it to double or somethin, idk what's best
|
|
|
|
typedef float ControlState;
|
|
|
|
|
|
|
|
//
|
|
|
|
// ControllerInterface
|
|
|
|
//
|
|
|
|
// some crazy shit i made to control different device inputs and outputs
|
|
|
|
// from lots of different sources, hopefully more easily
|
|
|
|
//
|
|
|
|
class ControllerInterface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2010-06-21 18:25:49 +00:00
|
|
|
// Forward declarations
|
|
|
|
class DeviceQualifier;
|
|
|
|
|
2010-04-02 02:48:24 +00:00
|
|
|
//
|
|
|
|
// Device
|
|
|
|
//
|
2010-06-21 03:12:16 +00:00
|
|
|
// a device class
|
2010-04-02 02:48:24 +00:00
|
|
|
//
|
|
|
|
class Device
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
//
|
|
|
|
// Control
|
|
|
|
//
|
|
|
|
// control includes inputs and outputs
|
|
|
|
//
|
|
|
|
class Control // input or output
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual std::string GetName() const = 0;
|
2010-04-24 00:44:10 +00:00
|
|
|
virtual ~Control() {}
|
2010-06-22 08:30:33 +00:00
|
|
|
bool operator==(const std::string& name) const;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// Input
|
|
|
|
//
|
|
|
|
// an input on a device
|
|
|
|
//
|
|
|
|
class Input : public Control
|
|
|
|
{
|
|
|
|
public:
|
2010-06-21 03:12:16 +00:00
|
|
|
// things like absolute axes/ absolute mouse position will override this
|
|
|
|
virtual bool IsDetectable() { return true; }
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// Output
|
|
|
|
//
|
2010-04-29 18:51:04 +00:00
|
|
|
// an output on a device
|
2010-04-02 02:48:24 +00:00
|
|
|
//
|
|
|
|
class Output : public Control
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~Output() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual ~Device();
|
|
|
|
|
|
|
|
virtual std::string GetName() const = 0;
|
|
|
|
virtual int GetId() const = 0;
|
|
|
|
virtual std::string GetSource() const = 0;
|
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
virtual ControlState GetInputState( const Input* const input ) const = 0;
|
2010-04-02 02:48:24 +00:00
|
|
|
virtual void SetOutputState( const Output* const output, const ControlState state ) = 0;
|
|
|
|
|
|
|
|
virtual bool UpdateInput() = 0;
|
|
|
|
virtual bool UpdateOutput() = 0;
|
|
|
|
|
|
|
|
virtual void ClearInputState();
|
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
const std::vector<Input*>& Inputs() const { return m_inputs; }
|
|
|
|
const std::vector<Output*>& Outputs() const { return m_outputs; }
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
protected:
|
2010-06-21 03:12:16 +00:00
|
|
|
void AddInput(Input* const i);
|
|
|
|
void AddOutput(Output* const o);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<Input*> m_inputs;
|
|
|
|
std::vector<Output*> m_outputs;
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// DeviceQualifier
|
|
|
|
//
|
|
|
|
// device qualifier used to match devices
|
|
|
|
// currently has ( source, id, name ) properties which match a device
|
|
|
|
//
|
|
|
|
class DeviceQualifier
|
|
|
|
{
|
|
|
|
public:
|
2010-06-21 03:12:16 +00:00
|
|
|
DeviceQualifier() : cid(-1) {}
|
|
|
|
DeviceQualifier(const std::string& _source, const int _id, const std::string& _name)
|
2010-04-02 09:41:43 +00:00
|
|
|
: source(_source), cid(_id), name(_name) {}
|
2010-04-02 02:48:24 +00:00
|
|
|
void FromDevice(const Device* const dev);
|
|
|
|
void FromString(const std::string& str);
|
|
|
|
std::string ToString() const;
|
2010-06-21 03:12:16 +00:00
|
|
|
bool operator==(const DeviceQualifier& devq) const;
|
2010-06-22 08:30:33 +00:00
|
|
|
bool operator==(const Device* const dev) const;
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
std::string source;
|
2010-04-02 09:41:43 +00:00
|
|
|
int cid;
|
2010-04-02 02:48:24 +00:00
|
|
|
std::string name;
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// ControlReference
|
|
|
|
//
|
|
|
|
// these are what you create to actually use the inputs, InputReference or OutputReference
|
|
|
|
//
|
|
|
|
// after being binded to devices and controls with ControllerInterface::UpdateReference,
|
2010-06-21 03:12:16 +00:00
|
|
|
// 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-04-24 00:44:10 +00:00
|
|
|
virtual ~ControlReference() {}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
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;
|
|
|
|
size_t BoundCount() const { return m_controls.size(); }
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
ControlState range;
|
2010-06-21 03:12:16 +00:00
|
|
|
std::string expression;
|
|
|
|
const bool is_input;
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
protected:
|
|
|
|
ControlReference(const bool _is_input) : range(1), is_input(_is_input) {}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
struct DeviceControl
|
|
|
|
{
|
|
|
|
DeviceControl() : device(NULL), control(NULL), mode(0) {}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
Device* device;
|
|
|
|
Device::Control* control;
|
|
|
|
int mode;
|
|
|
|
};
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
std::vector<DeviceControl> m_controls;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// InputReference
|
|
|
|
//
|
|
|
|
// control reference for inputs
|
|
|
|
//
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// OutputReference
|
|
|
|
//
|
|
|
|
// control reference for outputs
|
|
|
|
//
|
|
|
|
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) {}
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2010-06-21 03:12:16 +00:00
|
|
|
void SetHwnd(void* const hwnd);
|
2010-04-02 02:48:24 +00:00
|
|
|
void Init();
|
2010-06-06 03:52:11 +00:00
|
|
|
// TODO: remove this hack param
|
|
|
|
void DeInit(const bool hacks_no_sdl_quit = false);
|
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-04-02 02:48:24 +00:00
|
|
|
bool UpdateInput();
|
|
|
|
bool UpdateOutput();
|
|
|
|
|
2010-06-22 08:30:33 +00:00
|
|
|
const std::vector<Device*>& Devices() const { return m_devices; }
|
|
|
|
Device* FindDevice(const DeviceQualifier& devq) const;
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_is_init;
|
|
|
|
std::vector<Device*> m_devices;
|
|
|
|
void* m_hwnd;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|