summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f84b3e8)
raw | patch | inline | side by side (parent: f84b3e8)
author | joncruz <joncruz@users.sourceforge.net> | |
Sat, 22 Mar 2008 21:40:30 +0000 (21:40 +0000) | ||
committer | joncruz <joncruz@users.sourceforge.net> | |
Sat, 22 Mar 2008 21:40:30 +0000 (21:40 +0000) |
src/device-manager.cpp | patch | blob | history | |
src/device-manager.h | patch | blob | history | |
src/ui/dialog/input.cpp | patch | blob | history |
diff --git a/src/device-manager.cpp b/src/device-manager.cpp
index 9cf4583c698f1bfc379f2350536e9e4ea12d63d0..dcf86edb706f53a0d3290ac6d3886b4b5ff055c5 100644 (file)
--- a/src/device-manager.cpp
+++ b/src/device-manager.cpp
virtual gint getNumKeys() const {return device->num_keys;}
virtual Glib::ustring getLink() const {return link;}
virtual void setLink( Glib::ustring const& link ) {this->link = link;}
+ virtual gint getLiveAxes() const {return liveAxes;}
+ virtual void setLiveAxes(gint axes) {liveAxes = axes;}
virtual gint getLiveButtons() const {return liveButtons;}
virtual void setLiveButtons(gint buttons) {liveButtons = buttons;}
Glib::ustring name;
Gdk::InputSource source;
Glib::ustring link;
+ guint liveAxes;
guint liveButtons;
};
name(device->name ? device->name : ""),
source(static_cast<Gdk::InputSource>(device->source)),
link(),
+ liveAxes(0),
liveButtons(0)
{
switch ( source ) {
DeviceManagerImpl();
virtual std::list<InputDevice const *> getDevices();
virtual sigc::signal<void, const Glib::RefPtr<InputDevice>& > signalDeviceChanged();
+ virtual sigc::signal<void, const Glib::RefPtr<InputDevice>& > signalAxesChanged();
virtual sigc::signal<void, const Glib::RefPtr<InputDevice>& > signalButtonsChanged();
virtual sigc::signal<void, const Glib::RefPtr<InputDevice>& > signalLinkChanged();
+ virtual void addAxis(Glib::ustring const & id, gint axis);
virtual void addButton(Glib::ustring const & id, gint button);
virtual void setLinkedTo(Glib::ustring const & id, Glib::ustring const& link);
protected:
std::list<InputDeviceImpl*> devices;
sigc::signal<void, const Glib::RefPtr<InputDevice>& > signalDeviceChangedPriv;
+ sigc::signal<void, const Glib::RefPtr<InputDevice>& > signalAxesChangedPriv;
sigc::signal<void, const Glib::RefPtr<InputDevice>& > signalButtonsChangedPriv;
sigc::signal<void, const Glib::RefPtr<InputDevice>& > signalLinkChangedPriv;
};
@@ -179,6 +186,11 @@ sigc::signal<void, const Glib::RefPtr<InputDevice>& > DeviceManagerImpl::signalD
return signalDeviceChangedPriv;
}
+sigc::signal<void, const Glib::RefPtr<InputDevice>& > DeviceManagerImpl::signalAxesChanged()
+{
+ return signalAxesChangedPriv;
+}
+
sigc::signal<void, const Glib::RefPtr<InputDevice>& > DeviceManagerImpl::signalButtonsChanged()
{
return signalButtonsChangedPriv;
@@ -189,6 +201,23 @@ sigc::signal<void, const Glib::RefPtr<InputDevice>& > DeviceManagerImpl::signalL
return signalLinkChangedPriv;
}
+void DeviceManagerImpl::addAxis(Glib::ustring const & id, gint axis)
+{
+ if ( axis >= 0 && axis < static_cast<gint>(bitVals.size()) ) {
+ std::list<InputDeviceImpl*>::iterator it = std::find_if(devices.begin(), devices.end(), IdMatcher(id));
+ if ( it != devices.end() ) {
+ gint mask = bitVals[axis];
+ if ( (mask & (*it)->getLiveAxes()) == 0 ) {
+ (*it)->setLiveAxes((*it)->getLiveAxes() | mask);
+
+ // Only signal if a new axis was added
+ (*it)->reference();
+ signalAxesChangedPriv.emit(Glib::RefPtr<InputDevice>(*it));
+ }
+ }
+ }
+}
+
void DeviceManagerImpl::addButton(Glib::ustring const & id, gint button)
{
if ( button >= 0 && button < static_cast<gint>(bitVals.size()) ) {
}
}
-
void DeviceManagerImpl::setLinkedTo(Glib::ustring const & id, Glib::ustring const& link)
{
std::list<InputDeviceImpl*>::iterator it = std::find_if(devices.begin(), devices.end(), IdMatcher(id));
diff --git a/src/device-manager.h b/src/device-manager.h
index f441180a67c8fd2a4a910dd46a98a3d6190b54bc..1bfb5120c109ea6ddb2ec6a4ea195452143f0a6c 100644 (file)
--- a/src/device-manager.h
+++ b/src/device-manager.h
virtual gint getNumAxes() const = 0;
virtual gint getNumKeys() const = 0;
virtual Glib::ustring getLink() const = 0;
+ virtual gint getLiveAxes() const = 0;
virtual gint getLiveButtons() const = 0;
protected:
virtual std::list<InputDevice const *> getDevices() = 0;
virtual sigc::signal<void, const Glib::RefPtr<InputDevice>& > signalDeviceChanged() = 0;
+ virtual sigc::signal<void, const Glib::RefPtr<InputDevice>& > signalAxesChanged() = 0;
virtual sigc::signal<void, const Glib::RefPtr<InputDevice>& > signalButtonsChanged() = 0;
virtual sigc::signal<void, const Glib::RefPtr<InputDevice>& > signalLinkChanged() = 0;
+ virtual void addAxis(Glib::ustring const & id, gint axis) = 0;
virtual void addButton(Glib::ustring const & id, gint button) = 0;
virtual void setLinkedTo(Glib::ustring const & id, Glib::ustring const& link) = 0;
index 1400ce93ff0c47b785b27e58acadb31584c352cf..34e503d0894419eb389da470a648160d003d542c 100644 (file)
--- a/src/ui/dialog/input.cpp
+++ b/src/ui/dialog/input.cpp
void linkComboChanged();
void resyncToSelection();
void handleDeviceChange(const Glib::RefPtr<InputDevice>& device);
+ void updateDeviceAxes(const Glib::RefPtr<InputDevice>& device);
void updateDeviceButtons(const Glib::RefPtr<InputDevice>& device);
void updateDeviceLinks(const Glib::RefPtr<InputDevice>& device);
};
g_warning("No devices found");
}
Inkscape::DeviceManager::getManager().signalDeviceChanged().connect(sigc::mem_fun(*this, &InputDialogImpl::handleDeviceChange));
+ Inkscape::DeviceManager::getManager().signalAxesChanged().connect(sigc::mem_fun(*this, &InputDialogImpl::updateDeviceAxes));
Inkscape::DeviceManager::getManager().signalButtonsChanged().connect(sigc::mem_fun(*this, &InputDialogImpl::updateDeviceButtons));
Inkscape::DeviceManager::getManager().signalLinkChanged().connect(sigc::mem_fun(*this, &InputDialogImpl::updateDeviceLinks));
@@ -686,6 +688,23 @@ void InputDialogImpl::handleDeviceChange(const Glib::RefPtr<InputDevice>& /*devi
// g_message("OUCH!!!! for %p hits %s", &device, device->getId().c_str());
}
+void InputDialogImpl::updateDeviceAxes(const Glib::RefPtr<InputDevice>& device)
+{
+ gint live = device->getLiveAxes();
+
+ std::map<guint, std::pair<guint, gdouble> > existing = axesMap[device->getId()];
+ gint mask = 0x1;
+ for ( gint num = 0; num < 32; num++, mask <<= 1) {
+ if ( (mask & live) != 0 ) {
+ if ( (existing.find(num) == existing.end()) || (existing[num].first < 2) ) {
+ axesMap[device->getId()][num].first = 2;
+ axesMap[device->getId()][num].second = 0.0;
+ }
+ }
+ }
+ updateTestAxes( device->getId(), 0 );
+}
+
void InputDialogImpl::updateDeviceButtons(const Glib::RefPtr<InputDevice>& device)
{
gint live = device->getLiveButtons();
@@ -877,31 +896,32 @@ void InputDialogImpl::mapAxesValues( Glib::ustring const& key, guint numAxes, gd
{
static gdouble epsilon = 0.0001;
if ( (numAxes > 0) && axes) {
- for ( guint axesNum = 0; axesNum < numAxes; axesNum++ ) {
+ for ( guint axisNum = 0; axisNum < numAxes; axisNum++ ) {
// 0 == new, 1 == set value, 2 == changed value, 3 == active
- gdouble diff = axesMap[key][axesNum].second - axes[axesNum];
- switch(axesMap[key][axesNum].first) {
+ gdouble diff = axesMap[key][axisNum].second - axes[axisNum];
+ switch(axesMap[key][axisNum].first) {
case 0:
{
- axesMap[key][axesNum].first = 1;
- axesMap[key][axesNum].second = axes[axesNum];
+ axesMap[key][axisNum].first = 1;
+ axesMap[key][axisNum].second = axes[axisNum];
}
break;
case 1:
{
if ( (diff > epsilon) || (diff < -epsilon) ) {
-// g_message("Axis %d changed on %s]", axesNum, key.c_str());
- axesMap[key][axesNum].first = 3;
- axesMap[key][axesNum].second = axes[axesNum];
+// g_message("Axis %d changed on %s]", axisNum, key.c_str());
+ axesMap[key][axisNum].first = 3;
+ axesMap[key][axisNum].second = axes[axisNum];
updateTestAxes(key, dev);
+ DeviceManager::getManager().addAxis(key, axisNum);
}
}
break;
case 2:
{
if ( (diff > epsilon) || (diff < -epsilon) ) {
- axesMap[key][axesNum].first = 3;
- axesMap[key][axesNum].second = axes[axesNum];
+ axesMap[key][axisNum].first = 3;
+ axesMap[key][axisNum].second = axes[axisNum];
updateTestAxes(key, dev);
}
}
@@ -909,9 +929,9 @@ void InputDialogImpl::mapAxesValues( Glib::ustring const& key, guint numAxes, gd
case 3:
{
if ( (diff > epsilon) || (diff < -epsilon) ) {
- axesMap[key][axesNum].second = axes[axesNum];
+ axesMap[key][axisNum].second = axes[axisNum];
} else {
- axesMap[key][axesNum].first = 2;
+ axesMap[key][axisNum].first = 2;
updateTestAxes(key, dev);
}
}