diff --git a/src/common/JoyMap.cxx b/src/common/JoyMap.cxx index 2a20b4a8b..266dd5e74 100644 --- a/src/common/JoyMap.cxx +++ b/src/common/JoyMap.cxx @@ -185,9 +185,35 @@ JoyMap::JoyMappingArray JoyMap::getEventMapping(const Event::Type event, const E // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string JoyMap::saveMapping(const EventMode mode) const { + using MapType = std::pair; + std::vector sortedMap(myMap.begin(), myMap.end()); + + std::sort(sortedMap.begin(), sortedMap.end(), + [](const MapType& a, const MapType& b) + { + // Event::Type first + if(a.second != b.second) + return a.second < b.second; + + if(a.first.button != b.first.button) + return a.first.button < b.first.button; + + if(a.first.axis != b.first.axis) + return a.first.axis < b.first.axis; + + if(a.first.adir != b.first.adir) + return a.first.adir < b.first.adir; + + if(a.first.hat != b.first.hat) + return a.first.hat < b.first.hat; + + return a.first.hdir < b.first.hdir; + } + ); + ostringstream buf; - for (auto item : myMap) + for (auto item : sortedMap) { if (item.first.mode == mode) { diff --git a/src/common/KeyMap.cxx b/src/common/KeyMap.cxx index eca0369ec..47b34dc9c 100644 --- a/src/common/KeyMap.cxx +++ b/src/common/KeyMap.cxx @@ -16,11 +16,12 @@ //============================================================================ #include "KeyMap.hxx" +#include // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void KeyMap::add(const Event::Type event, const Mapping& mapping) { - myMap[convertMod(mapping)] = event; + myMap[convertMod(mapping)] = event; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -32,7 +33,7 @@ void KeyMap::add(const Event::Type event, const EventMode mode, const int key, c // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void KeyMap::erase(const Mapping& mapping) { - myMap.erase(convertMod(mapping)); + myMap.erase(convertMod(mapping)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -170,9 +171,26 @@ KeyMap::MappingArray KeyMap::getEventMapping(const Event::Type event, const Even // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string KeyMap::saveMapping(const EventMode mode) const { + using MapType = std::pair; + std::vector sortedMap(myMap.begin(), myMap.end()); + + std::sort(sortedMap.begin(), sortedMap.end(), + [](const MapType& a, const MapType& b) + { + // Event::Type first + if(a.second != b.second) + return a.second < b.second; + + if(a.first.key != b.first.key) + return a.first.key < b.first.key; + + return a.first.mod < b.first.mod; + } + ); + ostringstream buf; - for (auto item : myMap) + for (auto item : sortedMap) { if (item.first.mode == mode) {