Remove unused font (LargeFont, SmallFontTitle).

Replace global Font by accessor.
This commit is contained in:
Joris 2011-02-27 11:49:24 +01:00
parent 0a316c6464
commit 1c91eb3250
11 changed files with 62 additions and 52 deletions

View file

@ -562,7 +562,7 @@ static void DrawPlayers()
{ {
int i; int i;
char buf[256]; char buf[256];
CLabel label(SmallFont); CLabel label(GetSmallFont());
int x = UI.InfoPanel.X + 8; int x = UI.InfoPanel.X + 8;
int y = UI.InfoPanel.Y + 4 + IconHeight + 10; int y = UI.InfoPanel.Y + 4 + IconHeight + 10;
@ -613,7 +613,7 @@ static void DrawPlayers()
strcat_s(buf, sizeof(buf), "Computer"); strcat_s(buf, sizeof(buf), "Computer");
break; break;
} }
label.SetFont(GameFont); label.SetFont(GetGameFont());
label.Draw(x, y, buf); label.Draw(x, y, buf);
} }
} }
@ -627,7 +627,7 @@ static void DrawPopup() {
std::string nc, rc; std::string nc, rc;
GetDefaultTextColors(nc, rc); GetDefaultTextColors(nc, rc);
DrawPopupUnitInfo(Editor.ShownUnitTypes[Editor.CursorUnitIndex], DrawPopupUnitInfo(Editor.ShownUnitTypes[Editor.CursorUnitIndex],
Editor.SelectedPlayer, SmallFont, Editor.SelectedPlayer, GetSmallFont(),
Video.MapRGB(TheScreen->format, 38, 38, 78), Video.MapRGB(TheScreen->format, 38, 38, 78),
Editor.PopUpX, Editor.PopUpY); Editor.PopUpX, Editor.PopUpY);
SetDefaultTextColors(nc, rc); SetDefaultTextColors(nc, rc);
@ -722,7 +722,7 @@ static void DrawTileIcon(unsigned tilenum, unsigned x, unsigned y, unsigned flag
static void DrawTileIcons() static void DrawTileIcons()
{ {
int i; int i;
CLabel label(GameFont); CLabel label(GetGameFont());
int x = UI.InfoPanel.X + 46; int x = UI.InfoPanel.X + 46;
int y = UI.InfoPanel.Y + 4 + IconHeight + 11; int y = UI.InfoPanel.Y + 4 + IconHeight + 11;
@ -987,7 +987,7 @@ static void DrawEditorInfo()
} }
snprintf(buf, sizeof(buf),"Editor (%d %d)", x, y); snprintf(buf, sizeof(buf),"Editor (%d %d)", x, y);
VideoDrawText(UI.ResourceX + 2, UI.ResourceY + 2, GameFont, buf); VideoDrawText(UI.ResourceX + 2, UI.ResourceY + 2, GetGameFont(), buf);
CMapField *mf = Map.Field(x, y); CMapField *mf = Map.Field(x, y);
// //
// Flags info // Flags info
@ -1008,7 +1008,7 @@ static void DrawEditorInfo()
flags & MapFieldAirUnit ? 'a' : '-', flags & MapFieldAirUnit ? 'a' : '-',
flags & MapFieldSeaUnit ? 's' : '-', flags & MapFieldSeaUnit ? 's' : '-',
flags & MapFieldBuilding ? 'b' : '-'); flags & MapFieldBuilding ? 'b' : '-');
VideoDrawText(UI.ResourceX + 118, UI.ResourceY + 2, GameFont, buf); VideoDrawText(UI.ResourceX + 118, UI.ResourceY + 2, GetGameFont(), buf);
// //
// Tile info // Tile info
@ -1029,7 +1029,7 @@ static void DrawEditorInfo()
? Map.Tileset.SolidTerrainTypes[Map.Tileset.Tiles[i].MixTerrain].TerrainName ? Map.Tileset.SolidTerrainTypes[Map.Tileset.Tiles[i].MixTerrain].TerrainName
: ""); : "");
VideoDrawText(UI.ResourceX + 252, UI.ResourceY + 2, GameFont, buf); VideoDrawText(UI.ResourceX + 252, UI.ResourceY + 2, GetGameFont(), buf);
#endif #endif
} }

View file

