summaryrefslogtreecommitdiff
path: root/src/gui/widgets/browserbox.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-05-18 01:38:38 +0300
committerAndrei Karas <akaras@inbox.ru>2011-05-18 01:48:04 +0300
commit7cd309e7c9e0200cedb45edfeeba5a601d3fb446 (patch)
treec52eb86ae689ffbd088442d90b6da073ac7d98c0 /src/gui/widgets/browserbox.cpp
parented41c67908b8d6289f0e5eb49f101c851d9adc75 (diff)
downloadmanaverse-7cd309e7c9e0200cedb45edfeeba5a601d3fb446.tar.gz
manaverse-7cd309e7c9e0200cedb45edfeeba5a601d3fb446.tar.bz2
manaverse-7cd309e7c9e0200cedb45edfeeba5a601d3fb446.tar.xz
manaverse-7cd309e7c9e0200cedb45edfeeba5a601d3fb446.zip
Impliment support for images in browser box. Enabled for help window.
Diffstat (limited to 'src/gui/widgets/browserbox.cpp')
-rw-r--r--src/gui/widgets/browserbox.cpp49
1 files changed, 46 insertions, 3 deletions
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
index a925c0712..5d144c5a9 100644
--- a/src/gui/widgets/browserbox.cpp
+++ b/src/gui/widgets/browserbox.cpp
@@ -24,6 +24,7 @@
#include "gui/widgets/browserbox.h"
#include "client.h"
+#include "graphics.h"
#include "log.h"
#include "utils/stringutils.h"
@@ -33,6 +34,10 @@
#include "gui/widgets/linkhandler.h"
+#include "resources/image.h"
+#include "resources/resource.h"
+#include "resources/resourcemanager.h"
+
#include <guichan/graphics.hpp>
#include <guichan/font.hpp>
#include <guichan/cliprectangle.hpp>
@@ -52,7 +57,8 @@ BrowserBox::BrowserBox(unsigned int mode, bool opaque):
mYStart(0),
mUpdateTime(-1),
mAlwaysUpdate(true),
- mProcessVersion(false)
+ mProcessVersion(false),
+ mEnableImages(false)
{
setFocusable(true);
addMouseListener(this);
@@ -235,6 +241,14 @@ void BrowserBox::addRow(const std::string &row, bool atTop)
updateHeight();
}
+void BrowserBox::addImage(const std::string &path)
+{
+ if (!mEnableImages)
+ return;
+
+ mTextRows.push_back("~~~" + path);
+}
+
void BrowserBox::clearRows()
{
mTextRows.clear();
@@ -283,6 +297,7 @@ void BrowserBox::mouseMoved(gcn::MouseEvent &event)
void BrowserBox::draw(gcn::Graphics *graphics)
{
gcn::ClipRectangle cr = graphics->getCurrentClipArea();
+ Graphics *graphics2 = static_cast<Graphics*>(graphics);
mYStart = cr.y - cr.yOffset;
int yEnd = mYStart + cr.height;
if (mYStart < 0)
@@ -333,8 +348,15 @@ void BrowserBox::draw(gcn::Graphics *graphics)
continue;
if (part.mY > yEnd)
break;
- graphics->setColor(part.mColor);
- font->drawString(graphics, part.mText, part.mX, part.mY);
+ if (!part.mType)
+ {
+ graphics->setColor(part.mColor);
+ font->drawString(graphics, part.mText, part.mX, part.mY);
+ }
+ else if (part.mImage)
+ {
+ graphics2->drawImage(part.mImage, part.mX, part.mY);
+ }
}
return;
@@ -357,6 +379,7 @@ int BrowserBox::calcHeight()
gcn::Color selColor = Theme::getThemeColor(Theme::TEXT);
const gcn::Color textColor = Theme::getThemeColor(Theme::TEXT);
+ ResourceManager *resman = ResourceManager::getInstance();
mLineParts.clear();
@@ -379,6 +402,19 @@ int BrowserBox::calcHeight()
y += fontHeight;
continue;
}
+ else if (mEnableImages && row.find("~~~", 0) == 0)
+ {
+ std::string str = row.substr(3);
+ if (str.size() > 2 && str.substr(str.size() - 1) == "~")
+ str = str.substr(0, str.size() - 1);
+ Image *img = resman->getImage(str);
+ if (img)
+ {
+ mLineParts.push_back(LinePart(x, y, selColor, img));
+ y += img->getHeight();
+ }
+ continue;
+ }
gcn::Color prevColor = selColor;
@@ -546,3 +582,10 @@ void BrowserBox::updateHeight()
mUpdateTime = cur_time;
}
}
+
+LinePart::~LinePart()
+{
+ if (mImage)
+ mImage->decRef();
+ mImage = 0;
+}