1
1
forked from 0ad/0ad

# Removed some ancient unused code

This was SVN commit r3758.
This commit is contained in:
Ykkrosh 2006-04-13 21:50:44 +00:00
parent 47880f4213
commit 68d4d6cd77
14 changed files with 2 additions and 1180 deletions

View File

@ -32,7 +32,6 @@ gee@pyro.nu
#include "Pyrogenesis.h"
#include "input.h"
#include "OverlayText.h"
// TODO Gee: Whatever include CRect/CPos/CSize
#include "Overlay.h"

View File

@ -11,8 +11,6 @@ gee@pyro.nu
#include "ps/Font.h"
#include "ogl.h"
// TODO Gee: new
#include "OverlayText.h"
#include "lib/res/graphics/unifont.h"
#include "ps/Hotkey.h"

View File

@ -10,9 +10,6 @@ gee@pyro.nu
#include "ogl.h"
// TODO Gee: new
#include "OverlayText.h"
using namespace std;
//-------------------------------------------------------------------

View File

@ -9,7 +9,6 @@ gee@pyro.nu
#include "GUI.h"
#include "CLogger.h"
#include "Parser.h"
#include "OverlayText.h"
#include <algorithm>
#define LOG_CATEGORY "gui"

View File

@ -1,171 +0,0 @@
//////////////////////////////////////////////////////////////////////////////
// AUTHOR: Michael Reiland
// FILENAME: Error.h
// PURPOSE: Provides a simple Error Mechanism
//
// USEAGE:
// SetError_Long(PS_FAIL,"A Sample Error",__FILE__,__LINE__);
// SetError_Short(PS_FAIL,"A Sample Error");
// TestError(PS_FAIL);
//
// TODO: Figure out how we're going to clean up and exit upon failure of
// SetError()
//
// MODIFIED: 07.20.2003 mreiland
#ifndef _ERROR_H_
#define _ERROR_H_
#include "Singleton.h"
#include "Pyrogenesis.h"
#include <string>
// Used to specify Null pointers.
const int NullPtr = 0;
// Setup error interface
#define IsError() GError.ErrorMechanism_Error()
#define ClearError() GError.ErrorMechanism_ClearError()
#define TestError(TError) GError.ErrorMechanism_TestError(TError)
#define SetError_Short(w,x) GError.ErrorMechanism_SetError(w,x,__FILE__,__LINE__)
#define SetError_Long(w,x,y,z) GError.ErrorMechanism_SetError(w,x,y,z)
#define GetError() GError.ErrorMechanism_GetError()
/****************************************************************************/
// USER DEFINED TYPES //
/****************************************************************************/
//////////////////////////////////////////////////////////////////////////////
//
// NAME: CError
// PURPOSE: Encapsulation of the data for our error framework.
//
class CError
{
public:
PS_RESULT ErrorName; // Actual name of the error
std::string Description; // Description of the error
std::string FileName; // File where the error occured
unsigned int LineNumber; // Line where the file occured
CError()
:ErrorName(NullPtr), LineNumber(-1){;}
};
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// NAME: ErrorMechanism
// PURPOSE: Provides the interface for the Error mechanism we are using. It's
// implemented as a singleton so that only one framework is in
// existence at one time.
//
class ErrorMechanism : Singleton<ErrorMechanism>
{
public:
inline bool ErrorMechanism_Error();
inline void ErrorMechanism_ClearError();
inline bool ErrorMechanism_TestError( PS_RESULT);
inline void ErrorMechanism_SetError(
PS_RESULT,
std::string,
std::string,
unsigned int);
inline CError ErrorMechanism_GetError();
private:
CError ErrorVar;
};
//////////////////////////////////////////////////////////////////////////////
/******************************************************************************/
// FUNCTION DEFINITIONS //
/******************************************************************************/
//////////////////////////////////////////////////////////////////////////////
//
// Tests if an error exists. If so, returns true
//
bool ErrorMechanism::ErrorMechanism_Error()
{
return ( ErrorVar.ErrorName != NullPtr );
}
//////////////////////////////////////////////////////////////////////////////
//
// The error has been dealt with, and needs to be cleared.
//
void ErrorMechanism::ErrorMechanism_ClearError()
{
ErrorVar.ErrorName = NullPtr;
}
//////////////////////////////////////////////////////////////////////////////
//
// Checks if the error passed in is the error that's occurred
//
bool ErrorMechanism::ErrorMechanism_TestError( PS_RESULT TErrorName)
{
return ( ErrorVar.ErrorName == TErrorName );
}
//////////////////////////////////////////////////////////////////////////////
//
// Set's an error that's just occured.
//
void ErrorMechanism::ErrorMechanism_SetError( PS_RESULT TErrorName, std::string TDescription,
std::string TFileName, unsigned int TLineNumber)
{
if( ErrorMechanism::ErrorVar.ErrorName == NullPtr )
{
ErrorVar.ErrorName = TErrorName;
ErrorVar.Description = TDescription;
ErrorVar.FileName = TFileName;
ErrorVar.LineNumber = TLineNumber;
}
else
{
// We need to clean up properly and exit.
exit(EXIT_FAILURE);
}
}
//////////////////////////////////////////////////////////////////////////////
//
// Getter for the error
//
CError ErrorMechanism::ErrorMechanism_GetError()
{
return ErrorVar;
}
#endif