@ -158,10 +158,8 @@ public:
** Font selector for the font functions. ** Font selector for the font functions.
** FIXME: should be moved to lua ** FIXME: should be moved to lua
*/ */
extern CFont *SmallFont; /// Small font used in stats extern CFont *GetSmallFont(); /// Small font used in stats
extern CFont *GameFont; /// Normal font used in game extern CFont *GetGameFont(); /// Normal font used in game
extern CFont *LargeFont; /// Large font used in menus
extern CFont *SmallTitleFont; /// Small font used in episoden titles
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
-- Functions -- Functions

View file

@ -316,9 +316,9 @@ void CViewport::DrawMapBackgroundInViewport() const
Video.DrawHLineClip(color, dx, dy, PixelTileSize.x); Video.DrawHLineClip(color, dx, dy, PixelTileSize.x);
Video.DrawVLineClip(color, dx, dy, PixelTileSize.y); Video.DrawVLineClip(color, dx, dy, PixelTileSize.y);
if ( 0 && my_mask ) { if ( 0 && my_mask ) {
CLabel label(SmallFont); CLabel label(GetSmallFont());
label.Draw(dx + 2, dy +2, tile); label.Draw(dx + 2, dy +2, tile);
label.Draw(dx + 2, dy + SmallFont->Height() + 4, label.Draw(dx + 2, dy + GetSmallFont()->Height() + 4,
Map.Fields[sx].TilesetTile ); Map.Fields[sx].TilesetTile );
} }

View file

