summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2008-12-29 14:02:01 -0700
committerIra Rice <irarice@gmail.com>2008-12-29 14:06:41 -0700
commita5c8eae057746618443c788fcaa04221d8ad7ba4 (patch)
treeab104a2dd1f931730eef50365434b8ac0896ca8b /src
parent6b680b60af9084767fd50737df763a89ca2c2919 (diff)
downloadmana-a5c8eae057746618443c788fcaa04221d8ad7ba4.tar.gz
mana-a5c8eae057746618443c788fcaa04221d8ad7ba4.tar.bz2
mana-a5c8eae057746618443c788fcaa04221d8ad7ba4.tar.xz
mana-a5c8eae057746618443c788fcaa04221d8ad7ba4.zip
Added support for True Type Fonts using GUIChan's inbuilt SDLTrueType
class. NOTE: This commit adds a brand new dependency (SDL_TTF). Make sure to install it, regenerate your config files, reconfigure, and then install before attempting to compile. Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am4
-rw-r--r--src/gui/browserbox.cpp56
-rw-r--r--src/gui/browserbox.h5
-rw-r--r--src/gui/gui.cpp33
-rw-r--r--src/gui/itemcontainer.cpp1
-rw-r--r--src/gui/itemshortcutcontainer.cpp1
-rw-r--r--src/gui/sdltruetypefont.cpp171
-rw-r--r--src/gui/widgets/adjustingcontainer.cpp279
-rw-r--r--src/gui/widgets/adjustingcontainer.hpp235
-rw-r--r--src/gui/window.cpp1
-rw-r--r--src/main.cpp4
-rw-r--r--src/sdltruetypefont.cpp171
-rw-r--r--src/sdltruetypefont.hpp157
14 files changed, 1055 insertions, 65 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index fea11c55..a7735e41 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -338,6 +338,8 @@ SET(SRCS
player_relations.cpp
player_relations.h
properties.h
+ sdltruetypefont.cpp
+ sdltruetypefont.hpp
serverinfo.h
shopitem.cpp
shopitem.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 5f168dda..f6b343f6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -74,6 +74,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \
gui/npc_text.h \
gui/ok_dialog.cpp \
gui/ok_dialog.h \
+ gui/truetypefont.cpp \
+ gui/truetypefont.h \
gui/passwordfield.cpp \
gui/passwordfield.h \
gui/playerbox.cpp \
@@ -301,6 +303,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \
properties.h \
recorder.cpp \
recorder.h \
+ sdltruetypefont.cpp \
+ sdltruetypefont.h \
serverinfo.h \
shopitem.cpp \
shopitem.h \
diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp
index 430a2aa2..18acfa6a 100644
--- a/src/gui/browserbox.cpp
+++ b/src/gui/browserbox.cpp
@@ -29,13 +29,7 @@
#include "colour.h"
#include "linkhandler.h"
-#ifdef USE_OPENGL
-#include "../configuration.h"
-#include "../resources/resourcemanager.h"
-
-int BrowserBox::instances = 0;
-gcn::ImageFont* BrowserBox::browserFont = NULL;
-#endif
+#include "../sdltruetypefont.hpp"
BrowserBox::BrowserBox(unsigned int mode):
gcn::Widget(),
@@ -47,35 +41,10 @@ BrowserBox::BrowserBox(unsigned int mode):
{
setFocusable(true);
addMouseListener(this);
-
-#ifdef USE_OPENGL
- if (config.getValue("opengl", 0.0f)) {
- 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 +73,7 @@ void BrowserBox::addRow(const std::string &row)
std::string newRow;
BROWSER_LINK bLink;
int idx1, idx2, idx3;
- gcn::ImageFont *font = dynamic_cast<gcn::ImageFont*>(getFont());
+ gcn::Font *font = getFont();
// Use links and user defined colors
if (mUseLinksAndUserColors)
@@ -178,7 +147,7 @@ void BrowserBox::addRow(const std::string &row)
{
unsigned int j, y = 0;
unsigned int nextChar;
- char hyphen = '~';
+ const char *hyphen = "~";
int hyphenWidth = font->getWidth(hyphen);
int x = 0;
@@ -187,7 +156,8 @@ void BrowserBox::addRow(const std::string &row)
std::string row = *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)
@@ -302,7 +272,7 @@ BrowserBox::draw(gcn::Graphics *graphics)
unsigned int j;
int x = 0, y = 0;
int wrappedLines = 0;
- gcn::ImageFont *font = dynamic_cast<gcn::ImageFont*>(getFont());
+ gcn::Font *font = getFont();
graphics->setColor(BLACK);
for (TextRowIterator i = mTextRows.begin(); i != mTextRows.end(); i++)
@@ -353,22 +323,24 @@ BrowserBox::draw(gcn::Graphics *graphics)
{
for (x = 0; x < getWidth(); x++)
{
- font->drawGlyph(graphics, '-', x, y);
- x += font->getWidth('-') - 2;
+ const std::string dash = "-";
+ font->drawString(graphics, dash, 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 = '~';
+ const std::string hyphen = "~";
int hyphenWidth = font->getWidth(hyphen);
// Wraping between words (at blank spaces)
@@ -395,7 +367,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();
diff --git a/src/gui/browserbox.h b/src/gui/browserbox.h
index 267e0fea..1c1e283a 100644
--- a/src/gui/browserbox.h
+++ b/src/gui/browserbox.h
@@ -145,11 +145,6 @@ class BrowserBox : public gcn::Widget, public gcn::MouseListener
bool mUseLinksAndUserColors;
int mSelectedLink;
unsigned int mMaxRows;
-
-#ifdef USE_OPENGL
- static int instances; /**< Number of Window instances */
- static gcn::ImageFont* browserFont;
-#endif
};
#endif
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 70f82d9d..846a0f44 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -36,6 +36,7 @@
#include "../configuration.h"
#include "../graphics.h"
#include "../log.h"
+#include "../sdltruetypefont.hpp"
#include "../resources/image.h"
#include "../resources/imageset.h"
@@ -110,26 +111,20 @@ Gui::Gui(Graphics *graphics):
Window::setWindowContainer(guiTop);
setTop(guiTop);
- // Set global font (based on ISO-8859-15)
+ // Set global font
try {
- mGuiFont = new gcn::ImageFont("graphics/gui/sansserif8.png",
- " !\"#$%&'()*+,-./"
- "0123456789:;<=>?"
- "@ABCDEFGHIJKLMNO"
- "PQRSTUVWXYZ[\\]^_"
- "`abcdefghijklmno"
- "pqrstuvwxyz{|}~|"
- " ¡¢£¤¥¦§¨©ª«¬­®¯"
- "°±²³´µ¶·¸¹º»¼½¾¿"
- "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ"
- "ÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß"
- "àáâãäåæçèéêëìíîï"
- "ðñòóôõö÷øùúûüýþÿ"
- );
+ mGuiFont = new gcn::contrib::SDLTrueTypeFont("/usr/local/share/aethyra/data/fonts/dejavusans.ttf", 10);
}
catch (gcn::Exception e)
{
- logger->error("Unable to load sansserif8.png!");
+ try {
+ mGuiFont = new gcn::contrib::SDLTrueTypeFont("data/fonts/dejavusans.ttf", 10);
+ }
+ catch (gcn::Exception e)
+ {
+ logger->error(std::string("Unable to load dejavusans.ttf: ")
+ + e.getMessage());
+ }
}
// Set speech font
@@ -142,7 +137,8 @@ Gui::Gui(Graphics *graphics):
}
catch (gcn::Exception e)
{
- logger->error("Unable to load rpgfont_wider.png!");
+ logger->error(std::string("Unable to load rpgfont_wider.png: ")
+ + e.getMessage());
}
// Set npc name font
@@ -198,7 +194,8 @@ Gui::Gui(Graphics *graphics):
}
catch (gcn::Exception e)
{
- logger->error("Unable to load colored hits' fonts!");
+ logger->error(std::string("Unable to load colored hits' fonts: ")
+ + e.getMessage());
}
// Initialize mouse cursor and listen for changes to the option
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 9e17f3da..26ca3379 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -118,6 +118,7 @@ void ItemContainer::draw(gcn::Graphics *graphics)
}
// Draw item caption
+ graphics->setColor(0x000000);
graphics->drawText(
(item->isEquipped() ? "Eq." : toString(item->getQuantity())),
itemX + gridWidth / 2,
diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp
index de5e1956..77657169 100644
--- a/src/gui/itemshortcutcontainer.cpp
+++ b/src/gui/itemshortcutcontainer.cpp
@@ -87,6 +87,7 @@ ItemShortcutContainer::draw(gcn::Graphics *graphics)
// Draw item keyboard shortcut.
const char *key = SDL_GetKeyName(
(SDLKey) keyboard.getKeyValue(keyboard.KEY_SHORTCUT_0 + i));
+ graphics->setColor(0x000000);
g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT);
if (itemShortcut->getItem(i) < 0)
diff --git a/src/gui/sdltruetypefont.cpp b/src/gui/sdltruetypefont.cpp
new file mode 100644
index 00000000..ee09f64d
--- /dev/null
+++ b/src/gui/sdltruetypefont.cpp
@@ -0,0 +1,171 @@
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
+ *
+ *
+ * Per Larsson a.k.a finalman
+ * Olof Naessén a.k.a jansem/yakslem
+ *
+ * Visit: http://guichan.sourceforge.net
+ *
+ * License: (BSD)
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name of Guichan nor the names of its contributors may
+ * be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * For comments regarding functions please see the header file.
+ */
+
+#include "sdltruetypefont.hpp"
+
+#include <guichan/exception.hpp>
+#include <guichan/image.hpp>
+#include <guichan/graphics.hpp>
+#include <guichan/sdl/sdlgraphics.hpp>
+
+namespace gcn
+{
+ namespace contrib
+ {
+ SDLTrueTypeFont::SDLTrueTypeFont (const std::string& filename, int size)
+ {
+ mRowSpacing = 0;
+ mGlyphSpacing = 0;
+ mAntiAlias = true;
+ mFilename = filename;
+ mFont = NULL;
+
+ mFont = TTF_OpenFont(filename.c_str(), size);
+
+ if (mFont == NULL)
+ {
+ throw GCN_EXCEPTION("SDLTrueTypeFont::SDLTrueTypeFont. "+std::string(TTF_GetError()));
+ }
+ }
+
+ SDLTrueTypeFont::~SDLTrueTypeFont()
+ {
+ TTF_CloseFont(mFont);
+ }
+
+ int SDLTrueTypeFont::getWidth(const std::string& text) const
+ {
+ int w, h;
+ TTF_SizeText(mFont, text.c_str(), &w, &h);
+
+ return w;
+ }
+
+ int SDLTrueTypeFont::getHeight() const
+ {
+ return TTF_FontHeight(mFont) + mRowSpacing;
+ }
+
+ void SDLTrueTypeFont::drawString(gcn::Graphics* graphics, const std::string& text, const int x, const int y)
+ {
+ if (text == "")
+ {
+ return;
+ }
+
+ SDLGraphics *sdlGraphics = dynamic_cast<SDLGraphics *>(graphics);
+
+ if (sdlGraphics == NULL)
+ {
+ throw GCN_EXCEPTION("SDLTrueTypeFont::drawString. Graphics object not an SDL graphics object!");
+ return;
+ }
+
+ // This is needed for drawing the Glyph in the middle if we have spacing
+ int yoffset = getRowSpacing() / 2;
+
+ Color col = sdlGraphics->getColor();
+
+ SDL_Color sdlCol;
+ sdlCol.b = col.b;
+ sdlCol.r = col.r;
+ sdlCol.g = col.g;
+
+ SDL_Surface *textSurface;
+ if (mAntiAlias)
+ {
+ textSurface = TTF_RenderText_Blended(mFont, text.c_str(), sdlCol);
+ }
+ else
+ {
+ textSurface = TTF_RenderText_Solid(mFont, text.c_str(), sdlCol);
+ }
+
+ SDL_Rect dst, src;
+ dst.x = x;
+ dst.y = y + yoffset;
+ src.w = textSurface->w;
+ src.h = textSurface->h;
+ src.x = 0;
+ src.y = 0;
+
+ sdlGraphics->drawSDLSurface(textSurface, src, dst);
+ SDL_FreeSurface(textSurface);
+ }
+
+ void SDLTrueTypeFont::setRowSpacing(int spacing)
+ {
+ mRowSpacing = spacing;
+ }
+
+ int SDLTrueTypeFont::getRowSpacing()
+ {
+ return mRowSpacing;
+ }
+
+ void SDLTrueTypeFont::setGlyphSpacing(int spacing)
+ {
+ mGlyphSpacing = spacing;
+ }
+
+ int SDLTrueTypeFont::getGlyphSpacing()
+ {
+ return mGlyphSpacing;
+ }
+
+ void SDLTrueTypeFont::setAntiAlias(bool antiAlias)
+ {
+ mAntiAlias = antiAlias;
+ }
+
+ bool SDLTrueTypeFont::isAntiAlias()
+ {
+ return mAntiAlias;
+ }
+ }
+}
+
diff --git a/src/gui/widgets/adjustingcontainer.cpp b/src/gui/widgets/adjustingcontainer.cpp
new file mode 100644
index 00000000..2c613fbe
--- /dev/null
+++ b/src/gui/widgets/adjustingcontainer.cpp
@@ -0,0 +1,279 @@
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * Copyright (c) 2007 - 2008 Josh Matthews and Olof Naessén
+ *
+ *
+ * Per Larsson a.k.a finalman
+ * Olof Naessén a.k.a jansem/yakslem
+ *
+ * Visit: http://guichan.sourceforge.net
+ *
+ * License: (BSD)
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name of Guichan nor the names of its contributors may
+ * be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * For comments regarding functions please see the header file.
+ */
+
+#include "adjustingcontainer.hpp"
+
+#include <guichan.hpp>
+
+namespace gcn
+{
+ namespace contrib
+ {
+ AdjustingContainer::AdjustingContainer()
+ : mWidth(0),
+ mHeight(0),
+ mNumberOfColumns(1),
+ mNumberOfRows(1),
+ mPaddingLeft(0),
+ mPaddingRight(0),
+ mPaddingTop(0),
+ mPaddingBottom(0),
+ mVerticalSpacing(0),
+ mHorizontalSpacing(0)
+
+
+ {
+ mColumnWidths.push_back(0);
+ mRowHeights.push_back(0);
+ }
+
+ AdjustingContainer::~AdjustingContainer()
+ {
+
+ }
+
+ void AdjustingContainer::setNumberOfColumns(unsigned int numberOfColumns)
+ {
+ mNumberOfColumns = numberOfColumns;
+
+ if (mColumnAlignment.size() < numberOfColumns)
+ {
+ while (mColumnAlignment.size() < numberOfColumns)
+ {
+ mColumnAlignment.push_back(LEFT);
+ }
+ }
+ else
+ {
+ while (mColumnAlignment.size() > numberOfColumns)
+ {
+ mColumnAlignment.pop_back();
+ }
+ }
+ }
+
+ void AdjustingContainer::setColumnAlignment(unsigned int column,
+ unsigned int alignment)
+ {
+ if (column < mColumnAlignment.size())
+ {
+ mColumnAlignment[column] = alignment;
+ }
+ }
+
+ void AdjustingContainer::setPadding(unsigned int paddingLeft,
+ unsigned int paddingRight,
+ unsigned int paddingTop,
+ unsigned int paddingBottom)
+ {
+ mPaddingLeft = paddingLeft;
+ mPaddingRight = paddingRight;
+ mPaddingTop = paddingTop;
+ mPaddingBottom = paddingBottom;
+ }
+
+ void AdjustingContainer::setVerticalSpacing(unsigned int verticalSpacing)
+ {
+ mVerticalSpacing = verticalSpacing;
+ }
+
+ void AdjustingContainer::setHorizontalSpacing(unsigned int horizontalSpacing)
+ {
+ mHorizontalSpacing = horizontalSpacing;
+ }
+
+ void AdjustingContainer::logic()
+ {
+ Container::logic();
+ adjustContent();
+ }
+
+ void AdjustingContainer::add(Widget *widget)
+ {
+ Container::add(widget);
+ mContainedWidgets.push_back(widget);
+ }
+
+ void AdjustingContainer::add(Widget *widget, int x, int y)
+ {
+ add(widget);
+ }
+
+ void AdjustingContainer::clear()
+ {
+ Container::clear();
+ mContainedWidgets.clear();
+ }
+
+ void AdjustingContainer::remove(Widget *widget)
+ {
+ Container::remove(widget);
+ std::vector<gcn::Widget *>::iterator it;
+ for(it = mContainedWidgets.begin(); it != mContainedWidgets.end(); it++)
+ {
+ if(*it == widget)
+ {
+ mContainedWidgets.erase(it);
+ break;
+ }
+ }
+ }
+
+ void AdjustingContainer::adjustSize()
+ {
+ mNumberOfRows = mContainedWidgets.size()
+ / mNumberOfColumns + mContainedWidgets.size() % mNumberOfColumns;
+
+ mColumnWidths.clear();
+
+ unsigned int i;
+ for (i = 0; i < mNumberOfColumns; i++)
+ {
+ mColumnWidths.push_back(0);
+ }
+
+ mRowHeights.clear();
+
+ for (i = 0; i < mNumberOfRows; i++)
+ {
+ mRowHeights.push_back(0);
+ }
+
+ for (i = 0; i < mNumberOfColumns; i++)
+ {
+ unsigned int j;
+ for (j = 0; j < mNumberOfRows && mNumberOfColumns * j + i < mContainedWidgets.size(); j++)
+ {
+ if ((unsigned int)mContainedWidgets[mNumberOfColumns * j + i]->getWidth() > mColumnWidths[i])
+ {
+ mColumnWidths[i] = mContainedWidgets[mNumberOfColumns * j + i]->getWidth();
+ }
+ if ((unsigned int)mContainedWidgets[mNumberOfColumns * j + i]->getHeight() > mRowHeights[j])
+ {
+ mRowHeights[j] = mContainedWidgets[mNumberOfColumns * j + i]->getHeight();
+ }
+ }
+ }
+
+ mWidth = mPaddingLeft;
+
+ for (i = 0; i < mColumnWidths.size(); i++)
+ {
+ mWidth += mColumnWidths[i] + mHorizontalSpacing;
+ }
+
+ mWidth -= mHorizontalSpacing;
+ mWidth += mPaddingRight;
+
+ mHeight = mPaddingTop;
+
+ for (i = 0; i < mRowHeights.size(); i++)
+ {
+ mHeight += mRowHeights[i] + mVerticalSpacing;
+ }
+
+ mHeight -= mVerticalSpacing;
+ mHeight += mPaddingBottom;
+
+ setHeight(mHeight);
+ setWidth(mWidth);
+ }
+
+ void AdjustingContainer::adjustContent()
+ {
+ adjustSize();
+
+ unsigned int columnCount = 0;
+ unsigned int rowCount = 0;
+ unsigned int y = mPaddingTop;
+
+ for (unsigned int i = 0; i < mContainedWidgets.size(); i++)
+ {
+ unsigned basex;
+ if (columnCount % mNumberOfColumns)
+ {
+ basex = mPaddingLeft;
+ unsigned int j;
+
+ for (j = 0; j < columnCount; j++)
+ {
+ basex += mColumnWidths[j] + mHorizontalSpacing;
+ }
+ }
+ else
+ {
+ basex = mPaddingLeft;
+ }
+
+ switch (mColumnAlignment[columnCount])
+ {
+ case LEFT:
+ mContainedWidgets[i]->setX(basex);
+ break;
+ case CENTER:
+ mContainedWidgets[i]->setX(basex + (mColumnWidths[columnCount] - mContainedWidgets[i]->getWidth()) / 2);
+ break;
+ case RIGHT:
+ mContainedWidgets[i]->setX(basex + mColumnWidths[columnCount] - mContainedWidgets[i]->getWidth());
+ break;
+ default:
+ throw GCN_EXCEPTION("Unknown alignment.");
+ }
+
+ mContainedWidgets[i]->setY(y);
+ columnCount++;
+
+ if (columnCount == mNumberOfColumns)
+ {
+ columnCount = 0;
+ y += mRowHeights[rowCount] + mVerticalSpacing;
+ rowCount++;
+ }
+ }
+ }
+ }
+}
diff --git a/src/gui/widgets/adjustingcontainer.hpp b/src/gui/widgets/adjustingcontainer.hpp
new file mode 100644
index 00000000..3227274e
--- /dev/null
+++ b/src/gui/widgets/adjustingcontainer.hpp
@@ -0,0 +1,235 @@
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * Copyright (c) 2007 - 2008 Josh Matthews and Olof Naessén
+ *
+ *
+ * Per Larsson a.k.a finalman
+ * Olof Naessén a.k.a jansem/yakslem
+ *
+ * Visit: http://guichan.sourceforge.net
+ *
+ * License: (BSD)
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name of Guichan nor the names of its contributors may
+ * be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef GCN_CONTRIB_ADJUSTINGCONTAINER_HPP
+#define GCN_CONTRIB_ADJUSTINGCONTAINER_HPP
+
+#include <vector>
+
+namespace gcn
+{
+ namespace contrib
+ {
+ /**
+ * Self-adjusting Container class. AdjustingContainers are an easy way to
+ * have Guichan position a group of widgets for you. It organizes elements
+ * in a table layout, with fixed columns and variable rows. The user specifies
+ *
+ * @verbitam
+ * <ul>
+ * <li>the number of columns</li>
+ * <li>horizontal spacing between columns</li>
+ * <li>vertical spacing between rows</li>
+ * <li>padding around the sides of the container</li>
+ * <li>each column's alignment</li>
+ * </ul>
+ * @endverbitam
+ *
+ * These properties give the user a lot of flexibility to make the
+ * widgets look just right.
+ * @code
+ * AdjustingContainer *adjust = new AdjustingContainer;
+ * adjust->setPadding(5, 5, 5, 5); //left, right, top, bottom
+ * adjust->setHorizontalSpacing(3);
+ * adjust->setVerticalSpacing(3);
+ * adjust->setColumns(3);
+ * adjust->setColumnAlignment(0, AdjustingContainer::LEFT);
+ * adjust->setColumnAlignment(1, AdjustingContainer::CENTER);
+ * adjust->setColumnAlignment(2, AdjustingContainer::RIGHT);
+ * top->add(adjust);
+ *
+ * for(int j = 0; j < 9; j++)
+ * {
+ * gcn::Label *l;
+ * int r = rand() % 3;
+ * if(r == 0)
+ * l = new gcn::Label("Short");
+ * else if(r == 1)
+ * l = new gcn::Label("A longer phrase");
+ * else
+ * l = new gcn::Label("Extravagent and wordy text");
+ * adjust->add(l);
+ * @endcode
+ *
+ * Output:
+ * @verbitam
+ * <pre>
+ *+---------------------------------------------------------------------------+
+ *| |
+ *| A longer phrase Short Extravagent and wordy text |
+ *| |
+ *| Short Extravagent and wordy text Short |
+ *| |
+ *| Short A longer phrase A longer phrase |
+ *| |
+ *+---------------------------------------------------------------------------+
+ * </pre>
+ * @endverbitam
+ * As you can see, each column is only as big as its largest element.
+ * The AdjustingContainer will resize itself and rearrange its contents
+ * based on whatever widgets it contains, allowing dynamic addition and
+ * removal while the program is running. It also plays nicely with ScrollAreas,
+ * allowing you to show a fixed, maximum size while not limiting the actual
+ * container.
+ *
+ * For more help with using AdjustingContainers, try the Guichan forums
+ * (http://guichan.sourceforge.net/forum/) or email mrlachatte@gmail.com.
+ *
+ * @author Josh Matthews
+ */
+ class AdjustingContainer : public gcn::Container
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ AdjustingContainer();
+
+ /**
+ * Destructor.
+ */
+ virtual ~AdjustingContainer();
+
+ /**
+ * Set the number of columns to divide the widgets into.
+ * The number of rows is derived automatically from the number
+ * of widgets based on the number of columns. Default column
+ * alignment is left.
+ *
+ * @param numberOfColumns the number of columns.
+ */
+ virtual void setNumberOfColumns(unsigned int numberOfColumns);
+
+ /**
+ * Set a specific column's alignment.
+ *
+ * @param column the column number, starting from 0.
+ * @param alignment the column's alignment. See enum with alignments.
+ */
+ virtual void setColumnAlignment(unsigned int column, unsigned int alignment);
+
+ /**
+ * Set the padding for the sides of the container.
+ *
+ * @param paddingLeft left padding.
+ * @param paddingRight right padding.
+ * @param paddingTop top padding.
+ * @param paddingBottom bottom padding.
+ */
+ virtual void setPadding(unsigned int paddingLeft,
+ unsigned int paddingRight,
+ unsigned int paddingTop,
+ unsigned int paddingBottom);
+
+ /**
+ * Set the spacing between rows.
+ *
+ * @param verticalSpacing spacing in pixels.
+ */
+ virtual void setVerticalSpacing(unsigned int verticalSpacing);
+
+ /**
+ * Set the horizontal spacing between columns.
+ *
+ * @param horizontalSpacing spacing in pixels.
+ */
+ virtual void setHorizontalSpacing(unsigned int horizontalSpacing);
+
+ /**
+ * Rearrange the widgets and resize the container.
+ */
+ virtual void adjustContent();
+
+
+ // Inherited from Container
+
+ virtual void logic();
+
+ virtual void add(Widget *widget);
+
+ virtual void add(Widget *widget, int x, int y);
+
+ virtual void remove(Widget *widget);
+
+ virtual void clear();
+
+ /**
+ * Possible alignment values for each column.
+ *
+ * LEFT - Align content to the left of the column.
+ * MIDDLE - Align content to the middle of the column.
+ * RIGHT - Align content to the right of the column.
+ */
+ enum
+ {
+ LEFT = 0,
+ CENTER,
+ RIGHT
+ };
+
+ protected:
+
+ /**
+ * Adjust the size of the container to fit all the widgets.
+ */
+ virtual void adjustSize();
+
+ std::vector<Widget*> mContainedWidgets;
+ std::vector<unsigned int> mColumnWidths;
+ std::vector<unsigned int> mColumnAlignment;
+ std::vector<unsigned int> mRowHeights;
+ unsigned int mWidth;
+ unsigned int mHeight;
+ unsigned int mNumberOfColumns;
+ unsigned int mNumberOfRows;
+ unsigned int mPaddingLeft;
+ unsigned int mPaddingRight;
+ unsigned int mPaddingTop;
+ unsigned int mPaddingBottom;
+ unsigned int mVerticalSpacing;
+ unsigned int mHorizontalSpacing;
+ };
+ }
+}
+
+#endif
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index cdace3ae..dee5832a 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -177,6 +177,7 @@ void Window::draw(gcn::Graphics *graphics)
// Draw title
if (mShowTitle)
{
+ g->setColor(gcn::Color(0, 0, 0));
g->setFont(getFont());
g->drawText(getCaption(), 7, 5, gcn::Graphics::LEFT);
}
diff --git a/src/main.cpp b/src/main.cpp
index 818a4e32..12789d80 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -34,6 +34,8 @@
#include <libxml/parser.h>
+#include <SDL/SDL_ttf.h>
+
#include "configuration.h"
#include "game.h"
#include "graphics.h"
@@ -399,6 +401,7 @@ void init_engine(const Options &options)
// Initialize the item shortcuts.
itemShortcut = new ItemShortcut();
+ TTF_Init();
gui = new Gui(graphics);
state = LOGIN_STATE; /**< Initial game state */
@@ -1052,6 +1055,7 @@ int main(int argc, char *argv[])
delete network;
SDLNet_Quit();
+ TTF_Quit();
if (nullFile)
{
diff --git a/src/sdltruetypefont.cpp b/src/sdltruetypefont.cpp
new file mode 100644
index 00000000..937d2d63
--- /dev/null
+++ b/src/sdltruetypefont.cpp
@@ -0,0 +1,171 @@
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
+ *
+ *
+ * Per Larsson a.k.a finalman
+ * Olof Naessén a.k.a jansem/yakslem
+ *
+ * Visit: http://guichan.sourceforge.net
+ *
+ * License: (BSD)
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name of Guichan nor the names of its contributors may
+ * be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * For comments regarding functions please see the header file.
+ */
+
+#include "sdltruetypefont.hpp"
+
+#include <guichan/exception.hpp>
+#include <guichan/image.hpp>
+#include <guichan/graphics.hpp>
+#include <guichan/sdl/sdlgraphics.hpp>
+
+namespace gcn
+{
+ namespace contrib
+ {
+ SDLTrueTypeFont::SDLTrueTypeFont (const std::string& filename, int size)
+ {
+ mRowSpacing = 0;
+ mGlyphSpacing = 0;
+ mAntiAlias = true;
+ mFilename = filename;
+ mFont = NULL;
+
+ mFont = TTF_OpenFont(filename.c_str(), size);
+
+ if (mFont == NULL)
+ {
+ throw GCN_EXCEPTION("SDLTrueTypeFont::SDLTrueTypeFont. "+std::string(TTF_GetError()));
+ }
+ }
+
+ SDLTrueTypeFont::~SDLTrueTypeFont()
+ {
+ TTF_CloseFont(mFont);
+ }
+
+ int SDLTrueTypeFont::getWidth(const std::string& text) const
+ {
+ int w, h;
+ TTF_SizeText(mFont, text.c_str(), &w, &h);
+
+ return w;
+ }
+
+ int SDLTrueTypeFont::getHeight() const
+ {
+ return TTF_FontHeight(mFont) + mRowSpacing;
+ }
+
+ void SDLTrueTypeFont::drawString(Graphics* graphics, const std::string& text, const int x, const int y)
+ {
+ if (text == "")
+ {
+ return;
+ }
+
+ SDLGraphics *sdlGraphics = dynamic_cast<SDLGraphics *>(graphics);
+
+ if (sdlGraphics == NULL)
+ {
+ throw GCN_EXCEPTION("SDLTrueTypeFont::drawString. Graphics object not an SDL graphics object!");
+ return;
+ }
+
+ // This is needed for drawing the Glyph in the middle if we have spacing
+ int yoffset = getRowSpacing() / 2;
+
+ Color col = sdlGraphics->getColor();
+
+ SDL_Color sdlCol;
+ sdlCol.b = col.b;
+ sdlCol.r = col.r;
+ sdlCol.g = col.g;
+
+ SDL_Surface *textSurface;
+ if (mAntiAlias)
+ {
+ textSurface = TTF_RenderText_Blended(mFont, text.c_str(), sdlCol);
+ }
+ else
+ {
+ textSurface = TTF_RenderText_Solid(mFont, text.c_str(), sdlCol);
+ }
+
+ SDL_Rect dst, src;
+ dst.x = x;
+ dst.y = y + yoffset;
+ src.w = textSurface->w;
+ src.h = textSurface->h;
+ src.x = 0;
+ src.y = 0;
+
+ sdlGraphics->drawSDLSurface(textSurface, src, dst);
+ SDL_FreeSurface(textSurface);
+ }
+
+ void SDLTrueTypeFont::setRowSpacing(int spacing)
+ {
+ mRowSpacing = spacing;
+ }
+
+ int SDLTrueTypeFont::getRowSpacing()
+ {
+ return mRowSpacing;
+ }
+
+ void SDLTrueTypeFont::setGlyphSpacing(int spacing)
+ {
+ mGlyphSpacing = spacing;
+ }
+
+ int SDLTrueTypeFont::getGlyphSpacing()
+ {
+ return mGlyphSpacing;
+ }
+
+ void SDLTrueTypeFont::setAntiAlias(bool antiAlias)
+ {
+ mAntiAlias = antiAlias;
+ }
+
+ bool SDLTrueTypeFont::isAntiAlias()
+ {
+ return mAntiAlias;
+ }
+ }
+}
+
diff --git a/src/sdltruetypefont.hpp b/src/sdltruetypefont.hpp
new file mode 100644
index 00000000..7a1dd658
--- /dev/null
+++ b/src/sdltruetypefont.hpp
@@ -0,0 +1,157 @@
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
+ *
+ *
+ * Per Larsson a.k.a finalman
+ * Olof Naessén a.k.a jansem/yakslem
+ *
+ * Visit: http://guichan.sourceforge.net
+ *
+ * License: (BSD)
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name of Guichan nor the names of its contributors may
+ * be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef GCN_CONTRIB_SDLTRUETYPEFONT_HPP
+#define GCN_CONTRIB_SDLTRUETYPEFONT_HPP
+
+#include <map>
+#include <string>
+
+#include <SDL/SDL_ttf.h>
+
+#include <guichan/font.hpp>
+#include <guichan/platform.hpp>
+
+namespace gcn
+{
+ class Graphics;
+
+ namespace contrib
+ {
+
+ /**
+ * SDL True Type Font implementation of Font. It uses the SDL_ttf library
+ * to display True Type Fonts with SDL.
+ *
+ * NOTE: You must initialize the SDL_ttf library before using this
+ * class. Also, remember to call the SDL_ttf libraries quit
+ * function.
+ *
+ * @author Walluce Pinkham
+ * @author Olof Naessén
+ */
+ class GCN_EXTENSION_DECLSPEC SDLTrueTypeFont: public Font
+ {
+ public:
+
+ /**
+ * Constructor.
+ *
+ * @param filename the filename of the True Type Font.
+ * @param size the size the font should be in.
+ */
+ SDLTrueTypeFont (const std::string& filename, int size);
+
+ /**
+ * Destructor.
+ */
+ virtual ~SDLTrueTypeFont();
+
+ /**
+ * Sets the spacing between rows in pixels. Default is 0 pixels.
+ * The spacing can be negative.
+ *
+ * @param spacing the spacing in pixels.
+ */
+ virtual void setRowSpacing (int spacing);
+
+ /**
+ * Gets the spacing between rows in pixels.
+ *
+ * @return the spacing.
+ */
+ virtual int getRowSpacing();
+
+ /**
+ * Sets the spacing between letters in pixels. Default is 0 pixels.
+ * The spacing can be negative.
+ *
+ * @param spacing the spacing in pixels.
+ */
+ virtual void setGlyphSpacing(int spacing);
+
+ /**
+ * Gets the spacing between letters in pixels.
+ *
+ * @return the spacing.
+ */
+ virtual int getGlyphSpacing();
+
+ /**
+ * Sets the use of anti aliasing..
+ *
+ * @param antaAlias true for use of antia aliasing.
+ */
+ virtual void setAntiAlias(bool antiAlias);
+
+ /**
+ * Checks if anti aliasing is used.
+ *
+ * @return true if anti aliasing is used.
+ */
+ virtual bool isAntiAlias();
+
+
+ // Inherited from Font
+
+ virtual int getWidth(const std::string& text) const;
+
+ virtual int getHeight() const;
+
+ virtual void drawString(gcn::Graphics* graphics, const std::string& text, int x, int y);
+
+ protected:
+ TTF_Font *mFont;
+
+ int mHeight;
+ int mGlyphSpacing;
+ int mRowSpacing;
+
+ std::string mFilename;
+ bool mAntiAlias;
+ };
+ }
+}
+
+#endif
+