Pass min/max to all AxisEventHandler
This commit is contained in:
parent
d4f651fa9e
commit
28a801da0a
2 changed files with 28 additions and 18 deletions
|
@ -165,6 +165,19 @@ AxisEvent::str() const
|
|||
return m_handler->str();
|
||||
}
|
||||
|
||||
AxisEventHandler::AxisEventHandler() :
|
||||
m_min(-1),
|
||||
m_max(+1)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
AxisEventHandler::set_axis_range(int min, int max)
|
||||
{
|
||||
m_min = min;
|
||||
m_max = max;
|
||||
}
|
||||
|
||||
RelAxisEventHandler*
|
||||
RelAxisEventHandler::from_string(const std::string& str)
|
||||
{
|
||||
|
@ -227,8 +240,14 @@ RelAxisEventHandler::init(UInput& uinput, int slot, bool extra_devices)
|
|||
void
|
||||
RelAxisEventHandler::send(UInput& uinput, int value)
|
||||
{
|
||||
// FIXME: Need to know the min/max of value
|
||||
int v = m_value * value / 32767;
|
||||
float value_f;
|
||||
if (value < 0)
|
||||
value_f = static_cast<float>(value) / static_cast<float>(-m_min);
|
||||
else
|
||||
value_f = static_cast<float>(value) / static_cast<float>(m_max);
|
||||
|
||||
int v = static_cast<int>(m_value * value_f);
|
||||
|
||||
if (v == 0)
|
||||
uinput.send_rel_repetitive(m_code, v, -1);
|
||||
else
|
||||
|
@ -285,8 +304,6 @@ AbsAxisEventHandler::from_string(const std::string& str)
|
|||
|
||||
AbsAxisEventHandler::AbsAxisEventHandler() :
|
||||
m_code(UIEvent::invalid()),
|
||||
m_min(-32768), // FIXME: this must be properly set
|
||||
m_max(32767),
|
||||
m_fuzz(0),
|
||||
m_flat(0)
|
||||
{
|
||||
|
@ -294,18 +311,10 @@ AbsAxisEventHandler::AbsAxisEventHandler() :
|
|||
|
||||
AbsAxisEventHandler::AbsAxisEventHandler(const UIEvent& code, int min, int max, int fuzz, int flat) :
|
||||
m_code(code),
|
||||
m_min(min),
|
||||
m_max(max),
|
||||
m_fuzz(fuzz),
|
||||
m_flat(flat)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
AbsAxisEventHandler::set_axis_range(int min, int max)
|
||||
{
|
||||
m_min = min;
|
||||
m_max = max;
|
||||
set_axis_range(min, max);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -66,14 +66,19 @@ private:
|
|||
|
||||
class AxisEventHandler
|
||||
{
|
||||
protected:
|
||||
int m_min;
|
||||
int m_max;
|
||||
|
||||
public:
|
||||
AxisEventHandler();
|
||||
virtual ~AxisEventHandler() {}
|
||||
|
||||
virtual void init(UInput& uinput, int slot, bool extra_devices) =0;
|
||||
virtual void send(UInput& uinput, int value) =0;
|
||||
virtual void update(UInput& uinput, int msec_delta) =0;
|
||||
|
||||
virtual void set_axis_range(int min, int max) {}
|
||||
virtual void set_axis_range(int min, int max);
|
||||
|
||||
virtual std::string str() const =0;
|
||||
};
|
||||
|
@ -108,8 +113,6 @@ public:
|
|||
AbsAxisEventHandler();
|
||||
AbsAxisEventHandler(const UIEvent& code, int min, int max, int fuzz, int flat);
|
||||
|
||||
void set_axis_range(int min, int max);
|
||||
|
||||
void init(UInput& uinput, int slot, bool extra_devices);
|
||||
void send(UInput& uinput, int value);
|
||||
void update(UInput& uinput, int msec_delta);
|
||||
|
@ -118,8 +121,6 @@ public:
|
|||
|
||||
private:
|
||||
UIEvent m_code;
|
||||
int m_min;
|
||||
int m_max;
|
||||
int m_fuzz;
|
||||
int m_flat;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue