summaryrefslogtreecommitdiff
path: root/src/gui/widgets
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
parented41c67908b8d6289f0e5eb49f101c851d9adc75 (diff)
downloadplus-7cd309e7c9e0200cedb45edfeeba5a601d3fb446.tar.gz
plus-7cd309e7c9e0200cedb45edfeeba5a601d3fb446.tar.bz2
plus-7cd309e7c9e0200cedb45edfeeba5a601d3fb446.tar.xz
plus-7cd309e7c9e0200cedb45edfeeba5a601d3fb446.zip
Impliment support for images in browser box. Enabled for help window.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/browserbox.cpp49
-rw-r--r--src/gui/widgets/browserbox.h19
2 files changed, 64 insertions, 4 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;
+}
diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h
index a1939bc6d..258e0bd09 100644
--- a/src/gui/widgets/browserbox.h
+++ b/src/gui/widgets/browserbox.h
@@ -30,6 +30,8 @@
#include <list>
#include <vector>
+class Image;
+class Resource;
class LinkHandler;
struct BROWSER_LINK
@@ -43,13 +45,22 @@ class LinePart
{
public:
LinePart(int x, int y, gcn::Color color, std::string text) :
- mX(x), mY(y), mColor(color), mText(text)
+ mX(x), mY(y), mColor(color), mText(text), mType(0), mImage(0)
{
}
+ LinePart(int x, int y, gcn::Color color, Image *image) :
+ mX(x), mY(y), mColor(color), mText(""), mType(1), mImage(image)
+ {
+ }
+
+ ~LinePart();
+
int mX, mY;
gcn::Color mColor;
std::string mText;
+ unsigned char mType;
+ Image *mImage;
};
/**
@@ -101,6 +112,8 @@ class BrowserBox : public gcn::Widget,
*/
void addRow(const std::string &row, bool atTop = false);
+ void addImage(const std::string &path);
+
/**
* Remove all rows.
*/
@@ -178,6 +191,9 @@ class BrowserBox : public gcn::Widget,
void setProcessVersion(bool n)
{ mProcessVersion = n; }
+ void setEnableImages(bool n)
+ { mEnableImages = n; }
+
private:
int calcHeight();
@@ -205,6 +221,7 @@ class BrowserBox : public gcn::Widget,
int mUpdateTime;
bool mAlwaysUpdate;
bool mProcessVersion;
+ bool mEnableImages;
};
#endif