From e4c171740956998fdac81c071aafefcb9dba817e Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Tue, 26 Apr 2005 11:22:35 +0000 Subject: Corrections to scrolling chat modifications by Usiu. --- src/gui/chat.cpp | 69 +++++++++++++++++++++----------------------------- src/gui/chat.h | 8 ++---- src/gui/scrollarea.cpp | 35 ++++++++++++++++++++----- src/gui/scrollarea.h | 11 ++++++++ 4 files changed, 70 insertions(+), 53 deletions(-) (limited to 'src/gui') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 27005a16..11f60466 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -23,6 +23,7 @@ #include "chat.h" #include "textfield.h" +#include "textbox.h" #include "../graphics.h" #include "../main.h" #include @@ -40,7 +41,8 @@ ChatWindow::ChatWindow(const char *logfile, int item_num): textOutput->setEditable(false); scrollArea = new ScrollArea(textOutput); scrollArea->setDimension(gcn::Rectangle( - 5, 5, 590, 85 - chatInput->getHeight())); + 2, 0, 596, 98 - chatInput->getHeight() - 5)); + scrollArea->setOpaque(false); chatInput->setPosition( chatInput->getBorderSize(), 100 - chatInput->getHeight() - chatInput->getBorderSize()); @@ -59,21 +61,13 @@ 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; CHATLOG tmp; - if (items <= items_keep) { - items++; // delete overhead from the end of the list - } - else { + // Delete overhead from the end of the list + while (chatlog.size() > items_keep) { chatlog.pop_back(); } @@ -88,6 +82,8 @@ void ChatWindow::chat_log(std::string line, int own) case ACT_WHISPER: tmp.nick += CAT_WHISPER; break; + case BY_GM: + tmp.nick += std::string("Global announcement: "); default: tmp.nick += CAT_NORMAL; } @@ -97,36 +93,43 @@ void ChatWindow::chat_log(std::string line, int own) } tmp.own = own; + line = tmp.nick + line; + // A try to get text sentences no too long... bool finished = false; unsigned int maxLength = 80; while (!finished) { - std::string tempText; + std::string tempText = line; + if (line.length() > maxLength) { - - tempText = line; - if (line.length() > maxLength) + if (line.length() > maxLength) { line = cut_string(tempText, maxLength); + } - tmp.text = tempText; + //tmp.text = tempText; //chatlog_file << tmp.nick << tmp.text << "\n"; //chatlog_file.flush(); - chatlog.push_front(tmp); + //chatlog.push_front(tmp); } else // Normal message { - tmp.text = line; + //tmp.text = line; //chatlog_file << tmp.nick << tmp.text << "\n"; //chatlog_file.flush(); - chatlog.push_front(tmp); + //chatlog.push_front(tmp); finished = true; } + + textOutput->setText( + textOutput->getText() + std::string("\n") + tempText); + scrollArea->setVerticalScrollAmount( + scrollArea->getVerticalMaxScroll()); } } @@ -142,6 +145,7 @@ void ChatWindow::draw(gcn::Graphics *graphics) Window::draw(graphics); // Draw the chat log + /* int x, y; int n = 8; int texty = getHeight() - 5 - chatInput->getHeight() - @@ -161,48 +165,32 @@ void ChatWindow::draw(gcn::Graphics *graphics) texty -= getFont()->getHeight() - 2; - //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); - addOutput(std::string("Global announcement: ")); - break; + addOutput(std::string("Global announcement: ")); + break; case BY_PLAYER: graphics->setColor(gcn::Color(255, 246, 98)); // Yellow - //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); - addOutput(std::string(line.nick)); break; - } - - //graphics->popClipArea(); + } switch (line.own) { case BY_GM: graphics->setColor(gcn::Color(39, 197, 39)); // Green - //graphics->drawText(line.text, 100, texty); - addOutput(std::string(line.text) + std::string("\n")); - break; + break; case BY_PLAYER: graphics->setColor(gcn::Color(255, 255, 255)); // White - //graphics->drawText(line.text, 100, texty); - addOutput(std::string(line.text) + std::string("\n")); - break; + break; case BY_OTHER: graphics->setColor(gcn::Color(39, 197, 39)); // Green - //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); - addOutput(std::string(line.text) + std::string("\n")); } if (i >= n) { @@ -210,6 +198,7 @@ void ChatWindow::draw(gcn::Graphics *graphics) } i++; } + */ } void ChatWindow::action(const std::string& eventId) diff --git a/src/gui/chat.h b/src/gui/chat.h index b41e6947..53891f7d 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -28,7 +28,6 @@ #include "../resources/image.h" #include "../net/network.h" #include "window.h" -#include "textbox.h" #include "scrollarea.h" #include #include @@ -111,9 +110,6 @@ class ChatWindow : public Window, public gcn::ActionListener { */ ~ChatWindow(); - - void addOutput(std::string output); - /* * Adds a line of text to our message list. Parameters: * @@ -203,8 +199,8 @@ class ChatWindow : public Window, public gcn::ActionListener { /** Input box for chat messages */ gcn::TextField *chatInput; - TextBox *textOutput; - ScrollArea *scrollArea; + gcn::TextBox *textOutput; + ScrollArea *scrollArea; }; #endif diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp index 033a9450..b1afa183 100644 --- a/src/gui/scrollarea.cpp +++ b/src/gui/scrollarea.cpp @@ -40,7 +40,9 @@ ScrollArea::ScrollArea(gcn::Widget *widget): void ScrollArea::init() { + // Draw background by default setBorderSize(2); + opaque = true; // Load the background skin ResourceManager *resman = ResourceManager::getInstance(); @@ -54,7 +56,7 @@ void ScrollArea::init() // Set GUI alpha level textbox->setAlpha(guiAlpha); - + for (y = 0; y < 3; y++) { for (x = 0; x < 3; x++) { background.grid[a] = textbox->getSubImage( @@ -80,7 +82,7 @@ void ScrollArea::init() a++; } } - + hscroll_left_default = resman->getImage("graphics/gui/hscroll_left_default.png"); hscroll_right_default = resman->getImage("graphics/gui/hscroll_right_default.png"); vscroll_down_default = resman->getImage("graphics/gui/vscroll_down_default.png"); @@ -97,8 +99,8 @@ void ScrollArea::draw(gcn::Graphics *graphics) int alpha = getBaseColor().a; gcn::Color highlightColor = getBaseColor() + 0x303030; - highlightColor.a = alpha; - gcn::Color shadowColor = getBaseColor() - 0x303030; + highlightColor.a = alpha; + gcn::Color shadowColor = getBaseColor() - 0x303030; shadowColor.a = alpha; if (mVBarVisible) @@ -128,7 +130,7 @@ void ScrollArea::draw(gcn::Graphics *graphics) if (mContent) { - gcn::Rectangle contdim = mContent->getDimension(); + gcn::Rectangle contdim = mContent->getDimension(); graphics->pushClipArea(getContentDimension()); if (mContent->getBorderSize() > 0) @@ -137,7 +139,7 @@ void ScrollArea::draw(gcn::Graphics *graphics) rec.x -= mContent->getBorderSize(); rec.y -= mContent->getBorderSize(); rec.width += 2 * mContent->getBorderSize(); - rec.height += 2 * mContent->getBorderSize(); + rec.height += 2 * mContent->getBorderSize(); graphics->pushClipArea(rec); mContent->drawBorder(graphics); graphics->popClipArea(); @@ -160,7 +162,26 @@ void ScrollArea::drawBorder(gcn::Graphics *graphics) x -= bs; y -= bs; - ((Graphics*)graphics)->drawImageRect(x, y, w, h, background); + if (isOpaque()) { + ((Graphics*)graphics)->drawImageRect(x, y, w, h, background); + } +} + +void ScrollArea::setOpaque(bool opaque) +{ + this->opaque = opaque; + + if (opaque) { + setBorderSize(2); + } + else { + setBorderSize(0); + } +} + +bool ScrollArea::isOpaque() +{ + return opaque; } void ScrollArea::drawUpButton(gcn::Graphics *graphics) diff --git a/src/gui/scrollarea.h b/src/gui/scrollarea.h index 26c87e0e..ce745ba8 100644 --- a/src/gui/scrollarea.h +++ b/src/gui/scrollarea.h @@ -55,6 +55,16 @@ class ScrollArea : public gcn::ScrollArea { */ void drawBorder(gcn::Graphics *graphics); + /** + * Sets whether the widget should draw its background or not. + */ + void setOpaque(bool opaque); + + /** + * Returns whether the widget draws its background or not. + */ + bool isOpaque(); + protected: /** * Initializes the scroll area. @@ -77,6 +87,7 @@ class ScrollArea : public gcn::ScrollArea { Image *hscroll_left_pressed, *hscroll_right_pressed, *vscroll_down_pressed, *vscroll_up_pressed; float guiAlpha; + bool opaque; }; #endif -- cgit v1.2.3-70-g09d2