2002-12-01 07:56:17 +00:00
|
|
|
/*******************************************************************************
|
2002-12-29 06:50:19 +00:00
|
|
|
This file is Part of the ZEngine Library for 2D game development.
|
|
|
|
Copyright (C) 2002, 2003 James Turk
|
2002-12-01 07:56:17 +00:00
|
|
|
|
2002-12-29 06:50:19 +00:00
|
|
|
Licensed under a BSD-style license.
|
2002-12-01 07:56:17 +00:00
|
|
|
|
2002-12-29 06:50:19 +00:00
|
|
|
The maintainer of this library is James Turk (james@conceptofzero.net)
|
|
|
|
and the home of this Library is http://www.zengine.sourceforge.net
|
2002-12-01 07:56:17 +00:00
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\file ZE_ZFont.h
|
|
|
|
\brief Definition file for ZFont.
|
|
|
|
|
|
|
|
Definition file for ZFont, the basic Font class for ZEngine.
|
2003-05-13 01:30:50 +00:00
|
|
|
<br>$ Id $<br>
|
2003-05-07 20:34:50 +00:00
|
|
|
\author James Turk
|
2002-12-01 07:56:17 +00:00
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef __ze_zfont_h__
|
|
|
|
#define __ze_zfont_h__
|
|
|
|
|
2003-02-10 04:02:38 +00:00
|
|
|
#include "ZE_ZEngine.h"
|
2002-12-01 07:56:17 +00:00
|
|
|
#include "ZE_ZImage.h"
|
|
|
|
|
|
|
|
#ifdef USE_SDL_TTF
|
|
|
|
|
|
|
|
namespace ZE
|
|
|
|
{
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief ZFont class for basic Font use.
|
|
|
|
|
2003-06-06 03:02:55 +00:00
|
|
|
ZFont font container class, class wraps common features of SDL_TTF.
|
2002-12-01 07:56:17 +00:00
|
|
|
**/
|
2003-02-10 04:02:38 +00:00
|
|
|
class ZFont
|
2002-12-01 07:56:17 +00:00
|
|
|
{
|
|
|
|
protected:
|
2003-02-10 04:02:38 +00:00
|
|
|
//! Pointer to ZEngine Object
|
|
|
|
ZEngine* rEngine;
|
2002-12-01 07:56:17 +00:00
|
|
|
//! Pointer to font data.
|
|
|
|
TTF_Font *rFont;
|
|
|
|
//! Filename, for resizing.
|
2003-06-11 00:15:07 +00:00
|
|
|
std::string rFilename;
|
2002-12-01 07:56:17 +00:00
|
|
|
//! SDL_Color for current text color.
|
|
|
|
SDL_Color rColor;
|
|
|
|
//! SDL_Color for background color to be used in shaded draws.
|
|
|
|
SDL_Color rBGColor;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
///////////////////////
|
|
|
|
//Opening and Closing//
|
|
|
|
///////////////////////
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Default Constructor.
|
|
|
|
|
|
|
|
Default Constructor, does nothing.
|
|
|
|
**/
|
|
|
|
ZFont();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Constructor that opens a font with a certain size.
|
|
|
|
|
|
|
|
Constructor simply calls ZFont::Open() with same parameters.
|
|
|
|
\param filename Font to open.
|
|
|
|
\param size Size to use for font.
|
|
|
|
**/
|
2003-06-11 00:15:07 +00:00
|
|
|
ZFont(std::string filename, int size);
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Destructor, frees memory.
|
|
|
|
|
|
|
|
Destructor calls ZFont::Release().
|
|
|
|
**/
|
2003-02-10 04:40:16 +00:00
|
|
|
virtual ~ZFont();
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Opens a font with a certain size.
|
|
|
|
|
|
|
|
Opens a font given a filename and a point size.
|
|
|
|
\param filename Font to open.
|
|
|
|
\param size Size to use for font.
|
|
|
|
**/
|
2003-06-11 00:15:07 +00:00
|
|
|
void Open(std::string filename, int size);
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Release font.
|
|
|
|
|
|
|
|
Release memory held by font.
|
|
|
|
**/
|
|
|
|
void Release();
|
|
|
|
|
|
|
|
////////////////////////
|
|
|
|
//Settings and Drawing//
|
|
|
|
////////////////////////
|
|
|
|
|
|
|
|
/*!
|
2003-06-11 00:15:07 +00:00
|
|
|
\brief Draws a std::string in a color to a ZImage.
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
Draw to a surface in specified color and associate that surface with a ZImage.
|
|
|
|
\param text String to write.
|
|
|
|
\param image ZImage to draw to.
|
|
|
|
**/
|
2003-06-11 00:15:07 +00:00
|
|
|
void DrawText(std::string text, ZImage &image) const;
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
/*!
|
2003-06-11 00:15:07 +00:00
|
|
|
\brief Draws a std::string with a colored background to a ZImage.
|
2002-12-01 07:56:17 +00:00
|
|
|
|
2003-06-11 00:15:07 +00:00
|
|
|
Draw to a surface a std::string with a background of rBGColor and lettering in the normal color and associate that surface with a ZImage.
|
2002-12-01 07:56:17 +00:00
|
|
|
\param text String to write.
|
|
|
|
\param image ZImage to draw to.
|
|
|
|
**/
|
2003-06-11 00:15:07 +00:00
|
|
|
void DrawShadedText(std::string text, ZImage &image) const;
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Set Text rColor.
|
|
|
|
|
|
|
|
Set rColor of Text Output.
|
|
|
|
\param r Red component of color (0-255).
|
|
|
|
\param g Green component of color (0-255).
|
|
|
|
\param b Blue component of color (0-255).
|
|
|
|
**/
|
|
|
|
void SetColor(Uint8 r, Uint8 g, Uint8 b);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Set Background rColor.
|
|
|
|
|
|
|
|
Set rColor of Background for Shaded Draw.
|
|
|
|
\param r Red component of color (0-255).
|
|
|
|
\param g Green component of color (0-255).
|
|
|
|
\param b Blue component of color (0-255).
|
|
|
|
**/
|
|
|
|
void SetBGColor(Uint8 r, Uint8 g, Uint8 b);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Set display format.
|
|
|
|
|
|
|
|
Set display format (bold, italic, underline).
|
|
|
|
\param bold Decides bold setting of font.
|
|
|
|
\param italic Decides italic setting of font.
|
|
|
|
\param underline Decides underline setting of font.
|
|
|
|
**/
|
|
|
|
void SetStyle(bool bold, bool italic, bool underline);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Resize Font.
|
|
|
|
|
|
|
|
Release and Reopen font in new size.
|
|
|
|
\param size New size for font.
|
|
|
|
**/
|
|
|
|
void Resize(int size);
|
|
|
|
|
|
|
|
/////////////
|
|
|
|
//Accessors//
|
|
|
|
/////////////
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Check if file is loaded.
|
|
|
|
|
|
|
|
Check if file is loaded and pointer to data is non-NULL.
|
|
|
|
\return Loaded or Unloaded state of data.
|
|
|
|
**/
|
2003-01-16 05:45:58 +00:00
|
|
|
bool IsLoaded() const;
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Get Bold Setting.
|
|
|
|
|
|
|
|
Check if font output is currently bold.
|
|
|
|
\return True or False state of bold.
|
|
|
|
**/
|
2003-01-16 05:45:58 +00:00
|
|
|
bool IsBold() const;
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Get Italic Setting.
|
|
|
|
|
|
|
|
Check if font output is currently italic.
|
|
|
|
\return True or False state of italic.
|
|
|
|
**/
|
2003-01-16 05:45:58 +00:00
|
|
|
bool IsItalic() const;
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Get Underlined Setting.
|
|
|
|
|
|
|
|
Check if font output is currently underline.
|
|
|
|
\return True or False state of underline.
|
|
|
|
**/
|
2003-01-16 05:45:58 +00:00
|
|
|
bool IsUnderlined() const;
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Get Height of Font.
|
|
|
|
|
|
|
|
Check font height as reported by SDL_ttf.
|
|
|
|
\return Height of font.
|
|
|
|
**/
|
2003-01-16 05:45:58 +00:00
|
|
|
int Height() const;
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Get Line Skip for Font.
|
|
|
|
|
|
|
|
Check font line skip as reported by SDL_ttf.
|
|
|
|
\return Recommended Line Skip of font.
|
|
|
|
**/
|
2003-01-16 05:45:58 +00:00
|
|
|
int LineSkip() const;
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Get String Width.
|
|
|
|
|
|
|
|
Get Width of String in Current Font in Pixels.
|
|
|
|
\param text String to get width of.
|
|
|
|
\return Width of String in Current font.
|
|
|
|
**/
|
2003-06-11 00:15:07 +00:00
|
|
|
int StringWidth(std::string text) const;
|
2002-12-01 07:56:17 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Get String Height.
|
|
|
|
|
|
|
|
Get Height of String in Current Font in Pixels.
|
|
|
|
\param text String to get height of.
|
|
|
|
\return Height of String in Current font.
|
|
|
|
**/
|
2003-06-11 00:15:07 +00:00
|
|
|
int StringHeight(std::string text) const;
|
2002-12-01 07:56:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //USE_SDL_TTF
|
|
|
|
|
|
|
|
#endif //__ze_zfont_h__
|