@ -557,8 +557,8 @@ void MissileDrawProxy::DrawMissile(const CViewport *vp) const
const int y = this->Y - vp->MapY * PixelTileSize.y + vp->Y - vp->OffsetY; const int y = this->Y - vp->MapY * PixelTileSize.y + vp->Y - vp->OffsetY;
switch (this->Type->Class) { switch (this->Type->Class) {
case MissileClassHit: case MissileClassHit:
CLabel(GameFont).DrawClip(x,y, this->data.Damage); CLabel(GetGameFont()).DrawClip(x,y, this->data.Damage);
//VideoDrawNumberClip(x, y, GameFont, this->data.Damage); //VideoDrawNumberClip(x, y, GetGameFont(), this->data.Damage);
break; break;
default: default:
this->Type->DrawMissileType(this->data.SpriteFrame, x, y); this->Type->DrawMissileType(this->data.SpriteFrame, x, y);
@ -596,7 +596,7 @@ void Missile::DrawMissile(const CViewport *vp) const
const int y = this->position.y - vp->MapY * PixelTileSize.y + vp->Y - vp->OffsetY; const int y = this->position.y - vp->MapY * PixelTileSize.y + vp->Y - vp->OffsetY;
switch (this->Type->Class) { switch (this->Type->Class) {
case MissileClassHit: case MissileClassHit:
CLabel(GameFont).DrawClip(x, y, this->Damage); CLabel(GetGameFont()).DrawClip(x, y, this->Damage);
break; break;
default: default:
this->Type->DrawMissileType(this->SpriteFrame, x, y); this->Type->DrawMissileType(this->SpriteFrame, x, y);

View file

@ -289,7 +289,7 @@ void ShowLoadProgress(const char *fmt, ...)
temp[sizeof(temp) - 1] = '\0'; temp[sizeof(temp) - 1] = '\0';
va_end(va); va_end(va);
if (Video.Depth && GameFont && GameFont->IsLoaded()) { if (Video.Depth && GetGameFont() && GetGameFont()->IsLoaded()) {
DisplayAutoLocker autolock; DisplayAutoLocker autolock;
// Remove non printable chars // Remove non printable chars
for (char *s = temp; *s; ++s) { for (char *s = temp; *s; ++s) {
@ -298,7 +298,7 @@ void ShowLoadProgress(const char *fmt, ...)
} }
} }
Video.FillRectangle(ColorBlack, 5, Video.Height - 18, Video.Width - 10, 18); Video.FillRectangle(ColorBlack, 5, Video.Height - 18, Video.Width - 10, 18);
CLabel(GameFont).DrawCentered(Video.Width / 2, Video.Height - 16, temp); CLabel(GetGameFont()).DrawCentered(Video.Width / 2, Video.Height - 16, temp);
InvalidateArea(5, Video.Height - 18, Video.Width - 10, 18); InvalidateArea(5, Video.Height - 18, Video.Width - 10, 18);
RealizeVideoMemory(); RealizeVideoMemory();
} else { } else {

View file

@ -133,7 +133,7 @@ static void ShowTitleImage(TitleScreen *t)
timeout = -1; timeout = -1;
} }
CLabel label(GameFont); CLabel label(GetGameFont());
DisplayAutoLocker autolock; DisplayAutoLocker autolock;
while (timeout-- && WaitNoEvent) { while (timeout-- && WaitNoEvent) {
g->DrawClip((Video.Width - g->Width) / 2, (Video.Height - g->Height) / 2); g->DrawClip((Video.Width - g->Width) / 2, (Video.Height - g->Height) / 2);

View file

@ -479,7 +479,7 @@ static void DrawPopup(const ButtonAction *button, const CUIButton *uibutton)
//Uint32 backgroundColor = Video.MapRGB(TheScreen->format, 255, 255, 200); //Uint32 backgroundColor = Video.MapRGB(TheScreen->format, 255, 255, 200);
//Uint32 backgroundColor = Video.MapRGB(TheScreen->format, 255, 255, 255); //Uint32 backgroundColor = Video.MapRGB(TheScreen->format, 255, 255, 255);
Uint32 backgroundColor = Video.MapRGB(TheScreen->format, 38, 38, 78); Uint32 backgroundColor = Video.MapRGB(TheScreen->format, 38, 38, 78);
CFont *font = SmallFont; CFont *font = GetSmallFont();
const int font_height = font->Height(); const int font_height = font->Height();
int start_x, x, popupWidth; int start_x, x, popupWidth;

View file

@ -567,7 +567,7 @@ static void DrawUnitInfo(CUnit &unit)
int x; int x;
int y; int y;
CUnit *uins; CUnit *uins;
CLabel label(GameFont); CLabel label(GetGameFont());
if (CPU_NUM == 1) { if (CPU_NUM == 1) {
UpdateUnitVariables(unit); UpdateUnitVariables(unit);
@ -741,7 +741,7 @@ void DrawResources()
{ {
int i; int i;
int v; int v;
CLabel label(GameFont); CLabel label(GetGameFont());
// Draw all icons of resource. // Draw all icons of resource.
for (i = 0; i <= ScoreCost; ++i) { for (i = 0; i <= ScoreCost; ++i) {
@ -753,7 +753,7 @@ void DrawResources()
for (i = 0; i < MaxCosts; ++i) { for (i = 0; i < MaxCosts; ++i) {
if (UI.Resources[i].TextX != -1) { if (UI.Resources[i].TextX != -1) {
v = ThisPlayer->Resources[i]; v = ThisPlayer->Resources[i];
label.SetFont(v > 99999 ? SmallFont : GameFont); label.SetFont(v > 99999 ? GetSmallFont() : GetGameFont());
label.Draw(UI.Resources[i].TextX, label.Draw(UI.Resources[i].TextX,
UI.Resources[i].TextY + (v > 99999) * 3, v); UI.Resources[i].TextY + (v > 99999) * 3, v);
} }
@ -761,7 +761,7 @@ void DrawResources()
if (UI.Resources[FoodCost].TextX != -1) { if (UI.Resources[FoodCost].TextX != -1) {
char tmp[128]; char tmp[128];
snprintf(tmp,sizeof(tmp), "%d/%d", ThisPlayer->Demand, ThisPlayer->Supply); snprintf(tmp,sizeof(tmp), "%d/%d", ThisPlayer->Demand, ThisPlayer->Supply);
label.SetFont(GameFont); label.SetFont(GetGameFont());
if (ThisPlayer->Supply < ThisPlayer->Demand) { if (ThisPlayer->Supply < ThisPlayer->Demand) {
label.DrawReverse(UI.Resources[FoodCost].TextX, label.DrawReverse(UI.Resources[FoodCost].TextX,
UI.Resources[FoodCost].TextY, tmp); UI.Resources[FoodCost].TextY, tmp);
@ -772,7 +772,7 @@ void DrawResources()
} }
if (UI.Resources[ScoreCost].TextX != -1) { if (UI.Resources[ScoreCost].TextX != -1) {
v = ThisPlayer->Score; v = ThisPlayer->Score;
label.SetFont(v > 99999 ? SmallFont : GameFont); label.SetFont(v > 99999 ? GetSmallFont() : GetGameFont());
label.Draw(UI.Resources[ScoreCost].TextX, label.Draw(UI.Resources[ScoreCost].TextX,
UI.Resources[ScoreCost].TextY + (v > 99999) * 3, v); UI.Resources[ScoreCost].TextY + (v > 99999) * 3, v);
} }
@ -1256,7 +1256,7 @@ static int Costs[MaxCosts + 1]; /// costs to display in status line
void DrawCosts() void DrawCosts()
{ {
int x = UI.StatusLine.TextX + 268; int x = UI.StatusLine.TextX + 268;
CLabel label(GameFont); CLabel label(GetGameFont());
if (CostsMana) { if (CostsMana) {
// FIXME: hardcoded image!!! // FIXME: hardcoded image!!!
UI.Resources[GoldCost].G->DrawFrameClip(3, x, UI.StatusLine.TextY); UI.Resources[GoldCost].G->DrawFrameClip(3, x, UI.StatusLine.TextY);
@ -1411,11 +1411,11 @@ void CInfoPanel::Draw()
x = UI.InfoPanel.X + 16; x = UI.InfoPanel.X + 16;
y = UI.InfoPanel.Y + 8; y = UI.InfoPanel.Y + 8;
VideoDrawTextClip(x, y, GameFont, "Stratagus"); VideoDrawTextClip(x, y, GetGameFont(), "Stratagus");
y += 16; y += 16;
VideoDrawTextClip(x, y, GameFont, "Cycle:"); VideoDrawTextClip(x, y, GetGameFont(), "Cycle:");
VideoDrawNumberClip(x + 48, y, GameFont, GameCycle); VideoDrawNumberClip(x + 48, y, GetGameFont(), GameCycle);
VideoDrawNumberClip(x + 110, y, GameFont, VideoDrawNumberClip(x + 110, y, GetGameFont(),
CYCLES_PER_SECOND * VideoSyncSpeed / 100); CYCLES_PER_SECOND * VideoSyncSpeed / 100);
y += 20; y += 20;
@ -1430,13 +1430,13 @@ void CInfoPanel::Draw()
SetDefaultTextColors(nc, rc); SetDefaultTextColors(nc, rc);
} }
VideoDrawNumberClip(x + 15, y, GameFont, i); VideoDrawNumberClip(x + 15, y, GetGameFont(), i);
Video.DrawRectangleClip(ColorWhite,x, y, 12, 12); Video.DrawRectangleClip(ColorWhite,x, y, 12, 12);
Video.FillRectangleClip(Players[i].Color, x + 1, y + 1, 10, 10); Video.FillRectangleClip(Players[i].Color, x + 1, y + 1, 10, 10);
VideoDrawTextClip(x + 27, y, GameFont,Players[i].Name); VideoDrawTextClip(x + 27, y, GetGameFont(),Players[i].Name);
VideoDrawNumberClip(x + 117, y, GameFont,Players[i].Score); VideoDrawNumberClip(x + 117, y, GetGameFont(),Players[i].Score);
y += 14; y += 14;
} }
} }
@ -1501,7 +1501,7 @@ static void DrawInfoPanelNoneSelected()
std::string rc; std::string rc;
int x = UI.InfoPanel.X + 16; int x = UI.InfoPanel.X + 16;
int y = UI.InfoPanel.Y + 8; int y = UI.InfoPanel.Y + 8;
CLabel label(GameFont); CLabel label(GetGameFont());
label.Draw(x,y, "Stratagus"); label.Draw(x,y, "Stratagus");
y += 16; y += 16;
@ -1510,7 +1510,7 @@ static void DrawInfoPanelNoneSelected()
label.Draw(x + 110, y, CYCLES_PER_SECOND * VideoSyncSpeed / 100); label.Draw(x + 110, y, CYCLES_PER_SECOND * VideoSyncSpeed / 100);
y += 20; y += 20;
if( y + PlayerMax * GameFont->Height() > Video.Height ) if( y + PlayerMax * GetGameFont()->Height() > Video.Height )
{ {
x = 16; x = 16;
y = 30; y = 30;

View file

@ -2047,7 +2047,7 @@ void DrawPieMenu()
return; return;
} }
ButtonActionProxy buttons(CurrentButtons); ButtonActionProxy buttons(CurrentButtons);
CLabel label(GameFont); CLabel label(GetGameFont());
CViewport *vp = UI.SelectedViewport; CViewport *vp = UI.SelectedViewport;
PushClipping(); PushClipping();
SetClipping(vp->X, vp->Y, vp->EndX, vp->EndY); SetClipping(vp->X, vp->Y, vp->EndX, vp->EndY);

View file

@ -486,7 +486,7 @@ void CDecoVarText::Draw(int x, int y,
const CUnitType *, const CVariable &Variable) const const CUnitType *, const CVariable &Variable) const
{ {
if (this->IsCenteredInX) { if (this->IsCenteredInX) {
x -= 2; // GameFont->Width(buf) / 2, with buf = str(Value) x -= 2; // GetGameFont()->Width(buf) / 2, with buf = str(Value)
} }
if (this->IsCenteredInY) { if (this->IsCenteredInY) {
y -= this->Font->Height() / 2; y -= this->Font->Height() / 2;
@ -575,7 +575,7 @@ static void DrawDecoration(const CUnit &unit, const CUnitType *type, int x, int
// //
// Show the number of references. // Show the number of references.
// //
VideoDrawNumberClip(x + 1, y + 1, GameFont, unit.Refs); VideoDrawNumberClip(x + 1, y + 1, GetGameFont(), unit.Refs);
#endif #endif
UpdateUnitVariables(unit); UpdateUnitVariables(unit);
@ -615,11 +615,11 @@ static void DrawDecoration(const CUnit &unit, const CUnitType *type, int x, int
int groupId = 0; int groupId = 0;
for (groupId = 0; !(unit.GroupId & (1 << groupId)); ++groupId) for (groupId = 0; !(unit.GroupId & (1 << groupId)); ++groupId)
; ;
int width = GameFont->Width(groupId); int width = GetGameFont()->Width(groupId);
x += (unit.Type->TileWidth * PixelTileSize.x + unit.Type->BoxWidth) / 2 - width; x += (unit.Type->TileWidth * PixelTileSize.x + unit.Type->BoxWidth) / 2 - width;
width = GameFont->Height(); width = GetGameFont()->Height();
y += (unit.Type->TileHeight * PixelTileSize.y + unit.Type->BoxHeight) / 2 - width; y += (unit.Type->TileHeight * PixelTileSize.y + unit.Type->BoxHeight) / 2 - width;
CLabel(GameFont).DrawClip(x, y, groupId); CLabel(GetGameFont()).DrawClip(x, y, groupId);
} }
} }
@ -1340,11 +1340,11 @@ void CUnitDrawProxy::DrawDecorationAt(int x, int y) const
&& Player == ThisPlayer && Player == ThisPlayer
#endif #endif
) { ) {
int width = GameFont->Width(GroupId - 1); int width = GetGameFont()->Width(GroupId - 1);
x += (Type->TileWidth * PixelTileSize.x + Type->BoxWidth) / 2 - width; x += (Type->TileWidth * PixelTileSize.x + Type->BoxWidth) / 2 - width;
width = GameFont->Height(); width = GetGameFont()->Height();
y += (Type->TileHeight * PixelTileSize.y + Type->BoxHeight) / 2 - width; y += (Type->TileHeight * PixelTileSize.y + Type->BoxHeight) / 2 - width;
CLabel(GameFont).DrawClip(x, y, GroupId - 1); CLabel(GetGameFont()).DrawClip(x, y, GroupId - 1);
} }
} }

View file

@ -75,13 +75,29 @@ static std::string DefaultReverseColorIndex; /// Default reverse color index
static std::map< const CFont *, std::map<const CFontColor *, CGraphic *> > FontColorGraphics; static std::map< const CFont *, std::map<const CFontColor *, CGraphic *> > FontColorGraphics;
// FIXME: remove these // FIXME: remove these
CFont *SmallFont; /// Small font used in stats static CFont *SmallFont; /// Small font used in stats
CFont *GameFont; /// Normal font used in game static CFont *GameFont; /// Normal font used in game
CFont *LargeFont; /// Large font used in menus
CFont *SmallTitleFont; /// Small font used in episoden titles
static int FormatNumber(int number, char *buf); static int FormatNumber(int number, char *buf);
CFont *GetSmallFont()
{
if (!SmallFont) {
SmallFont = CFont::Get("small");
}
return SmallFont;
}
CFont *GetGameFont()
{
if (!GameFont) {
GameFont = CFont::Get("game");
}
return GameFont;
}
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
-- Guichan Functions -- Guichan Functions
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/
@ -866,8 +882,6 @@ void LoadFonts()
// TODO: remove this // TODO: remove this
SmallFont = CFont::Get("small"); SmallFont = CFont::Get("small");
GameFont = CFont::Get("game"); GameFont = CFont::Get("game");
LargeFont = CFont::Get("large");
SmallTitleFont = CFont::Get("small-title");
} }
void CFont::FreeOpenGL() void CFont::FreeOpenGL()
@ -1056,8 +1070,6 @@ void CleanFonts()
SmallFont = NULL; SmallFont = NULL;
GameFont = NULL; GameFont = NULL;
LargeFont = NULL;
SmallTitleFont = NULL;
} }
//@} //@}