2010-07-03 08:04:10 +00:00
|
|
|
#ifndef _CIFACE_DINPUT_JOYSTICK_H_
|
|
|
|
#define _CIFACE_DINPUT_JOYSTICK_H_
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2013-06-17 00:07:10 +00:00
|
|
|
#include "../Device.h"
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
#define DIRECTINPUT_VERSION 0x0800
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#define NOMINMAX
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <dinput.h>
|
|
|
|
|
2011-03-15 04:04:27 +00:00
|
|
|
#include <list>
|
|
|
|
|
2010-04-02 02:48:24 +00:00
|
|
|
namespace ciface
|
|
|
|
{
|
2010-07-03 08:04:10 +00:00
|
|
|
namespace DInput
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
|
|
|
|
2013-06-17 00:07:10 +00:00
|
|
|
void InitJoystick(IDirectInput8* const idi8, std::vector<Core::Device*>& devices, HWND hwnd);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2013-06-17 00:07:10 +00:00
|
|
|
class Joystick : public Core::Device
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2011-03-14 01:20:11 +00:00
|
|
|
private:
|
2010-04-02 02:48:24 +00:00
|
|
|
struct EffectState
|
|
|
|
{
|
2010-09-16 05:09:29 +00:00
|
|
|
EffectState(LPDIRECTINPUTEFFECT eff) : iface(eff), params(NULL), size(0) {}
|
|
|
|
|
|
|
|
LPDIRECTINPUTEFFECT iface;
|
|
|
|
void* params; // null when force hasn't changed
|
|
|
|
u8 size; // zero when force should stop
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Button : public Input
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string GetName() const;
|
2011-03-14 01:20:11 +00:00
|
|
|
Button(u8 index, const BYTE& button) : m_index(index), m_button(button) {}
|
|
|
|
ControlState GetState() const;
|
2010-04-02 02:48:24 +00:00
|
|
|
private:
|
2011-03-14 01:20:11 +00:00
|
|
|
const BYTE& m_button;
|
|
|
|
const u8 m_index;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Axis : public Input
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string GetName() const;
|
2011-03-14 01:20:11 +00:00
|
|
|
Axis(u8 index, const LONG& axis, LONG base, LONG range) : m_index(index), m_axis(axis), m_base(base), m_range(range) {}
|
|
|
|
ControlState GetState() const;
|
2010-04-02 02:48:24 +00:00
|
|
|
private:
|
2011-03-14 01:20:11 +00:00
|
|
|
const LONG& m_axis;
|
|
|
|
const LONG m_base, m_range;
|
|
|
|
const u8 m_index;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Hat : public Input
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string GetName() const;
|
2011-03-14 01:20:11 +00:00
|
|
|
Hat(u8 index, const DWORD& hat, u8 direction) : m_index(index), m_hat(hat), m_direction(direction) {}
|
|
|
|
ControlState GetState() const;
|
2010-04-02 02:48:24 +00:00
|
|
|
private:
|
2011-03-14 01:20:11 +00:00
|
|
|
const DWORD& m_hat;
|
|
|
|
const u8 m_index, m_direction;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
|
2010-09-16 05:09:29 +00:00
|
|
|
template <typename P>
|
2010-04-02 02:48:24 +00:00
|
|
|
class Force : public Output
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string GetName() const;
|
2011-03-14 01:20:11 +00:00
|
|
|
Force(u8 index, EffectState& state);
|
|
|
|
void SetState(ControlState state);
|
2010-04-02 02:48:24 +00:00
|
|
|
private:
|
2011-03-14 01:20:11 +00:00
|
|
|
EffectState& m_state;
|
|
|
|
P params;
|
|
|
|
const u8 m_index;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
2010-09-16 05:09:29 +00:00
|
|
|
typedef Force<DICONSTANTFORCE> ForceConstant;
|
|
|
|
typedef Force<DIRAMPFORCE> ForceRamp;
|
|
|
|
typedef Force<DIPERIODIC> ForcePeriodic;
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-03-14 01:20:11 +00:00
|
|
|
public:
|
2010-04-02 02:48:24 +00:00
|
|
|
bool UpdateInput();
|
|
|
|
bool UpdateOutput();
|
|
|
|
|
|
|
|
void ClearInputState();
|
|
|
|
|
2011-03-14 01:20:11 +00:00
|
|
|
Joystick(const LPDIRECTINPUTDEVICE8 device, const unsigned int index);
|
2010-04-02 02:48:24 +00:00
|
|
|
~Joystick();
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2010-04-02 02:48:24 +00:00
|
|
|
std::string GetName() const;
|
|
|
|
int GetId() const;
|
|
|
|
std::string GetSource() const;
|
|
|
|
|
|
|
|
private:
|
2010-09-02 00:03:25 +00:00
|
|
|
const LPDIRECTINPUTDEVICE8 m_device;
|
|
|
|
const unsigned int m_index;
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-03-15 04:04:27 +00:00
|
|
|
DIJOYSTATE m_state_in;
|
|
|
|
std::list<EffectState> m_state_out;
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2011-03-15 04:04:27 +00:00
|
|
|
bool m_buffered;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|