2006-03-20 16:43:15 +00:00
|
|
|
/*
|
2014-06-01 17:55:23 +00:00
|
|
|
* Portions of this file are copyright Rebirth contributors and licensed as
|
|
|
|
* described in COPYING.txt.
|
|
|
|
* Portions of this file are copyright Parallax Software and licensed
|
|
|
|
* according to the Parallax license below.
|
|
|
|
* See COPYING.txt for license details.
|
|
|
|
|
2006-03-20 16:43:15 +00:00
|
|
|
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
|
|
|
|
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
|
|
|
|
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
|
|
|
|
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
|
|
|
|
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
|
|
|
|
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
|
|
|
|
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
|
|
|
|
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
|
2013-02-24 02:39:48 +00:00
|
|
|
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
2006-03-20 16:43:15 +00:00
|
|
|
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|
|
|
*/
|
2008-02-24 14:41:27 +00:00
|
|
|
|
2006-03-20 16:43:15 +00:00
|
|
|
/*
|
|
|
|
*
|
2007-07-15 15:23:45 +00:00
|
|
|
* Fonts for the game.
|
2006-03-20 16:43:15 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "gr.h"
|
2012-07-07 18:35:06 +00:00
|
|
|
#include "dxxerror.h"
|
2006-03-20 16:43:15 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include "strutil.h"
|
|
|
|
#include "args.h"
|
2014-07-20 01:09:55 +00:00
|
|
|
#include "physfsx.h"
|
2006-03-20 16:43:15 +00:00
|
|
|
#include "gamefont.h"
|
2008-03-22 08:30:23 +00:00
|
|
|
#include "mission.h"
|
2009-01-15 23:58:36 +00:00
|
|
|
#include "config.h"
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2015-04-02 02:36:52 +00:00
|
|
|
const array<char[16], 5> Gamefont_filenames_l{{
|
2008-02-24 14:41:27 +00:00
|
|
|
"font1-1.fnt", // Font 0
|
|
|
|
"font2-1.fnt", // Font 1
|
|
|
|
"font2-2.fnt", // Font 2
|
|
|
|
"font2-3.fnt", // Font 3
|
|
|
|
"font3-1.fnt" // Font 4
|
2015-04-02 02:36:52 +00:00
|
|
|
}};
|
2008-02-24 14:41:27 +00:00
|
|
|
|
2015-04-02 02:36:52 +00:00
|
|
|
const array<char[16], 5> Gamefont_filenames_h{{
|
2008-02-24 14:41:27 +00:00
|
|
|
"font1-1h.fnt", // Font 0
|
|
|
|
"font2-1h.fnt", // Font 1
|
|
|
|
"font2-2h.fnt", // Font 2
|
|
|
|
"font2-3h.fnt", // Font 3
|
|
|
|
"font3-1h.fnt" // Font 4
|
2015-04-02 02:36:52 +00:00
|
|
|
}};
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2014-07-20 03:48:27 +00:00
|
|
|
array<grs_font_ptr, MAX_FONTS> Gamefonts;
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2015-04-02 02:36:52 +00:00
|
|
|
static int Gamefont_installed;
|
2008-10-29 11:03:31 +00:00
|
|
|
float FNTScaleX = 1, FNTScaleY = 1;
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
//code to allow variable GAME_FONT, added 10/7/99 Matt Mueller - updated 11/18/99 to handle all fonts, not just GFONT_SMALL
|
|
|
|
// take scry into account? how/when?
|
2013-12-22 22:03:07 +00:00
|
|
|
struct a_gamefont_conf
|
|
|
|
{
|
2006-03-20 16:43:15 +00:00
|
|
|
int x;
|
2006-08-13 15:52:49 +00:00
|
|
|
int y;
|
2006-03-20 16:43:15 +00:00
|
|
|
union{
|
|
|
|
char name[64];//hrm.
|
|
|
|
} f;
|
2013-12-22 22:03:07 +00:00
|
|
|
};
|
2008-02-24 14:41:27 +00:00
|
|
|
|
2013-12-22 22:03:07 +00:00
|
|
|
struct gamefont_conf
|
|
|
|
{
|
2006-03-20 16:43:15 +00:00
|
|
|
int num,cur;
|
2015-04-02 02:36:52 +00:00
|
|
|
array<a_gamefont_conf, 10> font;
|
2013-12-22 22:03:07 +00:00
|
|
|
};
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2015-04-02 02:36:52 +00:00
|
|
|
static array<gamefont_conf, MAX_FONTS> font_conf;
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2012-07-22 23:17:52 +00:00
|
|
|
static void gamefont_unloadfont(int gf)
|
|
|
|
{
|
2006-03-20 16:43:15 +00:00
|
|
|
if (Gamefonts[gf]){
|
|
|
|
font_conf[gf].cur=-1;
|
2014-07-20 03:48:27 +00:00
|
|
|
Gamefonts[gf].reset();
|
2006-03-20 16:43:15 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-24 14:41:27 +00:00
|
|
|
|
2012-07-22 23:17:52 +00:00
|
|
|
static void gamefont_loadfont(int gf,int fi)
|
|
|
|
{
|
2011-06-01 07:59:51 +00:00
|
|
|
if (PHYSFSX_exists(font_conf[gf].font[fi].f.name,1)){
|
2006-03-20 16:43:15 +00:00
|
|
|
gamefont_unloadfont(gf);
|
|
|
|
Gamefonts[gf]=gr_init_font(font_conf[gf].font[fi].f.name);
|
|
|
|
}else {
|
2014-07-20 03:48:27 +00:00
|
|
|
if (!Gamefonts[gf]){
|
2006-03-20 16:43:15 +00:00
|
|
|
Gamefonts[gf]=gr_init_font(Gamefont_filenames_l[gf]);
|
|
|
|
font_conf[gf].cur=-1;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
font_conf[gf].cur=fi;
|
|
|
|
}
|
2008-02-24 14:41:27 +00:00
|
|
|
|
2006-03-20 16:43:15 +00:00
|
|
|
void gamefont_choose_game_font(int scrx,int scry){
|
2014-09-26 02:42:09 +00:00
|
|
|
int close=-1,m=-1;
|
2006-03-20 16:43:15 +00:00
|
|
|
if (!Gamefont_installed) return;
|
|
|
|
|
2014-09-26 02:42:09 +00:00
|
|
|
for (int gf=0;gf<MAX_FONTS;gf++){
|
|
|
|
for (int i=0;i<font_conf[gf].num;i++)
|
2006-08-13 15:52:49 +00:00
|
|
|
if ((scrx>=font_conf[gf].font[i].x && close<font_conf[gf].font[i].x)&&(scry>=font_conf[gf].font[i].y && close<font_conf[gf].font[i].y)){
|
2006-03-20 16:43:15 +00:00
|
|
|
close=font_conf[gf].font[i].x;
|
|
|
|
m=i;
|
|
|
|
}
|
|
|
|
if (m<0)
|
|
|
|
Error("no gamefont found for %ix%i\n",scrx,scry);
|
|
|
|
|
2008-02-24 14:41:27 +00:00
|
|
|
#ifdef OGL
|
2015-12-24 04:01:27 +00:00
|
|
|
if (!CGameArg.OglFixedFont)
|
2008-02-24 14:41:27 +00:00
|
|
|
{
|
2009-01-15 23:58:36 +00:00
|
|
|
// if there's no texture filtering, scale by int
|
2016-07-15 03:43:02 +00:00
|
|
|
auto &f = font_conf[gf].font[m];
|
2015-12-18 04:08:23 +00:00
|
|
|
if (!CGameCfg.TexFilt)
|
2009-01-15 23:58:36 +00:00
|
|
|
{
|
2016-07-15 03:43:02 +00:00
|
|
|
FNTScaleX = scrx / f.x;
|
|
|
|
FNTScaleY = scry / f.y;
|
2009-01-15 23:58:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-15 03:43:02 +00:00
|
|
|
FNTScaleX = static_cast<float>(scrx) / f.x;
|
|
|
|
FNTScaleY = static_cast<float>(scry) / f.y;
|
2009-01-15 23:58:36 +00:00
|
|
|
}
|
2013-02-21 00:20:26 +00:00
|
|
|
|
2008-11-09 14:31:30 +00:00
|
|
|
// keep proportions
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
|
|
|
#define DXX_FONT_SCALE_MULTIPLIER 1
|
|
|
|
#elif defined(DXX_BUILD_DESCENT_II)
|
|
|
|
#define DXX_FONT_SCALE_MULTIPLIER 100
|
|
|
|
#endif
|
|
|
|
if (FNTScaleY*DXX_FONT_SCALE_MULTIPLIER < FNTScaleX*DXX_FONT_SCALE_MULTIPLIER)
|
2008-11-09 14:31:30 +00:00
|
|
|
FNTScaleX = FNTScaleY;
|
2013-03-03 01:03:33 +00:00
|
|
|
else if (FNTScaleX*DXX_FONT_SCALE_MULTIPLIER < FNTScaleY*DXX_FONT_SCALE_MULTIPLIER)
|
2008-11-09 14:31:30 +00:00
|
|
|
FNTScaleY = FNTScaleX;
|
2008-02-24 14:41:27 +00:00
|
|
|
}
|
|
|
|
#endif
|
2006-03-20 16:43:15 +00:00
|
|
|
gamefont_loadfont(gf,m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-22 23:17:52 +00:00
|
|
|
static void addfontconf(int gf, int x, int y, const char *const fn)
|
|
|
|
{
|
2011-06-01 07:59:51 +00:00
|
|
|
if (!PHYSFSX_exists(fn,1))
|
2008-02-24 14:41:27 +00:00
|
|
|
return;
|
|
|
|
|
2014-09-26 02:42:09 +00:00
|
|
|
for (int i=0;i<font_conf[gf].num;i++){
|
2006-08-13 15:52:49 +00:00
|
|
|
if (font_conf[gf].font[i].x==x && font_conf[gf].font[i].y==y){
|
2006-03-20 16:43:15 +00:00
|
|
|
if (i==font_conf[gf].cur)
|
|
|
|
gamefont_unloadfont(gf);
|
|
|
|
strcpy(font_conf[gf].font[i].f.name,fn);
|
|
|
|
if (i==font_conf[gf].cur)
|
|
|
|
gamefont_loadfont(gf,i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
font_conf[gf].font[font_conf[gf].num].x=x;
|
2006-08-13 15:52:49 +00:00
|
|
|
font_conf[gf].font[font_conf[gf].num].y=y;
|
2006-03-20 16:43:15 +00:00
|
|
|
strcpy(font_conf[gf].font[font_conf[gf].num].f.name,fn);
|
|
|
|
font_conf[gf].num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gamefont_init()
|
|
|
|
{
|
2007-07-15 21:22:07 +00:00
|
|
|
if (Gamefont_installed)
|
|
|
|
return;
|
2006-08-13 15:52:49 +00:00
|
|
|
|
2006-03-20 16:43:15 +00:00
|
|
|
Gamefont_installed = 1;
|
|
|
|
|
2014-09-26 02:42:09 +00:00
|
|
|
for (int i=0;i<MAX_FONTS;i++){
|
2006-03-20 16:43:15 +00:00
|
|
|
Gamefonts[i]=NULL;
|
|
|
|
|
2015-12-24 04:01:26 +00:00
|
|
|
if (!CGameArg.GfxSkipHiresFNT)
|
2007-07-15 15:23:45 +00:00
|
|
|
addfontconf(i,640,480,Gamefont_filenames_h[i]); // ZICO - addition to use D2 fonts if available
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
2008-04-02 12:13:21 +00:00
|
|
|
if (MacHog && (i != 0))
|
|
|
|
addfontconf(i,640,480,Gamefont_filenames_l[i]); // Mac fonts are hires (except for the "big" one)
|
2008-03-22 08:30:23 +00:00
|
|
|
else
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2008-03-22 08:30:23 +00:00
|
|
|
addfontconf(i,320,200,Gamefont_filenames_l[i]);
|
2006-03-20 16:43:15 +00:00
|
|
|
}
|
2006-08-13 15:52:49 +00:00
|
|
|
|
2006-03-20 16:43:15 +00:00
|
|
|
gamefont_choose_game_font(grd_curscreen->sc_canvas.cv_bitmap.bm_w,grd_curscreen->sc_canvas.cv_bitmap.bm_h);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void gamefont_close()
|
|
|
|
{
|
|
|
|
if (!Gamefont_installed) return;
|
|
|
|
Gamefont_installed = 0;
|
|
|
|
|
2014-09-26 02:42:09 +00:00
|
|
|
for (int i=0; i<MAX_FONTS; i++ ) {
|
2006-03-20 16:43:15 +00:00
|
|
|
gamefont_unloadfont(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|