HIDGamepadElement.h [plain text]
#pragma once
#if ENABLE(GAMEPAD) && PLATFORM(MAC)
#include "HIDElement.h"
#include "SharedGamepadValue.h"
#include <wtf/HashMap.h>
#include <wtf/RetainPtr.h>
#include <wtf/UniqueRef.h>
namespace WebCore {
enum class HIDInputType {
ButtonPress,
NotAButtonPress,
};
class HIDGamepadElement : public HIDElement {
WTF_MAKE_FAST_ALLOCATED;
public:
virtual ~HIDGamepadElement() { }
virtual HIDInputType gamepadValueChanged(IOHIDValueRef) = 0;
void refreshCurrentValue();
protected:
HIDGamepadElement(const HIDElement&);
virtual double normalizedValue();
virtual bool isButton() const { return false; }
virtual bool isAxis() const { return false; }
};
class HIDGamepadButton final : public HIDGamepadElement {
public:
HIDGamepadButton(const HIDElement& element, SharedGamepadValue& value)
: HIDGamepadElement(element)
, m_value(value)
{
}
bool isButton() const final { return true; }
private:
HIDInputType gamepadValueChanged(IOHIDValueRef) override;
SharedGamepadValue m_value;
};
class HIDGamepadAxis final : public HIDGamepadElement {
public:
HIDGamepadAxis(const HIDElement& element, SharedGamepadValue& value)
: HIDGamepadElement(element)
, m_value(value)
{
}
bool isAxis() const final { return true; }
private:
HIDInputType gamepadValueChanged(IOHIDValueRef) override;
double normalizedValue() final;
SharedGamepadValue m_value;
};
class HIDGamepadHatswitch : public HIDGamepadElement {
public:
HIDGamepadHatswitch(const HIDElement& element, Vector<SharedGamepadValue>&& buttonValues)
: HIDGamepadElement(element)
, m_buttonValues(WTFMove(buttonValues))
{
}
bool isButton() const final { return true; }
private:
HIDInputType gamepadValueChanged(IOHIDValueRef) final;
double normalizedValue() final;
Vector<SharedGamepadValue> m_buttonValues;
};
}
#endif // ENABLE(GAMEPAD) && PLATFORM(MAC)