summaryrefslogtreecommitdiff
path: root/indra/llcommon/llkeybind.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon/llkeybind.cpp')
-rw-r--r--indra/llcommon/llkeybind.cpp76
1 files changed, 59 insertions, 17 deletions
diff --git a/indra/llcommon/llkeybind.cpp b/indra/llcommon/llkeybind.cpp
index 0eca289d4b..ff88a9c9aa 100644
--- a/indra/llcommon/llkeybind.cpp
+++ b/indra/llcommon/llkeybind.cpp
@@ -218,13 +218,17 @@ bool LLKeyBind::isEmpty() const
LLSD LLKeyBind::asLLSD() const
{
+ S32 last = mData.size() - 1;
+ while (mData[last].empty())
+ {
+ last--;
+ }
+
LLSD data;
- for (data_vector_t::const_iterator iter = mData.begin(); iter != mData.end(); iter++)
+ for (S32 i = 0; i <= last; ++i)
{
- if (!iter->isEmpty())
- {
- data.append(iter->asLLSD());
- }
+ // append even if empty to not affect visual representation
+ data.append(mData[i].asLLSD());
}
return data;
}
@@ -280,6 +284,43 @@ bool LLKeyBind::hasKeyData(const LLKeyData& data) const
return hasKeyData(data.mMouse, data.mKey, data.mMask, data.mIgnoreMasks);
}
+bool LLKeyBind::hasKeyData(U32 index) const
+{
+ return mData.size() > index;
+}
+
+S32 LLKeyBind::findKeyData(EMouseClickType mouse, KEY key, MASK mask, bool ignore) const
+{
+ if (mouse != CLICK_NONE || key != KEY_NONE)
+ {
+ for (S32 i = 0; i < mData.size(); ++i)
+ {
+ if (mData[i].mKey == key
+ && mData[i].mMask == mask
+ && mData[i].mMouse == mouse
+ && mData[i].mIgnoreMasks == ignore)
+ {
+ return i;
+ }
+ }
+ }
+ return -1;
+}
+
+S32 LLKeyBind::findKeyData(const LLKeyData& data) const
+{
+ return findKeyData(data.mMouse, data.mKey, data.mMask, data.mIgnoreMasks);
+}
+
+LLKeyData LLKeyBind::getKeyData(U32 index) const
+{
+ if (mData.size() > index)
+ {
+ return mData[index];
+ }
+ return LLKeyData();
+}
+
bool LLKeyBind::addKeyData(EMouseClickType mouse, KEY key, MASK mask, bool ignore)
{
if (!hasKeyData(mouse, key, mask, ignore))
@@ -344,28 +385,29 @@ void LLKeyBind::replaceKeyData(const LLKeyData& data, U32 index)
}
}
}
- if (mData.size() > index)
+ if (mData.size() <= index)
{
- mData[index] = data;
- }
- else
- {
- mData.push_back(data);
+ mData.resize(index + 1);
}
+ mData[index] = data;
}
-bool LLKeyBind::hasKeyData(U32 index) const
+void LLKeyBind::resetKeyData(S32 index)
{
- return mData.size() > index;
+ if (mData.size() > index)
+ {
+ mData[index].reset();
+ }
}
-LLKeyData LLKeyBind::getKeyData(U32 index) const
+void LLKeyBind::trimEmpty()
{
- if (mData.size() > index)
+ S32 last = mData.size() - 1;
+ while (last >= 0 && mData[last].empty())
{
- return mData[index];
+ mData.erase(mData.begin() + last);
+ last--;
}
- return LLKeyData();
}
U32 LLKeyBind::getDataCount()