summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-05-09 19:33:22 +0200
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-05-09 19:36:15 +0200
commit3dacb9b09622375d35d704c8ac9d7039d506026f (patch)
treeebc9dd04955cee5d394403b754c150b7c2260f3b /src
parent3074acf977841492b2378b5542bc3d755cf0a227 (diff)
downloadmana-3dacb9b09622375d35d704c8ac9d7039d506026f.tar.gz
mana-3dacb9b09622375d35d704c8ac9d7039d506026f.tar.bz2
mana-3dacb9b09622375d35d704c8ac9d7039d506026f.tar.xz
mana-3dacb9b09622375d35d704c8ac9d7039d506026f.zip
Insert player and item names at caret position instead of at the end
An improvement based on the 0.0.28.Q version.
Diffstat (limited to 'src')
-rw-r--r--src/gui/chat.cpp23
-rw-r--r--src/gui/chat.h8
2 files changed, 21 insertions, 10 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 3d0cb766..11a327d8 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -44,6 +44,8 @@
#include <guichan/focushandler.hpp>
#include <guichan/focuslistener.hpp>
+#include <sstream>
+
/**
* The chat input hides when it loses focus. It is also invisible by default.
*/
@@ -336,7 +338,7 @@ void ChatWindow::doPresent()
time(&t);
// Format the time string properly
- std::stringstream timeStr;
+ std::ostringstream timeStr;
timeStr << "[" << ((((t / 60) / 60) % 24 < 10) ? "0" : "")
<< (int) (((t / 60) / 60) % 24)
<< ":" << (((t / 60) % 60 < 10) ? "0" : "")
@@ -359,7 +361,8 @@ void ChatWindow::scroll(int amount)
return;
ChatTab *tab = getFocused();
- if (tab) tab->scroll(amount);
+ if (tab)
+ tab->scroll(amount);
}
void ChatWindow::keyPressed(gcn::KeyEvent &event)
@@ -397,16 +400,24 @@ void ChatWindow::keyPressed(gcn::KeyEvent &event)
}
}
-void ChatWindow::addInputText(std::string input_str)
+void ChatWindow::addInputText(const std::string &text)
{
- mChatInput->setText(mChatInput->getText() + input_str + " ");
- requestChatFocus();
+ const int caretPos = mChatInput->getCaretPosition();
+ const std::string inputText = mChatInput->getText();
+
+ std::ostringstream ss;
+ ss << inputText.substr(0, caretPos) << text << " ";
+ ss << inputText.substr(caretPos);
+
+ mChatInput->setText(ss.str());
+ mChatInput->setCaretPosition(caretPos + text.length() + 1);
+ requestChatFocus();
}
void ChatWindow::addItemText(const std::string &item)
{
std::ostringstream text;
- text << "[" << item << "] ";
+ text << "[" << item << "]";
addInputText(text.str());
}
diff --git a/src/gui/chat.h b/src/gui/chat.h
index efd0b02e..c6e8e326 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -91,12 +91,12 @@ class ChatWindow : public Window,
/**
* Gets the focused tab.
*/
- ChatTab* getFocused() const;
+ ChatTab *getFocused() const;
/**
* Clear the given tab.
*/
- void clearTab(ChatTab* tab);
+ void clearTab(ChatTab *tab);
/**
* Clear the current tab.
@@ -141,8 +141,8 @@ class ChatWindow : public Window,
/** Called when key is pressed */
void keyPressed(gcn::KeyEvent &event);
- /** Add the given text to the chat input */
- void addInputText(std::string input_str);
+ /** Add the given text to the chat input. */
+ void addInputText(const std::string &text);
/** Called to add item to chat */
void addItemText(const std::string &item);