diff options
author | Eugenio Favalli <elvenprogrammer@gmail.com> | 2007-09-10 07:46:51 +0000 |
---|---|---|
committer | Eugenio Favalli <elvenprogrammer@gmail.com> | 2007-09-10 07:46:51 +0000 |
commit | ce2b0db3129cc4f3f20c322fd6c727ce663838cc (patch) | |
tree | 90a79ae61c7f231dd9fbd5dcd99c814b2ad3ab05 /src/gui/browserbox.cpp | |
parent | 6635397f7a397bdd430fc062cc9e8c5bd3efed82 (diff) | |
download | mana-ce2b0db3129cc4f3f20c322fd6c727ce663838cc.tar.gz mana-ce2b0db3129cc4f3f20c322fd6c727ce663838cc.tar.bz2 mana-ce2b0db3129cc4f3f20c322fd6c727ce663838cc.tar.xz mana-ce2b0db3129cc4f3f20c322fd6c727ce663838cc.zip |
Added support for True Type Fonts.
Diffstat (limited to 'src/gui/browserbox.cpp')
-rw-r--r-- | src/gui/browserbox.cpp | 56 |
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(); |