3 This file is part of libmspgbase
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/core/except.h>
9 #include <msp/strings/lexicalcast.h>
11 #include "inputdevice.h"
16 ControlSource::ControlSource():
22 ControlSource::ControlSource(Device &d, ControlSrcType t, unsigned i):
28 std::string ControlSource::str() const
31 return dev->get_button_name(index);
32 else if(type==AXIS_POS || type==AXIS_NEG)
33 return dev->get_axis_name(index);
37 return lexical_cast(index);
45 Control::Control(const ControlSource &s):
50 Control::Control(Device &d, ControlSrcType t, unsigned i):
57 Control::Control(const Control &c):
65 Control &Control::operator=(const Control &c)
75 void Control::capture(Device &d)
79 capture_dev->signal_button_press.connect(sigc::mem_fun(this, &Control::button_press));
80 capture_dev->signal_axis_motion.connect(sigc::mem_fun(this, &Control::axis_motion));
83 void Control::cancel_capture()
90 void Control::connect_signals()
97 src.dev->signal_button_press.connect(sigc::mem_fun(this, &Control::button_press));
98 src.dev->signal_button_release.connect(sigc::mem_fun(this, &Control::button_release));
102 src.dev->signal_axis_motion.connect(sigc::mem_fun(this, &Control::axis_motion));
105 throw Exception("Invalid source in Control");
109 void Control::button_press(unsigned i)
120 signal_capture_complete.emit();
122 else if(src.type==BUTTON && i==src.index)
126 void Control::button_release(unsigned i)
128 if(src.type==BUTTON && i==src.index)
132 void Control::axis_motion(unsigned i, float v, float r)
136 ControlSrcType type=NONE;
137 if(v<-src.dev->get_axis_threshold())
139 else if(v>src.dev->get_axis_threshold())
151 signal_capture_complete.emit();
154 else if(src.type==AXIS_POS && i==src.index && v>=0)
156 else if(src.type==AXIS_NEG && i==src.index && v<=0)