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>
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::set_source(Device &d, ControlSrcType t, unsigned i)
92 set_source(ControlSource(d, t, i));
95 void Control::set_source(const ControlSource &s)
102 void Control::connect_signals()
109 src.dev->signal_button_press.connect(sigc::mem_fun(this, &Control::button_press));
110 src.dev->signal_button_release.connect(sigc::mem_fun(this, &Control::button_release));
114 src.dev->signal_axis_motion.connect(sigc::mem_fun(this, &Control::axis_motion));
117 throw Exception("Invalid source in Control");
121 void Control::button_press(unsigned i)
132 signal_capture_complete.emit();
134 else if(src.type==BUTTON && i==src.index)
138 void Control::button_release(unsigned i)
140 if(src.type==BUTTON && i==src.index)
144 void Control::axis_motion(unsigned i, float v, float r)
148 ControlSrcType type=NONE;
149 if(v<-src.dev->get_axis_threshold())
151 else if(v>src.dev->get_axis_threshold())
163 signal_capture_complete.emit();
166 else if(src.type==AXIS_POS && i==src.index && v>=0)
168 else if(src.type==AXIS_NEG && i==src.index && v<=0)