2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2003-11-19 23:46:39 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-11-19 23:46:39 +00:00
|
|
|
*/
|
|
|
|
|
2006-04-15 21:29:41 +00:00
|
|
|
#ifndef GRAPHICS_FONT_H
|
|
|
|
#define GRAPHICS_FONT_H
|
2003-11-19 23:46:39 +00:00
|
|
|
|
2004-03-13 13:03:25 +00:00
|
|
|
#include "common/str.h"
|
|
|
|
|
2006-04-14 02:16:55 +00:00
|
|
|
namespace Common {
|
2011-04-24 08:34:27 +00:00
|
|
|
template<class T> class Array;
|
2006-04-14 02:16:55 +00:00
|
|
|
}
|
|
|
|
|
2004-03-21 21:20:25 +00:00
|
|
|
namespace Graphics {
|
2003-11-19 23:46:39 +00:00
|
|
|
|
2011-04-24 08:34:27 +00:00
|
|
|
struct Surface;
|
|
|
|
|
2008-11-12 14:30:16 +00:00
|
|
|
/** Text alignment modes */
|
|
|
|
enum TextAlign {
|
2009-06-06 17:51:41 +00:00
|
|
|
kTextAlignInvalid,
|
2011-01-07 12:43:00 +00:00
|
|
|
kTextAlignLeft, ///< Text should be aligned to the left
|
|
|
|
kTextAlignCenter, ///< Text should be centered
|
|
|
|
kTextAlignRight ///< Text should be aligned to the right
|
2004-03-13 13:03:25 +00:00
|
|
|
};
|
|
|
|
|
2004-03-15 18:44:14 +00:00
|
|
|
/**
|
|
|
|
* Instances of this class represent a distinct font, with a built-in renderer.
|
2005-01-06 19:09:34 +00:00
|
|
|
* @todo Maybe move the high-level methods (drawString etc.) to a separate
|
2004-03-15 18:44:14 +00:00
|
|
|
* FontRenderer class? That way, we could have different variants... ?
|
|
|
|
*/
|
2004-03-13 13:03:25 +00:00
|
|
|
class Font {
|
|
|
|
public:
|
2005-06-20 17:59:00 +00:00
|
|
|
Font() {}
|
|
|
|
virtual ~Font() {}
|
|
|
|
|
2011-01-07 12:43:00 +00:00
|
|
|
/**
|
|
|
|
* Query the height of the font.
|
|
|
|
*
|
|
|
|
* @return font height.
|
|
|
|
*/
|
2004-03-13 13:03:25 +00:00
|
|
|
virtual int getFontHeight() const = 0;
|
2011-01-07 12:43:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Query the maximum width of the font.
|
|
|
|
*
|
|
|
|
* @return maximum font width.
|
|
|
|
*/
|
2004-03-13 13:03:25 +00:00
|
|
|
virtual int getMaxCharWidth() const = 0;
|
|
|
|
|
2011-01-07 12:43:00 +00:00
|
|
|
/**
|
|
|
|
* Query the width of a specific character.
|
|
|
|
*
|
|
|
|
* @param chr The character to query the width of.
|
|
|
|
* @return The character's width.
|
|
|
|
*/
|
2004-03-13 13:03:25 +00:00
|
|
|
virtual int getCharWidth(byte chr) const = 0;
|
2011-01-07 12:43:00 +00:00
|
|
|
|
2012-01-08 01:33:34 +00:00
|
|
|
/**
|
|
|
|
* Query the kerning offset between two characters.
|
|
|
|
*
|
|
|
|
* @param left The left character. May be 0.
|
|
|
|
* @param right The right character. May be 0.
|
|
|
|
* @return The horizontal displacement.
|
|
|
|
*/
|
|
|
|
virtual int getKerningOffset(byte left, byte right) const;
|
|
|
|
|
2011-01-07 12:43:00 +00:00
|
|
|
/**
|
|
|
|
* Draw a character at a specific point on a surface.
|
|
|
|
*
|
|
|
|
* Note that the point describes the top left edge point of the
|
|
|
|
* character's bounding box.
|
|
|
|
*
|
|
|
|
* The Font implemenation should take care of not drawing outside of the
|
|
|
|
* specified surface.
|
|
|
|
*
|
|
|
|
* @param dst The surface to drawn on.
|
|
|
|
* @param chr The character to draw.
|
|
|
|
* @param x The x coordinate where to draw the character.
|
|
|
|
* @param y The y coordinate where to draw the character.
|
|
|
|
* @param color The color of the character.
|
|
|
|
*/
|
2005-05-02 18:00:05 +00:00
|
|
|
virtual void drawChar(Surface *dst, byte chr, int x, int y, uint32 color) const = 0;
|
2004-03-13 13:03:25 +00:00
|
|
|
|
2011-01-07 12:43:00 +00:00
|
|
|
// TODO: Add doxygen comments to this
|
2008-11-12 14:30:16 +00:00
|
|
|
void drawString(Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, TextAlign align = kTextAlignLeft, int deltax = 0, bool useEllipsis = true) const;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-05-15 16:13:52 +00:00
|
|
|
/**
|
|
|
|
* Compute and return the width the string str has when rendered using this font.
|
|
|
|
*/
|
2004-03-13 13:03:25 +00:00
|
|
|
int getStringWidth(const Common::String &str) const;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-05-15 16:13:52 +00:00
|
|
|
/**
|
2010-06-07 17:17:41 +00:00
|
|
|
* Take a text (which may contain newline characters) and word wrap it so that
|
2005-05-15 16:13:52 +00:00
|
|
|
* no text line is wider than maxWidth pixels. If necessary, additional line breaks
|
2010-06-07 17:17:41 +00:00
|
|
|
* are generated, preferably between words (i.e. where whitespaces are).
|
|
|
|
* The resulting lines are appended to the lines string list.
|
2005-07-30 21:11:48 +00:00
|
|
|
* It returns the maximal width of any of the new lines (i.e. a value which is less
|
2005-05-15 16:13:52 +00:00
|
|
|
* or equal to maxWidth).
|
|
|
|
*
|
2011-01-07 12:43:00 +00:00
|
|
|
* @param str the string to word wrap
|
|
|
|
* @param maxWidth the maximum width a line may have
|
|
|
|
* @param lines the string list to which the text lines from str are appended
|
2005-05-15 16:13:52 +00:00
|
|
|
* @return the maximal width of any of the lines added to lines
|
|
|
|
*/
|
2010-03-18 15:09:24 +00:00
|
|
|
int wordWrapText(const Common::String &str, int maxWidth, Common::Array<Common::String> &lines) const;
|
2004-03-13 13:03:25 +00:00
|
|
|
};
|
|
|
|
|
2004-03-21 21:20:25 +00:00
|
|
|
} // End of namespace Graphics
|
2003-11-19 23:46:39 +00:00
|
|
|
|
|
|
|
#endif
|