View File

@ -867,13 +867,13 @@ static void LoadUnitUIThunk( const char* path, const DirEnt* UNUSED(ent), void*
{
if ( name.BeforeLast(".") == name ) //this is a directory (contains no ".")
return;
LOG(ERROR, "Unknown rank texture extension (%s)", path);
LOG(ERROR, LOG_CATEGORY, "Unknown rank texture extension (%s)", path);
return;
}
Handle tmp = ogl_tex_load(path);
if (tmp <= 0)
{
LOG(ERROR, "Rank Textures", "loadRankTextures failed on \"%s\"", path);
LOG(ERROR, LOG_CATEGORY, "Rank Textures", "loadRankTextures failed on \"%s\"", path);
return;
}
name.Remove("art/textures/ui/session/icons/"); //Names are relative to this directory

View File

@ -1,368 +0,0 @@
// last modified Thursday, May 08, 2003
#include "precompiled.h"
#if 0
#include "LogFile.h"
#include "lib.h"
#include <sstream>
//-------------------------------------------------
//Add a hyperlink to Link.
//-------------------------------------------------
PS_RESULT CLogFile::AddLink(string LinkText,string Link, string Colour)
{
if(m_IsFileOpen)
{
m_TheFile << "<a href=" << Link << "><font color=" << Colour << ">" << LinkText << "</font></a><br>";
}
else
{
return PS_FAIL;
}
return PS_OK;
}
//-------------------------------------------------
//Standard destructor.
//-------------------------------------------------
CLogFile::~CLogFile()
{
if(m_IsFileOpen)
{
m_TheFile << "</font></body></html>";
m_TheFile.close();
if(m_HasFrame)
{
m_ErrorFile.close();
}
m_IsFileOpen = false;
}
}
//-------------------------------------------------
//Standard constructor.
//-------------------------------------------------
CLogFile::CLogFile()
{
m_CurrentColour = "Black";
m_IsFileOpen = false;
}
//-------------------------------------------------
// Constructor that opens a file.
// 3rd parameter determines whether the error frame is shown.
//-------------------------------------------------
CLogFile::CLogFile(string FileName, string PageTitle, bool WithFrame)
{
Open(FileName,PageTitle,WithFrame);
m_IsFileOpen = true;
}
//-------------------------------------------------
//Closes the open files, if open.
//-------------------------------------------------
PS_RESULT CLogFile::Close()
{
if(m_IsFileOpen)
{
m_CurrentColour = "Black";
m_TheFile << "</font></body></html>";
m_TheFile.close();
if(m_HasFrame)
{
m_ErrorFile.close();
}
m_IsFileOpen = false;
}
else
{
return PS_FAIL;
}
return PS_OK;
}
//-------------------------------------------------
//Inserts a horzontal divide in the page.
//-------------------------------------------------
PS_RESULT CLogFile::InsertDivide()
{
if(m_IsFileOpen)
{
m_TheFile << "<hr>";
}
else
{
return PS_FAIL;
}
return PS_OK;
}
//-------------------------------------------------
//Opens an error file. If WithFrame is true then it constructs a framed page.
//-------------------------------------------------
PS_RESULT CLogFile::Open(string FileName, string PageTitle, bool WithFrame)
{
if(m_IsFileOpen)
return PS_FAIL;
m_HasFrame=false;
m_CurrentColour = "Black";
//If there are no frames then create a normal page.
if(!WithFrame)
{
FileName = FileName + ".html";
m_TheFile.open(FileName.c_str());
m_TheFile << "<html><head><title>" << PageTitle << "</title></head><body><font color = black>";
}
else
{
//Open a temporary file to write the frameset.
ofstream TempStream;
string TempString;
TempString = FileName;
TempString = FileName + ".html";
TempStream.open(TempString.c_str());
FileName = FileName + "b.html";
//Write the proper details to the frame file.
TempStream << "<html><head><title>" << PageTitle << "</title></head>";
TempStream << "<frameset frameborder = 1 framespacing = 1 frameborder=yes border=1 rows=70,*>";
TempStream << "<frame src=ErrorLinks.html name =title scrolling =yes><frame src=";
TempStream << FileName << " name =main scrolling=yes ></frameset>";
TempStream << "</frameset></html>";
TempStream.close();
//Open the two pages to be displayed within the frames.
m_TheFile.open(FileName.c_str());
m_ErrorFile.open("ErrorLinks.html");
m_FileName = FileName.c_str();
//Start writing the two pages that will be displayed.
m_TheFile << "<html><head><title>" << PageTitle << "</title></head><body><font color = black>";
m_ErrorFile << "<html><head><title>" << PageTitle << "</title><BASE TARGET=main></head><body><font color = black>";
m_HasFrame = true;
m_ErrNo = 0;
}
m_IsFileOpen = true;
return PS_OK;
}
//-------------------------------------------------
//Sets the current alignment.
//-------------------------------------------------
PS_RESULT CLogFile::SetAlignment(PS_TEXT_ALIGN Align)
{
if(m_IsFileOpen)
{
switch(Align){
case PS_ALIGN_LEFT:
m_TheFile << "<p align = left>";
break;
case PS_ALIGN_CENTER:
m_TheFile << "<p align = center>";
break;
case PS_ALIGN_RIGHT:
m_TheFile << "<p align = right>";
break;
}
}
else
{
return PS_FAIL;
}
return PS_OK;
}
//-------------------------------------------------
//Changes the current colour.
//-------------------------------------------------
PS_RESULT CLogFile::SetColour(string ColourName)
{
if(m_IsFileOpen)
{
m_CurrentColour = ColourName;
m_TheFile << "</font><font color=" << m_CurrentColour << ">";
}
else
{
return PS_FAIL;
}
return PS_OK;
}
//-------------------------------------------------
//Writes an error, always in red.
//-------------------------------------------------
PS_RESULT CLogFile::WriteError(string Text, PS_DISPLAY_SETTINGS displayOptions)
{
if(m_IsFileOpen)
{
//If there is a frame then add an anchor and link to the appropriate places.
if(m_HasFrame)
{
m_TheFile << "<a name=" << m_ErrNo << "></a>";
m_ErrorFile << "<a href=" << m_FileName << "#" << m_ErrNo << ">Error: " << m_ErrNo << "</a><br>";
m_ErrNo++;
}
m_TheFile << "</font><font color=red>" << Line(displayOptions) << Text << Date(displayOptions) << "</font><font color =" << m_CurrentColour << "><br>";
}
else
{
return PS_FAIL;
}
return PS_OK;
}
PS_RESULT CLogFile::WriteError(string Text, PS_TEXT_ALIGN Align, PS_DISPLAY_SETTINGS displayOptions)
{
if(m_IsFileOpen)
{
SetAlignment(Align);
//If there is a frame then add an anchor and link to the appropriate places.
if(m_HasFrame)
{
m_TheFile << "<a name=" << m_ErrNo << "></a>";
m_ErrorFile << "<a href=" << m_FileName << "#" << m_ErrNo << ">Error: " << m_ErrNo << "</a><br>";
m_ErrNo++;
}
m_TheFile << "</font><font color=red>" << Line(displayOptions) << Text << Date(displayOptions) << "</font></p><font color =" << m_CurrentColour << "><br>";
}
else
{
return PS_FAIL;
}
return PS_OK;
}
//-------------------------------------------------
//Writes a header in larger text.
//-------------------------------------------------
PS_RESULT CLogFile::WriteHeader(string Text, PS_DISPLAY_SETTINGS displayOptions)
{
if(m_IsFileOpen)
{
m_TheFile << "</font><font size=6 color= " << m_CurrentColour << ">"
<< Line(displayOptions) << Text << Date(displayOptions) << "</font><font size =3><br>";
}
else
{
return PS_FAIL;
}
return PS_OK;
}
//-------------------------------------------------
//Writes a header in larger text, with alignment.
//-------------------------------------------------
PS_RESULT CLogFile::WriteHeader(string Text, PS_TEXT_ALIGN Align, PS_DISPLAY_SETTINGS displayOptions)
{
if(m_IsFileOpen)
{
SetAlignment(Align);
m_TheFile << "</font><font size=6 color=" << m_CurrentColour << ">"
<< Line(displayOptions) << Text << Date(displayOptions) << "</font></p><font size =3><br>";
}
else
{
return PS_FAIL;
}
return PS_OK;
}
//-------------------------------------------------
//Write a normal string.
//-------------------------------------------------
PS_RESULT CLogFile::WriteText(string Text, PS_DISPLAY_SETTINGS displayOptions)
{
if(m_IsFileOpen)
{
m_TheFile << Line(displayOptions) << Text << Date(displayOptions) << "<br>";
}
else
{
return PS_FAIL;
}
return PS_OK;
}
//-------------------------------------------------
//Write a normal string, with alignment.
//-------------------------------------------------
PS_RESULT CLogFile::WriteText(string Text, PS_TEXT_ALIGN Align, PS_DISPLAY_SETTINGS displayOptions)
{
if(m_IsFileOpen)
{
SetAlignment(Align);
m_TheFile << Line(displayOptions) << Text << Date(displayOptions) << "</p><br>";
}
else
{
return PS_FAIL;
}
return PS_OK;
}
//-------------------------------------------------
//Retrieve a string to display the line number
//-------------------------------------------------
string CLogFile::Line(const PS_DISPLAY_SETTINGS &options)
{
string lineText;
if (options.displayMode == PS_DISPLAY_MODE_SHOW_LINE_NUMBER )
{
lineText = options.file;
// jw: replaced _itoa. sprintf would be good here :P
std::string str_line;
std::stringstream ss;
ss << options.line;
ss >> str_line;
lineText += ", Line ";
lineText += str_line;
lineText += ": ";
}
return lineText;
}
//-------------------------------------------------
//Retrieve a string to display the date
//-------------------------------------------------
string CLogFile::Date(const PS_DISPLAY_SETTINGS &options)
{
string dateText;
if (options.displayMode == PS_DISPLAY_MODE_SHOW_DATE )
{
dateText = "<font color=#AAAAAA> &nbsp;&nbsp;(";
dateText += options.date;
dateText += ")</font>";
}
return dateText;
}
#endif

View File

@ -1,158 +0,0 @@
/*
Log File Writer.
by Mark Ellis
mark@markdellis.co.uk
--Overview--
Writes specified output to a formatted html file.
--Usage--
First open a file for writing using either the constructor
or the Open() function. Then use the formatting functions to
write to the HTML file. You may use Close() but the destructor
will handle all cleanup of the class.
You can enable a frame at the top of the page that will link to the errors,
this is enabled by passing true as the 3rd parameter when opening.
--More Info--
http://wildfiregames.com/0ad/codepit/tdd/logfile.html
*/
#ifndef LOGFILE_H
#define LOGFILE_H
//--------------------------------------------------------
// Includes / Compiler directives
//--------------------------------------------------------
#include "Pyrogenesis.h"
#include <string>
#include <fstream>
using std::string;
using std::ofstream;
//--------------------------------------------------------
// Macros
//--------------------------------------------------------
// Extra parameters for displaying text
#define PS_SHOW_LINE_NUMBER PS_DISPLAY_SETTINGS ( __LINE__, __FILE__, __DATE__, PS_DISPLAY_MODE_SHOW_LINE_NUMBER )
#define PS_SHOW_DATE PS_DISPLAY_SETTINGS ( __LINE__, __FILE__, __DATE__, PS_DISPLAY_MODE_SHOW_DATE )
#define PS_NONE PS_DISPLAY_SETTINGS ( __LINE__, __FILE__, __DATE__, PS_DISPLAY_MODE_NONE )
//-------------------------------------------------
// Types
//-------------------------------------------------
enum PS_DISPLAY_MODE { PS_DISPLAY_MODE_SHOW_LINE_NUMBER,
PS_DISPLAY_MODE_SHOW_DATE,
PS_DISPLAY_MODE_NONE };
enum PS_TEXT_ALIGN { PS_ALIGN_LEFT, PS_ALIGN_CENTER, PS_ALIGN_RIGHT };
//-------------------------------------------------
// Declarations
//-------------------------------------------------
class PS_DISPLAY_SETTINGS
{
public:
PS_DISPLAY_SETTINGS(int Line, char *File, char *Date, PS_DISPLAY_MODE DisplayMode)
{
line=Line;
file=File;
date=Date;
displayMode=DisplayMode;
}
int line;
char *file;
char *date;
PS_DISPLAY_MODE displayMode;
};
class CLogFile
{
public:
//Standard Constructor and destructor.
CLogFile();
~CLogFile();
CLogFile(string FileName, string PageTitle, bool WithFrame=false);
//Opens a file for output the 3rd parameter can be set to true to enable the error frame.
PS_RESULT Open(string FileName, string PageTitle, bool WithFrame=false);
//Closes the file.
PS_RESULT Close();
//The following functions edit the html file.
//Writes a header to the file.
PS_RESULT WriteHeader(string Text, PS_DISPLAY_SETTINGS displayOptions=PS_NONE);
//Writes a header to the file. Align can be 0=left, 1=centre, 2=left
PS_RESULT WriteHeader(string Text, PS_TEXT_ALIGN Align, PS_DISPLAY_SETTINGS displayOptions=PS_NONE);
//Writes some text to the file.
PS_RESULT WriteText(string Text, PS_DISPLAY_SETTINGS displayOptions=PS_NONE);
//Writes some text at a specified alignment.
PS_RESULT WriteText(string Text, PS_TEXT_ALIGN Align, PS_DISPLAY_SETTINGS displayOptions=PS_NONE);
//Writes an error - in red.
PS_RESULT WriteError(string Text, PS_DISPLAY_SETTINGS displayOptions=PS_NONE);
//Writes an aligned error.
PS_RESULT WriteError(string Text, PS_TEXT_ALIGN Align, PS_DISPLAY_SETTINGS displayOptions=PS_NONE);
//Inserts a page break.
PS_RESULT InsertDivide();
//Sets the current colour to colourname.
PS_RESULT SetColour(string ColourName);
//Adds a hyperlink.
PS_RESULT AddLink(string LinkText, string Link, string Colour);
private:
CLogFile(const CLogFile& init);
CLogFile& operator=(const CLogFile& rhs);
bool m_IsFileOpen; //Is the file open.
bool m_HasFrame; //Have frames been enabled.
ofstream m_TheFile; //The main file.
ofstream m_ErrorFile; //The error link file, used only for frames.
string m_CurrentColour; //The current colour.
string m_FileName; //The name of the main file.
int m_ErrNo; //The error number.
//Sets the current alignment of the text.
PS_RESULT SetAlignment(PS_TEXT_ALIGN Align);
//Writes the current line of text
string Line(const PS_DISPLAY_SETTINGS &options);
//Writes today's date
string Date(const PS_DISPLAY_SETTINGS &options);
};
#endif

View File

@ -1,107 +0,0 @@
#include "precompiled.h"
#include "NPFont.h"
#include "Renderer.h"
NPFont::NPFont()
{
}
NPFont::~NPFont()
{
}
NPFont* NPFont::create(const char* name)
{
// try and open up the file
FILE* fp=fopen(name,"rb");
if (!fp) return 0;
// create a new font
NPFont* font=new NPFont;
// read text metrics
if (fread(&font->_metrics,sizeof(font->_metrics),1,fp)!=1) {
fclose(fp);
delete font;
return 0;
}
// read characters
if (fread(font->_chars,sizeof(CharData)*128,1,fp)!=1) {
fclose(fp);
delete font;
return 0;
}
// read number of rows, cols of characters
if (fread(&font->_numRows,sizeof(font->_numRows),1,fp)!=1) {
fclose(fp);
delete font;
return 0;
}
if (fread(&font->_numCols,sizeof(font->_numCols),1,fp)!=1) {
fclose(fp);
delete font;
return 0;
}
// read texture dimensions
if (fread(&font->_texwidth,sizeof(font->_texwidth),1,fp)!=1) {
fclose(fp);
delete font;
return 0;
}
if (fread(&font->_texheight,sizeof(font->_texheight),1,fp)!=1) {
fclose(fp);
delete font;
return 0;
}
// read texture name
unsigned int namelen;
if (fread(&namelen,sizeof(unsigned int),1,fp)!=1) {
fclose(fp);
delete font;
return 0;
}
CStr texname("fonts/");
for (uint i=0;i<namelen;i++) {
char c;
if (fread(&c,sizeof(char),1,fp)!=1) {
fclose(fp);
delete font;
return 0;
}
texname+=c;
}
font->_texture.SetName((const char*) texname);
// store font name
font->_name=name;
g_Renderer.LoadTexture(&font->_texture,0);
// return created font
return font;
}
// GetOutputStringSize: return the rendered size of given font
void NPFont::GetOutputStringSize(const char* str,int& sx,int& sy)
{
sx=0;
sy=_metrics._height;
int i=0;
while (str && str[i]!='\0') {
const NPFont::CharData& cdata=chardata(str[i]);
const int* cw=&cdata._widthA;
if (cw[0]>0) sx+=cw[0];
sx+=cw[1]+1;
if (cw[2]>0) sx+=cw[2];
i++;
}
}

View File

@ -1,81 +0,0 @@
#ifndef _NPFONT_H
#define _NPFONT_H
// necessary includes
#include "CStr.h"
#include "Texture.h"
#include <cassert>
/////////////////////////////////////////////////////////////////////////////////////////
// NPFont:
class NPFont
{
public:
struct CharData {
int _width; // total width in pixels
int _widthA,_widthB,_widthC; // ABC widths
};
public:
// create - create font from given font file
static NPFont* create(const char* fontfilename);
// destructor
~NPFont();
// accessor for name (font file name)
const char* name() const { return (const char*) _name; }
// accessors for font metrics
int width(int c) const { debug_assert(c>=0 && c<128); return _chars[c]._width; }
int height() const { return _metrics._height; }
int descent() const { return _metrics._descent; }
int maxcharwidth() const { return _metrics._maxcharwidth; }
// accessors for texture data
int textureWidth() const { return _texwidth; }
int textureHeight() const { return _texheight; }
CTexture& texture() { return _texture; }
int numCols() const { return _numCols; }
int numRows() const { return _numRows; }
// accessor for character data
const CharData& chardata(char c) const {
debug_assert( !(c&0x80) ); // only allow 7-bit ASCII
return _chars[(unsigned char)c];
}
void GetOutputStringSize(const char* str,int& sx,int& sy);
private:
// constructor (private - all fonts created through create())
NPFont();
// font name
CStr _name;
// font texture width
int _texwidth;
// font texture height
int _texheight;
// font texture
CTexture _texture;
// font metrics
struct {
int _height;
int _descent;
int _maxcharwidth;
} _metrics;
// number of rows of characters
int _numRows;
// number of columns of characters
int _numCols;
// details about specific characters in this font
CharData _chars[128];
};
/////////////////////////////////////////////////////////////////////////////////////////
#endif

View File

@ -1,105 +0,0 @@
#include "precompiled.h"
#include "NPFontManager.h"
#include "NPFont.h"
#include <algorithm>
#include <cassert>
// the sole instance of the NPFontManager
NPFontManager* NPFontManager::_instance=0;
///////////////////////////////////////////////////////////////////////////////
// instance: return the sole font manager instance
NPFontManager& NPFontManager::instance()
{
if (!_instance) {
_instance=new NPFontManager;
}
return *_instance;
}
///////////////////////////////////////////////////////////////////////////////
// NPFontManager constructor (hidden); access available only through instance()
NPFontManager::NPFontManager()
{
}
///////////////////////////////////////////////////////////////////////////////
// NPFontManager destructor
NPFontManager::~NPFontManager()
{
// delete all collected fonts
for (uint i=0;i<_fonts.size();++i) {
delete _fonts[i];
}
}
///////////////////////////////////////////////////////////////////////////////
// release this font manager
void NPFontManager::release()
{
if (_instance) {
delete _instance;
_instance=0;
}
}
///////////////////////////////////////////////////////////////////////////////
// add a font; return the created font, or 0 if not found
NPFont* NPFontManager::add(const char* name)
{
// try and find font first
NPFont* font=find(name);
if (font) {
// ok - already got this font, return it
return font;
}
// try and create font
font=NPFont::create(name);
if (font) {
// success - add to list
_fonts.push_back(font);
return font;
} else {
// mark as bad? just return failure for the moment
return 0;
}
}
///////////////////////////////////////////////////////////////////////////////
// remove a font
bool NPFontManager::remove(const char* name)
{
// try and find font first
NPFont* font=find(name);
if (!font) {
// font not present ..
return false;
} else {
typedef std::vector<NPFont*>::iterator Iter;
Iter iter=std::find(_fonts.begin(),_fonts.end(),font);
debug_assert(iter != _fonts.end());
_fonts.erase(iter);
}
return true;
}
///////////////////////////////////////////////////////////////////////////////
// find a font (return 0 if not found)
NPFont* NPFontManager::find(const char* name)
{
// scan through font list checking names
for (uint i=0;i<_fonts.size();++i) {
NPFont* font=_fonts[i];
if (strcmp(name,font->name())==0) {
return font;
}
}
// got this far, font not found
return 0;
}

View File

@ -1,39 +0,0 @@
#ifndef _FONTMANAGER_H
#define _FONTMANAGER_H
// necessary includes
#include <vector>
// necessary declaration
class NPFont;
class NPFontManager
{
public:
// accessor; return the font manager
static NPFontManager& instance();
// release this font manager
static void release();
// destructor
~NPFontManager();
// add a font; return the created font, or 0 if not found
NPFont* add(const char* name);
// remove a font
bool remove(const char* name);
// find a font (return 0 if not found)
NPFont* find(const char* name);
private:
// hidden constructor; access available only through instance()
NPFontManager();
// list of recorded fonts
std::vector<NPFont*> _fonts;
// the sole instance of the FontManager
static NPFontManager* _instance;
};
#endif

View File

@ -1,34 +0,0 @@
/*
COverlayText
by Rich Cross
rich@0ad.wildfiregames.com
*/
#include "precompiled.h"
#include "OverlayText.h"
#include "NPFont.h"
#include "NPFontManager.h"
COverlayText::COverlayText()
: m_X(0), m_Y(0), m_Z(0), m_Color(CColor(0,0,0,0)), m_Font(0), m_String("")
{
}
COverlayText::COverlayText(float x,float y,int z,const char* fontname,const char* string,const CColor& color)
: m_X(x), m_Y(y), m_Z(z), m_Color(color), m_String(string)
{
m_Font=NPFontManager::instance().add(fontname);
}
COverlayText::~COverlayText()
{
}
bool COverlayText::GetOutputStringSize(int& sx,int& sy)
{
if (!m_Font) return false;
m_Font->GetOutputStringSize((const char*) m_String,sx,sy);
return true;
}

View File

@ -1,108 +0,0 @@
/*
COverlayText
by Rich Cross, rich@0ad.wildfiregames.com
--Overview--
Class representing 2D screen text overlay
*/
#ifndef COVERLAYTEXT_H
#define COVERLAYTEXT_H
//--------------------------------------------------------
// Includes / Compiler directives
//--------------------------------------------------------
#include "Texture.h"
#include "Overlay.h" // just for CColor at the mo
//--------------------------------------------------------
// Macros
//--------------------------------------------------------
//--------------------------------------------------------
// Types
//--------------------------------------------------------
//--------------------------------------------------------
// Error declarations
//--------------------------------------------------------
//--------------------------------------------------------
// Declarations
//--------------------------------------------------------
class NPFont;
/**
* @author Rich Cross
*
* OverlayText class definition.
*/
class COverlayText
{
public:
/**
* Default constructor; creates an overlay text object that won't actually be renderable
*/
COverlayText();
/**
* Constructor with setup for more common parameters
*/
COverlayText(float x,float y,int z,const char* fontname,const char* string,const CColor& color);
/**
* Destructor
*/
~COverlayText();
/**
* Get position
*/
void GetPosition(float& x,float& y) {
x=m_X;
y=m_Y;
}
/**
* Get depth
*/
int GetZ() const { return m_Z; }
/**
* Get font (not const as Renderer need to modify texture to store handle)
*/
NPFont* GetFont() { return m_Font; }
/**
* Get string to render
*/
const CStr& GetString() const { return m_String; }
/**
* Get color
*/
const CColor& GetColor() const { return m_Color; }
/**
* Get size of this string when rendered; return false if font is invalid and string size cannot
* actually by determined, or true on success
*/
bool GetOutputStringSize(int& sx,int& sy);
private:
/// coordinates to start rendering string
float m_X,m_Y;
/// depth of overlay text, for correctly overlapping overlays; higher z implies in-front-of behaviour
int m_Z;
/// text color
CColor m_Color;
/// pointer to the font to use in rendering out text; not owned by the overlay, never attempt to delete
NPFont* m_Font;
/// actual text string
CStr m_String;
};
#endif