gzdoom/src/v_font.h

154 lines
4.3 KiB
C
Raw Normal View History

2016-03-01 15:47:10 +00:00
/*
** v_font.h
**
**---------------------------------------------------------------------------
** Copyright 1998-2008 Randy Heit
** All rights reserved.
**
** 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. The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 __V_FONT_H__
#define __V_FONT_H__
#include "doomtype.h"
class DCanvas;
struct FRemapTable;
class FTexture;
2017-02-10 10:44:46 +00:00
enum EColorRange : int
2016-03-01 15:47:10 +00:00
{
CR_UNDEFINED = -1,
CR_BRICK,
CR_TAN,
CR_GRAY,
CR_GREY = CR_GRAY,
CR_GREEN,
CR_BROWN,
CR_GOLD,
CR_RED,
CR_BLUE,
CR_ORANGE,
CR_WHITE,
CR_YELLOW,
CR_UNTRANSLATED,
CR_BLACK,
CR_LIGHTBLUE,
CR_CREAM,
CR_OLIVE,
CR_DARKGREEN,
CR_DARKRED,
CR_DARKBROWN,
CR_PURPLE,
CR_DARKGRAY,
CR_CYAN,
CR_ICE,
CR_FIRE,
CR_SAPPHIRE,
CR_TEAL,
NUM_TEXT_COLORS,
2016-03-01 15:47:10 +00:00
};
extern int NumTextColors;
class FFont
{
public:
FFont (const char *fontname, const char *nametemplate, int first, int count, int base, int fdlump, int spacewidth=-1, bool notranslate = false);
2016-03-01 15:47:10 +00:00
virtual ~FFont ();
virtual FTexture *GetChar (int code, int *const width) const;
virtual int GetCharWidth (int code) const;
FRemapTable *GetColorTranslation (EColorRange range, PalEntry *color = nullptr) const;
2016-03-01 15:47:10 +00:00
int GetLump() const { return Lump; }
int GetSpaceWidth () const { return SpaceWidth; }
int GetHeight () const { return FontHeight; }
int GetDefaultKerning () const { return GlobalKerning; }
virtual void LoadTranslations();
FName GetName() const { return FontName; }
2016-03-01 15:47:10 +00:00
static FFont *FindFont(FName fontname);
2016-03-01 15:47:10 +00:00
// Return width of string in pixels (unscaled)
2017-03-08 17:47:52 +00:00
int StringWidth (const uint8_t *str) const;
inline int StringWidth (const char *str) const { return StringWidth ((const uint8_t *)str); }
inline int StringWidth (const FString &str) const { return StringWidth ((const uint8_t *)str.GetChars()); }
2016-03-01 15:47:10 +00:00
int GetCharCode(int code, bool needpic) const;
char GetCursor() const { return Cursor; }
void SetCursor(char c) { Cursor = c; }
bool NoTranslate() const { return noTranslate; }
2016-03-01 15:47:10 +00:00
protected:
FFont (int lump);
2017-03-08 17:47:52 +00:00
void BuildTranslations (const double *luminosity, const uint8_t *identity,
2016-03-01 15:47:10 +00:00
const void *ranges, int total_colors, const PalEntry *palette);
void FixXMoves();
2017-03-08 17:47:52 +00:00
static int SimpleTranslation (uint8_t *colorsused, uint8_t *translation,
uint8_t *identity, double **luminosity);
2016-03-01 15:47:10 +00:00
int FirstChar, LastChar;
int SpaceWidth;
int FontHeight;
int GlobalKerning;
char Cursor;
bool noTranslate;
2016-03-01 15:47:10 +00:00
struct CharData
{
FTexture *Pic;
int XMove;
} *Chars;
int ActiveColors;
TArray<FRemapTable> Ranges;
2017-03-08 17:47:52 +00:00
uint8_t *PatchRemap;
2016-03-01 15:47:10 +00:00
int Lump;
FName FontName;
2016-03-01 15:47:10 +00:00
FFont *Next;
static FFont *FirstFont;
friend struct FontsDeleter;
friend void V_ClearFonts();
};
extern FFont *SmallFont, *SmallFont2, *BigFont, *ConFont, *IntermissionFont;
void V_InitFonts();
void V_ClearFonts();
EColorRange V_FindFontColor (FName name);
PalEntry V_LogColorFromColorRange (EColorRange range);
2017-03-08 17:47:52 +00:00
EColorRange V_ParseFontColor (const uint8_t *&color_value, int normalcolor, int boldcolor);
2016-03-01 15:47:10 +00:00
FFont *V_GetFont(const char *);
void V_InitFontColors();
#endif //__V_FONT_H__