mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Prepare a font system
This commit is contained in:
parent
ab88884351
commit
4056c5bde6
2 changed files with 125 additions and 0 deletions
76
src/font.c
Normal file
76
src/font.c
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
// SONIC ROBO BLAST 2
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Copyright (C) 1999-2018 by Sonic Team Junior.
|
||||||
|
// Copyright (C) 2019 by Kart Krew.
|
||||||
|
//
|
||||||
|
// This program is free software distributed under the
|
||||||
|
// terms of the GNU General Public License, version 2.
|
||||||
|
// See the 'LICENSE' file for more details.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
/// \file font.c
|
||||||
|
/// \brief Font setup
|
||||||
|
|
||||||
|
#include "doomdef.h"
|
||||||
|
#include "hu_stuff.h"
|
||||||
|
#include "font.h"
|
||||||
|
|
||||||
|
font_t fontv[MAX_FONTS];
|
||||||
|
int fontc;
|
||||||
|
|
||||||
|
static void
|
||||||
|
FontCache (font_t *fnt)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int c;
|
||||||
|
|
||||||
|
c = fnt->start;
|
||||||
|
for (i = 0; i < fnt->size; ++i, ++c)
|
||||||
|
{
|
||||||
|
fnt->font[i] = HU_CachePatch(
|
||||||
|
"%s%.*d",
|
||||||
|
fnt->digits,
|
||||||
|
fnt->prefix,
|
||||||
|
c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Font_Load (void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < fontc; ++i)
|
||||||
|
{
|
||||||
|
FontCache(&fontv[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
Font_DumbRegister (const font_t *sfnt)
|
||||||
|
{
|
||||||
|
font_t *fnt;
|
||||||
|
|
||||||
|
if (fontc == MAX_FONTS)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
fnt = &fontv[fontc];
|
||||||
|
|
||||||
|
if (!( fnt->font = ZZ_Alloc(sfnt->size * sizeof (patch_t *)) ))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
memcpy(fnt, sfnt, sizeof (font_t));
|
||||||
|
|
||||||
|
return fontc++;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
Font_Register (const font_t *sfnt)
|
||||||
|
{
|
||||||
|
int d;
|
||||||
|
|
||||||
|
d = Font_DumbRegister(sfnt);
|
||||||
|
|
||||||
|
if (d >= 0)
|
||||||
|
FontCache(&fontv[d]);
|
||||||
|
|
||||||
|
return d;
|
||||||
|
}
|
||||||
49
src/font.h
Normal file
49
src/font.h
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
// SONIC ROBO BLAST 2
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Copyright (C) 1999-2018 by Sonic Team Junior.
|
||||||
|
// Copyright (C) 2019 by Kart Krew.
|
||||||
|
//
|
||||||
|
// This program is free software distributed under the
|
||||||
|
// terms of the GNU General Public License, version 2.
|
||||||
|
// See the 'LICENSE' file for more details.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
/// \file font.h
|
||||||
|
/// \brief Font setup
|
||||||
|
|
||||||
|
#ifndef __FONT_H_
|
||||||
|
#define __FONT_H__
|
||||||
|
|
||||||
|
#define MAX_FONTS 32
|
||||||
|
|
||||||
|
typedef struct font font_t;
|
||||||
|
|
||||||
|
struct font
|
||||||
|
{
|
||||||
|
patch_t **font;
|
||||||
|
|
||||||
|
UINT8 start;
|
||||||
|
UINT8 size;
|
||||||
|
|
||||||
|
char prefix[8];/* 7 used at most */
|
||||||
|
unsigned digits : 2;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern font_t fontv[MAX_FONTS];
|
||||||
|
extern int fontc;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Reloads already registered fonts.
|
||||||
|
*/
|
||||||
|
void Font_Load (void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Registers and loads a new font.
|
||||||
|
*/
|
||||||
|
int Font_Register (const font_t *);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Register a new font, but do not load it yet.
|
||||||
|
*/
|
||||||
|
int Font_DumbRegister (const font_t *);
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Add table
Reference in a new issue