cpp_photon/include/video/Font.hpp

148 lines
3.6 KiB
C++
Raw Normal View History

2005-06-29 04:30:40 +00:00
//This file is part of Photon (http://photon.sourceforge.net)
//Copyright (C) 2004-2005 James Turk
//
// Author:
// James Turk (jpt2433@rit.edu)
//
// Version:
2005-07-17 07:14:09 +00:00
// $Id: Font.hpp,v 1.5 2005/07/17 07:14:09 cozman Exp $
2005-06-29 04:30:40 +00:00
#ifndef PHOTON_VIDEO_FONT_HPP
#define PHOTON_VIDEO_FONT_HPP
#include "video/FontResourceManager.hpp"
#include "ResourceManaged.hpp"
2005-07-17 07:14:09 +00:00
#include "video/Color.hpp"
2005-06-29 04:30:40 +00:00
namespace photon
{
namespace video
{
class StreamFlusher { };
std::ostream& operator<<(std::ostream& os, const StreamFlusher& rhs);
2005-06-29 04:30:40 +00:00
// Class: Font
// Simple OO wrapper around a TrueType font that can be drawn to textures and
// rendered via OpenGL.
//
// Since Font is a child of <ResourceManaged>, all memory management is
// taken care of.
//
// Operators:
// - Font = Font
// - bool : True if font is loaded, false if not.
// - ostream& << Font
class Font: public ResourceManaged<FontResourceManager>
{
// Group: (Con/De)structors
public:
// Function: Font
// Default constructor, initalizes internal state of Font.
Font();
// Function: Font
// Copy constructor, copies another Font.
//
// Parameters:
// rhs - Font to construct copy of.
Font(const Font &rhs);
// Function: Font
// Initializing constructor, loads Font via call to <open>.
//
// Parameters:
// name - Name of the Font <Resource> to open.
//
// See Also:
// <open>
Font(const std::string& name);
// Group: General
public:
// Function: open
// Opens an TrueType font.
//
// Loading is done via FreeType.
2005-06-29 04:30:40 +00:00
//
// Parameters:
// name - Name of the Font <Resource> to open.
void open(const std::string& name);
bool isValid() const;
2005-06-29 04:30:40 +00:00
Font& operator=(const Font &rhs);
operator bool() const;
2005-07-17 07:14:09 +00:00
// Group: Coloring
public:
// Function: setColor
// Set draw color of the font.
//
// Parameters:
// color - <Color> to shade font glyphs when drawn.
void setColor(const Color& color);
// Function: getColor
// Get draw color of the font.
//
// Returns:
// Currently set <Color> to shade font glyphs when drawn.
Color getColor() const;
// Group: Drawing
public:
void drawText(float x, float y, const char *str, ...) const;
void drawText(float x, float y, const std::string& str) const;
std::ostream& beginDraw(float x, float y);
StreamFlusher endDraw();
// Group: Font Metrics
2005-06-29 04:30:40 +00:00
public:
unsigned int calcStringWidth(const std::string& str) const;
unsigned int getHeight() const;
2005-06-29 04:30:40 +00:00
2005-07-04 03:06:48 +00:00
// Group: Resource Creation
public:
// Function: addResource
// Define a new named resource.
// (Ex. Image::addResource("monkey","images/monkey.png") would
// make it so that any attempts to load "monkey" would load the image
// images/monkey.png)
//
// Parameters:
// name - Name to give to resource.
// path - Path of resource data file.
static void addResource(const std::string& name, const std::string& path,
uint size);
// Function: addResource
// Define a new unaliased resource. (name == path).
// (Ex. Image::addResource("images/monkey.png") is essentially the same as
// Image::addResource("images/monkey.png","images/monkey.png")
//
// Parameters:.
// path - Path of resource data file.
static void addResource(const std::string& path, uint size);
2005-06-29 04:30:40 +00:00
private:
// font data
uint texID_;
uint listBase_;
std::vector<ubyte> widths_;
ubyte height_;
// stream drawing stuff
std::ostringstream ss_;
float drawX_;
float drawY_;
2005-07-17 07:14:09 +00:00
// color
Color color_;
2005-06-29 04:30:40 +00:00
};
}
}
#endif //PHOTON_VIDEO_FONT_HPP