summaryrefslogtreecommitdiff
path: root/src/gui/browserbox.cpp
diff options
context:
space:
mode:
authorEugenio Favalli <elvenprogrammer@gmail.com>2007-09-10 07:46:51 +0000
committerEugenio Favalli <elvenprogrammer@gmail.com>2007-09-10 07:46:51 +0000
commitce2b0db3129cc4f3f20c322fd6c727ce663838cc (patch)
tree90a79ae61c7f231dd9fbd5dcd99c814b2ad3ab05 /src/gui/browserbox.cpp
parent6635397f7a397bdd430fc062cc9e8c5bd3efed82 (diff)
downloadmana-client-ce2b0db3129cc4f3f20c322fd6c727ce663838cc.tar.gz
mana-client-ce2b0db3129cc4f3f20c322fd6c727ce663838cc.tar.bz2
mana-client-ce2b0db3129cc4f3f20c322fd6c727ce663838cc.tar.xz
mana-client-ce2b0db3129cc4f3f20c322fd6c727ce663838cc.zip
Added support for True Type Fonts.
Diffstat (limited to 'src/gui/browserbox.cpp')
-rw-r--r--src/gui/browserbox.cpp56
1 files changed, 13 insertions, 43 deletions
diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp
index 4a3f2f64..c618fa69 100644
--- a/src/gui/browserbox.cpp
+++ b/src/gui/browserbox.cpp
@@ -30,14 +30,7 @@
#include <guichan/mouseinput.hpp>
#include "linkhandler.h"
-
-#ifdef USE_OPENGL
-#include "../configuration.h"
-#include "../resources/resourcemanager.h"
-
-int BrowserBox::instances = 0;
-gcn::ImageFont* BrowserBox::browserFont = NULL;
-#endif
+#include "truetypefont.h"
BrowserBox::BrowserBox(unsigned int mode):
gcn::Widget(),
@@ -47,35 +40,10 @@ BrowserBox::BrowserBox(unsigned int mode):
{
setFocusable(true);
addMouseListener(this);
-
-#ifdef USE_OPENGL
- if (config.getValue("opengl", 0)) {
- if (instances == 0) {
- browserFont = new gcn::ImageFont(
- "graphics/gui/browserfont.png",
- " abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567"
- "89:@!\"$%&/=?^+*#[]{}()<>_;'.,\\|-~`"
- "øåáÁéÉíÍóÓúÚç륣¢¡¿àãõêñÑöüäÖÜÄßèÈÅ");
- }
- setFont(browserFont);
- instances++;
- }
-#endif
}
BrowserBox::~BrowserBox()
{
-#ifdef USE_OPENGL
- instances--;
-
- if (instances == 0)
- {
- // Clean up static resource font
- delete browserFont;
- browserFont = NULL;
- }
-#endif
}
void BrowserBox::setLinkHandler(LinkHandler* linkHandler)
@@ -104,7 +72,7 @@ void BrowserBox::addRow(const std::string &row)
std::string newRow;
BROWSER_LINK bLink;
int idx1, idx2, idx3;
- gcn::ImageFont *font = static_cast<gcn::ImageFont*>(getFont());
+ TrueTypeFont *font = static_cast<TrueTypeFont*>(getFont());
// Use links and user defined colors
if (mUseLinksAndUserColors)
@@ -172,7 +140,7 @@ void BrowserBox::addRow(const std::string &row)
{
unsigned int i, j, y = 0;
unsigned int nextChar;
- char hyphen = '~';
+ char *hyphen = "~";
int hyphenWidth = font->getWidth(hyphen);
int x = 0;
for (i = 0; i < mTextRows.size(); i++)
@@ -180,7 +148,8 @@ void BrowserBox::addRow(const std::string &row)
std::string row = mTextRows[i];
for (j = 0; j < row.size(); j++)
{
- x += font->getWidth(row.at(j));
+ std::string character = row.substr(j, 1);
+ x += font->getWidth(character);
nextChar = j + 1;
// Wraping between words (at blank spaces)
@@ -294,7 +263,7 @@ BrowserBox::draw(gcn::Graphics *graphics)
unsigned int i, j;
int x = 0, y = 0;
int wrappedLines = 0;
- gcn::ImageFont *font = static_cast<gcn::ImageFont*>(getFont());
+ TrueTypeFont *font = static_cast<TrueTypeFont*>(getFont());
graphics->setColor(BLACK);
for (i = 0; i < mTextRows.size(); i++)
@@ -377,22 +346,23 @@ BrowserBox::draw(gcn::Graphics *graphics)
{
for (x = 0; x < getWidth(); x++)
{
- font->drawGlyph(graphics, '-', x, y);
- x += font->getWidth('-') - 2;
+ font->drawString(graphics, "-", x, y);
+ x += font->getWidth("-") - 2;
}
break;
}
// Draw each char
else
{
- font->drawGlyph(graphics, row.at(j), x, y);
- x += font->getWidth(row.at(j));
+ std::string character = row.substr(j, 1);
+ font->drawString(graphics, character, x, y);
+ x += font->getWidth(character.c_str());
// Auto wrap mode
if (mMode == AUTO_WRAP)
{
unsigned int nextChar = j + 1;
- char hyphen = '~';
+ char *hyphen = "~";
int hyphenWidth = font->getWidth(hyphen);
// Wraping between words (at blank spaces)
@@ -419,7 +389,7 @@ BrowserBox::draw(gcn::Graphics *graphics)
// Wrapping looong lines (brutal force)
else if ((x + 2 * hyphenWidth) > getWidth())
{
- font->drawGlyph(graphics, hyphen,
+ font->drawString(graphics, hyphen,
getWidth() - hyphenWidth, y);
x = 15; // Ident in new line
y += font->getHeight();