____                _       __
    / __ )____  _____   | |     / /___ ___________
   / __  / __ \/ ___/   | | /| / / __ `/ ___/ ___/
  / /_/ / /_/ (__  )    | |/ |/ / /_/ / /  (__  )
 /_____/\____/____/     |__/|__/\__,_/_/  /____/

       A futuristic real-time strategy game.
          This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project. Distributed under the "GNU General Public License"

font.cpp File Reference

The color fonts. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stratagus.h"
#include <string>
#include <vector>
#include <map>
#include "video.h"
#include "font.h"
#include "script.h"
#include "intern_video.h"

Go to the source code of this file.

Functions

static void VideoDrawChar (const CGraphic *g, int gx, int gy, int w, int h, int x, int y)
void SetDefaultTextColors (const std::string &normal, const std::string &reverse)
 < Set the default text colors for normal and reverse text
void GetDefaultTextColors (std::string &normalp, std::string &reversep)
 Draw text unclipped.
static bool GetUTF8 (const std::string &text, size_t &pos, int &utf8)
int convertKey (const char *key)
int GetHotKey (const std::string &text)
 Load and initialize the fonts.
static void VideoDrawCharClip (const CGraphic *g, int gx, int gy, int w, int h, int x, int y)
static int DoDrawText (int x, int y, CFont *font, const std::string &text, bool clip)
int VideoDrawText (int x, int y, CFont *font, const std::string &text)
 Draw text unclipped.
int VideoDrawTextClip (int x, int y, CFont *font, const std::string &text)
 Draw reverse text unclipped.
int VideoDrawReverseText (int x, int y, CFont *font, const std::string &text)
 Draw reverse text clipped.
int VideoDrawReverseTextClip (int x, int y, CFont *font, const std::string &text)
 Draw text centered and unclipped.
int VideoDrawTextCentered (int x, int y, CFont *font, const std::string &text)
 Draw number unclipped.
static void FormatNumber (int number, char *buf)
int VideoDrawNumber (int x, int y, CFont *font, int number)
 Draw number clipped.
int VideoDrawNumberClip (int x, int y, CFont *font, int number)
 Draw reverse number unclipped.
int VideoDrawReverseNumber (int x, int y, CFont *font, int number)
 Draw reverse number clipped.
int VideoDrawReverseNumberClip (int x, int y, CFont *font, int number)
 Get the hot key from a string.
void MakeFontColorTextures (CFont *font)
void LoadFonts ()
 Free OpenGL fonts.
void FreeOpenGLFonts ()
 Reload OpenGL fonts.
void ReloadFonts ()
 Cleanup the font module.
void CleanFonts ()

Variables

static std::vector< CFont * > AllFonts
 Vector of all fonts.
static std::map< std::string,
CFont * > 
Fonts
 Font mappings.
static std::vector< CFontColor * > AllFontColors
 Vector of all font colors.
std::map< std::string,
CFontColor * > 
FontColors
 Map of ident to font color.
static CFontColorFontColor
 Current font color.
static CFontColorLastTextColor
 Last text color.
static CFontColorDefaultTextColor
 Default text color.
static CFontColorReverseTextColor
 Reverse text color.
static std::string DefaultNormalColorIndex
 Default normal color index.
static std::string DefaultReverseColorIndex
 Default reverse color index.
static std::map< CFont
*, std::map< CFontColor
*, CGraphic * > > 
FontColorGraphics
CFontSmallFont
 Small font used in stats.
CFontGameFont
 Normal font used in game.
CFontLargeFont
 Large font used in menus.


Detailed Description

The color fonts.

Definition in file font.cpp.


Function Documentation

void CleanFonts ( void   ) 

Clean up the font module.

Definition at line 902 of file font.cpp.

References AllFontColors, AllFonts, FontColorGraphics, FontColors, Fonts, int(), CGraphic::NumTextures, CGraphic::Textures, and UseOpenGL.

Referenced by CleanModules().

int convertKey ( const char *  key  ) 

static int DoDrawText ( int  x,
int  y,
CFont font,
const std::string &  text,
bool  clip 
) [static]

Draw text with font at x,y clipped/unclipped.

~ is special prefix. ~~ is the ~ character self. ~! print next character reverse. ~< start reverse. ~> switch back to last used color.

Parameters:
x X screen position
y Y screen position
font Font number
text Text to be displayed.
clip Flag to clip the text.
Returns:
The length of the printed text.

Definition at line 349 of file font.cpp.

References Assert, CFont::CharWidth, DebugPrint, FontColorGraphics, CFont::G, CFontColor::Get(), GetUTF8(), CGraphic::GraphicHeight, CGraphic::GraphicWidth, CGraphic::Height, int(), UseOpenGL, VideoDrawChar(), VideoDrawCharClip(), and CGraphic::Width.

Referenced by VideoDrawText(), and VideoDrawTextClip().

static void FormatNumber ( int  number,
char *  buf 
) [static]

Format a number using commas

Parameters:
number Number to be formatted
buf Buffer to save the formatted number to

Definition at line 573 of file font.cpp.

References int(), and sprintf_s().

Referenced by VideoDrawNumber(), VideoDrawNumberClip(), VideoDrawReverseNumber(), and VideoDrawReverseNumberClip().

void FreeOpenGLFonts (  ) 

Reload OpenGL fonts.

Free OpenGL fonts

Definition at line 774 of file font.cpp.

References AllFontColors, AllFonts, FontColorGraphics, CFont::G, int(), CGraphic::NumTextures, and CGraphic::Textures.

Referenced by CVideo::ResizeScreen().

void GetDefaultTextColors ( std::string &  normalp,
std::string &  reversep 
)

Draw text unclipped.

Get the default text colors.

Parameters:
normalp Normal text color pointer.
reversep Reverse text color pointer.

Definition at line 161 of file font.cpp.

References DefaultNormalColorIndex, and DefaultReverseColorIndex.

Referenced by DrawInfoPanelNoneSelected(), DrawMenuButton(), DrawPopup(), StartEditor(), and StartMap().

int GetHotKey ( const std::string &  text  ) 

Load and initialize the fonts.

Get the hot key from a string

Definition at line 264 of file font.cpp.

References convertKey(), and GetUTF8().

Referenced by AddButton(), and ButtonWidget::ButtonWidget().

static bool GetUTF8 ( const std::string &  text,
size_t &  pos,
int &  utf8 
) [static]

Get the next utf8 character from a string

Definition at line 170 of file font.cpp.

References DebugPrint.

Referenced by DoDrawText(), GetHotKey(), and CFont::Width().

void LoadFonts (  ) 

Free OpenGL fonts.

Load all fonts.

Definition at line 750 of file font.cpp.

References AllFonts, CGraphic::File, CFont::G, CFont::Get(), int(), CGraphic::Load(), MakeFontColorTextures(), ShowLoadProgress(), and UseOpenGL.

Referenced by LoadGame(), LoadModules(), main1(), and PreMenuSetup().

void MakeFontColorTextures ( CFont font  ) 

void ReloadFonts ( void   ) 

Cleanup the font module.

Reload OpenGL fonts

Definition at line 790 of file font.cpp.

References AllFontColors, AllFonts, FontColorGraphics, CFont::G, int(), MakeFontColorTextures(), and CGraphic::Textures.

Referenced by ReloadOpenGL().

void SetDefaultTextColors ( const std::string &  normal,
const std::string &  reverse 
)

< Set the default text colors for normal and reverse text

Set the default text colors.

Parameters:
normal Normal text color.
reverse Reverse text color.

Definition at line 147 of file font.cpp.

References DefaultNormalColorIndex, DefaultReverseColorIndex, and CFontColor::Get().

Referenced by CreateGame(), DrawInfoPanelNoneSelected(), DrawMenuButton(), DrawPopup(), LoadGame(), LoadModules(), main1(), PreMenuSetup(), StartEditor(), and StartMap().

static void VideoDrawChar ( const CGraphic g,
int  gx,
int  gy,
int  w,
int  h,
int  x,
int  y 
) [static]

Draw character with current color.

Parameters:
g Pointer to object
gx X offset into object
gy Y offset into object
w width to display
h height to display
x X screen position
y Y screen position

Definition at line 127 of file font.cpp.

References CFontColor::Colors, CGraphic::DrawSub(), MaxFontColors, CGraphic::Surface, TheScreen, and UseOpenGL.

Referenced by DoDrawText(), and VideoDrawCharClip().

static void VideoDrawCharClip ( const CGraphic g,
int  gx,
int  gy,
int  w,
int  h,
int  x,
int  y 
) [static]

Draw character with current color clipped into 8 bit framebuffer.

Parameters:
g Pointer to object
gx X offset into object
gy Y offset into object
w width to display
h height to display
x X screen position
y Y screen position

Definition at line 322 of file font.cpp.

References CLIP_RECTANGLE_OFS, and VideoDrawChar().

Referenced by DoDrawText().

int VideoDrawNumber ( int  x,
int  y,
CFont font,
int  number 
)

Draw number clipped.

Draw number with font at x,y unclipped.

Parameters:
x X screen position
y Y screen position
font Font number
number Number to be displayed.
Returns:
The length of the printed text.

Definition at line 601 of file font.cpp.

References FormatNumber(), int(), and VideoDrawText().

Referenced by DrawCosts(), DrawInfoPanelNoneSelected(), and DrawPopup().

int VideoDrawNumberClip ( int  x,
int  y,
CFont font,
int  number 
)

Draw reverse number unclipped.

Draw number with font at x,y clipped.

Parameters:
x X screen position
y Y screen position
font Font number
number Number to be displayed.
Returns:
The length of the printed text.

Definition at line 619 of file font.cpp.

References FormatNumber(), int(), and VideoDrawTextClip().

Referenced by DrawDecoration(), and Missile::DrawMissile().

int VideoDrawReverseNumber ( int  x,
int  y,
CFont font,
int  number 
)

Draw reverse number clipped.

Draw reverse number with font at x,y unclipped.

Parameters:
x X screen position
y Y screen position
font Font number
number Number to be displayed.
Returns:
The length of the printed text.

Definition at line 637 of file font.cpp.

References FormatNumber(), int(), and VideoDrawReverseText().

int VideoDrawReverseNumberClip ( int  x,
int  y,
CFont font,
int  number 
)

Get the hot key from a string.

Draw reverse number with font at x,y clipped.

Parameters:
x X screen position
y Y screen position
font Font number
number Number to be displayed.
Returns:
The length of the printed text.

Definition at line 655 of file font.cpp.

References FormatNumber(), int(), and VideoDrawReverseTextClip().

int VideoDrawReverseText ( int  x,
int  y,
CFont font,
const std::string &  text 
)

Draw reverse text clipped.

Draw reverse text with font at x,y unclipped.

See also:
DoDrawText for full description.
Parameters:
x X screen position
y Y screen position
font Font number
text Text to be displayed.
Returns:
The length of the printed text.

Definition at line 511 of file font.cpp.

References VideoDrawText().

Referenced by VideoDrawReverseNumber().

int VideoDrawReverseTextClip ( int  x,
int  y,
CFont font,
const std::string &  text 
)

Draw text centered and unclipped.

Draw reverse text with font at x,y clipped.

See also:
DoDrawText for full description.
Parameters:
x X screen position
y Y screen position
font Font number
text Text to be displayed.
Returns:
The length of the printed text.

Definition at line 534 of file font.cpp.

References VideoDrawTextClip().

Referenced by VideoDrawReverseNumberClip().

int VideoDrawText ( int  x,
int  y,
CFont font,
const std::string &  text 
)

Draw text unclipped.

Draw text with font at x,y unclipped.

See also:
DoDrawText
Parameters:
x X screen position
y Y screen position
font Font number
text Text to be displayed.
Returns:
The length of the printed text.

Definition at line 477 of file font.cpp.

References DoDrawText().

Referenced by DrawInfoPanelMultipleSelected(), DrawInfoPanelNoneSelected(), DrawMenuButton(), DrawPlayers(), DrawPopup(), DrawResources(), DrawTimer(), DrawTrainingUnits(), DrawUnitStats(), ShowTitleImage(), VideoDrawNumber(), VideoDrawReverseText(), and VideoDrawTextCentered().

int VideoDrawTextCentered ( int  x,
int  y,
CFont font,
const std::string &  text 
)

Draw number unclipped.

Draw text with font at x,y centered.

See also:
DoDrawText for full description.
Parameters:
x X screen position
y Y screen position
font Font number
text Text to be displayed.
Returns:
The length of the printed text.

Definition at line 557 of file font.cpp.

References VideoDrawText(), and CFont::Width().

Referenced by DrawCoordinates(), DrawMenuButton(), DrawPlayers(), DrawTrainingUnits(), DrawUnitInfo(), DrawUnitStats(), and ShowLoadProgress().

int VideoDrawTextClip ( int  x,
int  y,
CFont font,
const std::string &  text 
)

Draw reverse text unclipped.

Draw text with font at x,y clipped.

See also:
DoDrawText.
Parameters:
x X screen position
y Y screen position
font Font number
text Text to be displayed.
Returns:
The length of the printed text.

Definition at line 494 of file font.cpp.

References DoDrawText().

Referenced by CStatusLine::Draw(), DrawInformations(), MessagesDisplay::DrawMessages(), DrawPieMenu(), CFont::drawString(), VideoDrawNumberClip(), and VideoDrawReverseTextClip().


Variable Documentation

std::vector<CFontColor *> AllFontColors [static]

Vector of all font colors.

Definition at line 58 of file font.cpp.

Referenced by CleanFonts(), FreeOpenGLFonts(), MakeFontColorTextures(), CFontColor::New(), and ReloadFonts().

std::vector<CFont *> AllFonts [static]

Vector of all fonts.

Definition at line 55 of file font.cpp.

Referenced by CleanFonts(), FreeOpenGLFonts(), LoadFonts(), CFont::New(), and ReloadFonts().

std::string DefaultNormalColorIndex [static]

Default normal color index.

Definition at line 66 of file font.cpp.

Referenced by GetDefaultTextColors(), and SetDefaultTextColors().

std::string DefaultReverseColorIndex [static]

Default reverse color index.

Definition at line 67 of file font.cpp.

Referenced by GetDefaultTextColors(), and SetDefaultTextColors().

Default text color.

Definition at line 64 of file font.cpp.

CFontColor* FontColor [static]

Current font color.

Definition at line 61 of file font.cpp.

std::map<CFont *, std::map<CFontColor *, CGraphic *> > FontColorGraphics [static]

Font color graphics Usage: FontColorGraphics[CFont *font][CFontColor *color]

Definition at line 73 of file font.cpp.

Referenced by CleanFonts(), DoDrawText(), FreeOpenGLFonts(), MakeFontColorTextures(), and ReloadFonts().

std::map<std::string, CFontColor *> FontColors

Map of ident to font color.

Definition at line 59 of file font.cpp.

Referenced by CleanFonts(), CFontColor::Get(), and CFontColor::New().

std::map<std::string, CFont *> Fonts [static]

Font mappings.

Definition at line 56 of file font.cpp.

Referenced by CleanFonts(), CFont::Get(), and CFont::New().

Large font used in menus.

Definition at line 78 of file font.cpp.

Last text color.

Definition at line 63 of file font.cpp.

Reverse text color.

Definition at line 65 of file font.cpp.

Small font used in stats.

Font selector for the font functions. FIXME: should be moved to lua

Definition at line 76 of file font.cpp.

Referenced by DrawPlayers(), DrawPopup(), and DrawUnitInfo().


Generated on Sat Feb 21 00:28:16 2009 for Bos Wars by  doxygen 1.5.6