summaryrefslogtreecommitdiff
path: root/src/gui/widgets/browserbox.cpp
diff options
context:
space:
mode:
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;
+}