X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Finput%2Fhub.cpp;h=1916126c9ff3f3be420de975bb3b93ea03ad9f55;hb=e82345f2c1286e684789854c7dbe32411bb0b05f;hp=cbf9f78a689e083d79057945ba84eb218aba3685;hpb=7d2b4349289578b8e7f322186a1f251684ddeb01;p=libs%2Fgui.git diff --git a/source/input/hub.cpp b/source/input/hub.cpp index cbf9f78..1916126 100644 --- a/source/input/hub.cpp +++ b/source/input/hub.cpp @@ -1,60 +1,88 @@ +#include "hub.h" #include #include -#include "hub.h" +#include +#include +#include using namespace std; namespace Msp { namespace Input { -Hub::Hub() +Hub::Hub(): + Device(UNSPECIFIED) { name = "Hub"; } -unsigned Hub::attach(Device &dev) +void Hub::attach(Device &dev) { unsigned index = devices.size(); devices.push_back(&dev); - dev.signal_button_press.connect(sigc::bind(sigc::mem_fun(this, &Hub::button_press), index)); - dev.signal_button_release.connect(sigc::bind(sigc::mem_fun(this, &Hub::button_release), index)); - dev.signal_axis_motion.connect(sigc::bind(sigc::mem_fun(this, &Hub::axis_motion), index)); - return index; + dev.signal_button_press.connect(sigc::bind_return(sigc::bind(sigc::mem_fun(this, &Hub::button_press), index), false)); + dev.signal_button_release.connect(sigc::bind_return(sigc::bind(sigc::mem_fun(this, &Hub::button_release), index), false)); + dev.signal_axis_motion.connect(sigc::bind_return(sigc::bind(sigc::mem_fun(this, &Hub::axis_motion), index), false)); +} + +Device *Hub::find_subdevice(DeviceType t, unsigned n) +{ + for(Device *d: devices) + if(Device *dev = d->find_subdevice(t, 0)) + { + if(!n) + return dev; + --n; + } + return nullptr; +} + +Device *Hub::find_subdevice(const string &n) +{ + if(n==name) + return this; + for(Device *d: devices) + if(Device *dev = d->find_subdevice(n)) + return dev; + return nullptr; } -std::string Hub::get_button_name(unsigned btn) const +string Hub::get_button_name(unsigned btn) const { - unsigned dev_index = btn>>12; + unsigned dev_index = btn>>8; if(dev_index>=devices.size()) - throw invalid_argument("Hub::get_button_name"); + throw out_of_range("Hub::get_button_name"); const Device &dev = *devices[dev_index]; - return dev.get_name()+": "+dev.get_button_name(btn&0xFFF); + return dev.get_name()+": "+dev.get_button_name(btn&0xFF); } -std::string Hub::get_axis_name(unsigned axis) const +string Hub::get_axis_name(unsigned axis) const { - unsigned dev_index = axis>>12; + unsigned dev_index = axis>>8; if(dev_index>=devices.size()) - throw invalid_argument("Hub::get_axis_name"); + throw out_of_range("Hub::get_axis_name"); const Device &dev = *devices[dev_index]; - return dev.get_name()+": "+dev.get_axis_name(axis&0xFFF); + return dev.get_name()+": "+dev.get_axis_name(axis&0xFF); } void Hub::button_press(unsigned btn, unsigned index) { - set_button_state((index<<12) | (btn&0xFFF), true, true); + if(btn<0x100) + set_button_state((index<<8) | btn, true, true); } void Hub::button_release(unsigned btn, unsigned index) { - set_button_state((index<<12) | (btn&0xFFF), false, true); + if(btn<0x100) + set_button_state((index<<8) | btn, false, true); } void Hub::axis_motion(unsigned axis, float value, float, unsigned index) { - set_axis_value((index<<12) | (axis&0xFFF), value, true); + if(axis<0x100) + set_axis_value((index<<8) | axis, value, true); } } // namespace Input