diff options
author | Mateusz Kaduk <mateusz.kaduk@gmail.com> | 2005-04-26 09:17:53 +0000 |
---|---|---|
committer | Mateusz Kaduk <mateusz.kaduk@gmail.com> | 2005-04-26 09:17:53 +0000 |
commit | c1d360e6f0ae1ff3c15a52fab8a6115841d058bb (patch) | |
tree | c535f85804c5e0290e32a649d9f0749cfefda41f /src/gui/chat.cpp | |
parent | 8b0e30d3798cd5bdce2c3a34a3c384e90dceac99 (diff) | |
download | mana-c1d360e6f0ae1ff3c15a52fab8a6115841d058bb.tar.gz mana-c1d360e6f0ae1ff3c15a52fab8a6115841d058bb.tar.bz2 mana-c1d360e6f0ae1ff3c15a52fab8a6115841d058bb.tar.xz mana-c1d360e6f0ae1ff3c15a52fab8a6115841d058bb.zip |
Added scrolling to chat but setText() works strangly and because of draw() I get message looping
Diffstat (limited to 'src/gui/chat.cpp')
-rw-r--r-- | src/gui/chat.cpp | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index fac868c5..27005a16 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -35,14 +35,19 @@ ChatWindow::ChatWindow(const char *logfile, int item_num): items_keep = item_num; setContentSize(600, 100); - + textOutput = new TextBox(); chatInput = new TextField(); + textOutput->setEditable(false); + scrollArea = new ScrollArea(textOutput); + scrollArea->setDimension(gcn::Rectangle( + 5, 5, 590, 85 - chatInput->getHeight())); chatInput->setPosition( chatInput->getBorderSize(), 100 - chatInput->getHeight() - chatInput->getBorderSize()); chatInput->setWidth(600 - 2 * chatInput->getBorderSize()); chatInput->setEventId("chatinput"); chatInput->addActionListener(this); + add(scrollArea); add(chatInput); } @@ -54,6 +59,12 @@ ChatWindow::~ChatWindow() chatlog_file.close(); } +void ChatWindow::addOutput(std::string output) +{ + textOutput->setText(textOutput->getText() + output); + //textOutput->setText(output); +} + void ChatWindow::chat_log(std::string line, int own) { int pos; @@ -150,41 +161,48 @@ void ChatWindow::draw(gcn::Graphics *graphics) texty -= getFont()->getHeight() - 2; - graphics->pushClipArea(gcn::Rectangle(0, 0, 95, getHeight())); + //graphics->pushClipArea(gcn::Rectangle(0, 0, 95, getHeight())); switch (line.own) { case BY_GM: graphics->setColor(gcn::Color(97, 156, 236)); // GM Bue - graphics->drawText("Global announcement: ", 5, texty); - break; + //graphics->drawText("Global announcement: ", 5, texty); + addOutput(std::string("Global announcement: ")); + break; case BY_PLAYER: graphics->setColor(gcn::Color(255, 246, 98)); // Yellow - graphics->drawText(line.nick, 5, texty); + //graphics->drawText(line.nick, 5, texty); + addOutput(std::string(line.nick)); break; case BY_OTHER: graphics->setColor(gcn::Color(97, 156, 236)); // GM Bue - graphics->drawText(line.nick, 5, texty); + //graphics->drawText(line.nick, 5, texty); + addOutput(std::string(line.nick)); break; - } + } - graphics->popClipArea(); + //graphics->popClipArea(); switch (line.own) { case BY_GM: graphics->setColor(gcn::Color(39, 197, 39)); // Green - graphics->drawText(line.text, 100, texty); - break; + //graphics->drawText(line.text, 100, texty); + addOutput(std::string(line.text) + std::string("\n")); + break; case BY_PLAYER: graphics->setColor(gcn::Color(255, 255, 255)); // White - graphics->drawText(line.text, 100, texty); - break; + //graphics->drawText(line.text, 100, texty); + addOutput(std::string(line.text) + std::string("\n")); + break; case BY_OTHER: graphics->setColor(gcn::Color(39, 197, 39)); // Green - graphics->drawText(line.text, 100, texty); + //graphics->drawText(line.text, 100, texty); + addOutput(std::string(line.text) + std::string("\n")); break; default: graphics->setColor(gcn::Color(83, 233, 246)); // Light blue - graphics->drawText(line.text, 5, texty); + //graphics->drawText(line.text, 5, texty); + addOutput(std::string(line.text) + std::string("\n")); } if (i >= n) { |