Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | pmbaty | 1 | /* |
| 2 | * Portions of this file are copyright Rebirth contributors and licensed as |
||
| 3 | * described in COPYING.txt. |
||
| 4 | * Portions of this file are copyright Parallax Software and licensed |
||
| 5 | * according to the Parallax license below. |
||
| 6 | * See COPYING.txt for license details. |
||
| 7 | |||
| 8 | THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX |
||
| 9 | SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO |
||
| 10 | END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A |
||
| 11 | ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS |
||
| 12 | IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS |
||
| 13 | SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE |
||
| 14 | FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE |
||
| 15 | CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS |
||
| 16 | AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. |
||
| 17 | COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. |
||
| 18 | */ |
||
| 19 | |||
| 20 | /* |
||
| 21 | * |
||
| 22 | * Fonts for the game. |
||
| 23 | * |
||
| 24 | */ |
||
| 25 | |||
| 26 | #include <stdlib.h> |
||
| 27 | #include <stdio.h> |
||
| 28 | |||
| 29 | #include "gr.h" |
||
| 30 | #include "dxxerror.h" |
||
| 31 | #include <string.h> |
||
| 32 | #include "strutil.h" |
||
| 33 | #include "args.h" |
||
| 34 | #include "physfsx.h" |
||
| 35 | #include "gamefont.h" |
||
| 36 | #include "mission.h" |
||
| 37 | #include "config.h" |
||
| 38 | |||
| 39 | #include "compiler-range_for.h" |
||
| 40 | #include "d_enumerate.h" |
||
| 41 | |||
| 42 | const std::array<char[16], 5> Gamefont_filenames_l{{ |
||
| 43 | "font1-1.fnt", // Font 0 |
||
| 44 | "font2-1.fnt", // Font 1 |
||
| 45 | "font2-2.fnt", // Font 2 |
||
| 46 | "font2-3.fnt", // Font 3 |
||
| 47 | "font3-1.fnt" // Font 4 |
||
| 48 | }}; |
||
| 49 | |||
| 50 | const std::array<char[16], 5> Gamefont_filenames_h{{ |
||
| 51 | "font1-1h.fnt", // Font 0 |
||
| 52 | "font2-1h.fnt", // Font 1 |
||
| 53 | "font2-2h.fnt", // Font 2 |
||
| 54 | "font2-3h.fnt", // Font 3 |
||
| 55 | "font3-1h.fnt" // Font 4 |
||
| 56 | }}; |
||
| 57 | |||
| 58 | std::array<grs_font_ptr, MAX_FONTS> Gamefonts; |
||
| 59 | |||
| 60 | static int Gamefont_installed; |
||
| 61 | font_x_scale_proportion FNTScaleX(1); |
||
| 62 | font_y_scale_proportion FNTScaleY(1); |
||
| 63 | |||
| 64 | //code to allow variable GAME_FONT, added 10/7/99 Matt Mueller - updated 11/18/99 to handle all fonts, not just GFONT_SMALL |
||
| 65 | // take scry into account? how/when? |
||
| 66 | struct a_gamefont_conf |
||
| 67 | { |
||
| 68 | int x; |
||
| 69 | int y; |
||
| 70 | union{ |
||
| 71 | char name[64];//hrm. |
||
| 72 | } f; |
||
| 73 | }; |
||
| 74 | |||
| 75 | struct gamefont_conf |
||
| 76 | { |
||
| 77 | int num,cur; |
||
| 78 | std::array<a_gamefont_conf, 10> font; |
||
| 79 | }; |
||
| 80 | |||
| 81 | static std::array<gamefont_conf, MAX_FONTS> font_conf; |
||
| 82 | |||
| 83 | static void gamefont_unloadfont(int gf) |
||
| 84 | { |
||
| 85 | if (Gamefonts[gf]){ |
||
| 86 | font_conf[gf].cur=-1; |
||
| 87 | Gamefonts[gf].reset(); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | static void gamefont_loadfont(int gf,int fi) |
||
| 92 | { |
||
| 93 | if (PHYSFSX_exists(font_conf[gf].font[fi].f.name,1)){ |
||
| 94 | gamefont_unloadfont(gf); |
||
| 95 | Gamefonts[gf] = gr_init_font(*grd_curcanv, font_conf[gf].font[fi].f.name); |
||
| 96 | }else { |
||
| 97 | if (!Gamefonts[gf]){ |
||
| 98 | font_conf[gf].cur=-1; |
||
| 99 | Gamefonts[gf] = gr_init_font(*grd_curcanv, Gamefont_filenames_l[gf]); |
||
| 100 | } |
||
| 101 | return; |
||
| 102 | } |
||
| 103 | font_conf[gf].cur=fi; |
||
| 104 | } |
||
| 105 | |||
| 106 | void gamefont_choose_game_font(int scrx,int scry){ |
||
| 107 | int close=-1,m=-1; |
||
| 108 | if (!Gamefont_installed) return; |
||
| 109 | |||
| 110 | range_for (const auto &&efc, enumerate(font_conf)) |
||
| 111 | { |
||
| 112 | const auto gf = efc.idx; |
||
| 113 | auto &fc = efc.value; |
||
| 114 | for (int i = 0; i < fc.num; ++i) |
||
| 115 | if ((scrx >= fc.font[i].x && close < fc.font[i].x) && (scry >= fc.font[i].y && close < fc.font[i].y)) |
||
| 116 | { |
||
| 117 | close = fc.font[i].x; |
||
| 118 | m=i; |
||
| 119 | } |
||
| 120 | if (m<0) |
||
| 121 | Error("no gamefont found for %ix%i\n",scrx,scry); |
||
| 122 | |||
| 123 | #if DXX_USE_OGL |
||
| 124 | if (!CGameArg.OglFixedFont) |
||
| 125 | { |
||
| 126 | // if there's no texture filtering, scale by int |
||
| 127 | auto &f = fc.font[m]; |
||
| 128 | if (!CGameCfg.TexFilt) |
||
| 129 | { |
||
| 130 | FNTScaleX.reset(scrx / f.x); |
||
| 131 | FNTScaleY.reset(scry / f.y); |
||
| 132 | } |
||
| 133 | else |
||
| 134 | { |
||
| 135 | FNTScaleX.reset(static_cast<float>(scrx) / f.x); |
||
| 136 | FNTScaleY.reset(static_cast<float>(scry) / f.y); |
||
| 137 | } |
||
| 138 | |||
| 139 | // keep proportions |
||
| 140 | #if defined(DXX_BUILD_DESCENT_I) |
||
| 141 | #define DXX_FONT_SCALE_MULTIPLIER 1 |
||
| 142 | #elif defined(DXX_BUILD_DESCENT_II) |
||
| 143 | #define DXX_FONT_SCALE_MULTIPLIER 100 |
||
| 144 | #endif |
||
| 145 | if (FNTScaleY*DXX_FONT_SCALE_MULTIPLIER < FNTScaleX*DXX_FONT_SCALE_MULTIPLIER) |
||
| 146 | FNTScaleX.reset(FNTScaleY.operator float()); |
||
| 147 | else if (FNTScaleX*DXX_FONT_SCALE_MULTIPLIER < FNTScaleY*DXX_FONT_SCALE_MULTIPLIER) |
||
| 148 | FNTScaleY.reset(FNTScaleX.operator float()); |
||
| 149 | } |
||
| 150 | #endif |
||
| 151 | gamefont_loadfont(gf,m); |
||
| 152 | } |
||
| 153 | } |
||
| 154 | |||
| 155 | static void addfontconf(int gf, int x, int y, const char *const fn) |
||
| 156 | { |
||
| 157 | if (!PHYSFSX_exists(fn,1)) |
||
| 158 | return; |
||
| 159 | |||
| 160 | for (int i=0;i<font_conf[gf].num;i++){ |
||
| 161 | if (font_conf[gf].font[i].x==x && font_conf[gf].font[i].y==y){ |
||
| 162 | if (i==font_conf[gf].cur) |
||
| 163 | gamefont_unloadfont(gf); |
||
| 164 | strcpy(font_conf[gf].font[i].f.name,fn); |
||
| 165 | if (i==font_conf[gf].cur) |
||
| 166 | gamefont_loadfont(gf,i); |
||
| 167 | return; |
||
| 168 | } |
||
| 169 | } |
||
| 170 | font_conf[gf].font[font_conf[gf].num].x=x; |
||
| 171 | font_conf[gf].font[font_conf[gf].num].y=y; |
||
| 172 | strcpy(font_conf[gf].font[font_conf[gf].num].f.name,fn); |
||
| 173 | font_conf[gf].num++; |
||
| 174 | } |
||
| 175 | |||
| 176 | namespace dsx { |
||
| 177 | void gamefont_init() |
||
| 178 | { |
||
| 179 | if (Gamefont_installed) |
||
| 180 | return; |
||
| 181 | |||
| 182 | Gamefont_installed = 1; |
||
| 183 | |||
| 184 | range_for (auto &&egf, enumerate(Gamefonts)) |
||
| 185 | { |
||
| 186 | const auto i = egf.idx; |
||
| 187 | auto &gf = egf.value; |
||
| 188 | gf = nullptr; |
||
| 189 | |||
| 190 | if (!CGameArg.GfxSkipHiresFNT) |
||
| 191 | addfontconf(i,640,480,Gamefont_filenames_h[i]); // ZICO - addition to use D2 fonts if available |
||
| 192 | #if defined(DXX_BUILD_DESCENT_I) |
||
| 193 | if (MacHog && (i != 0)) |
||
| 194 | addfontconf(i,640,480,Gamefont_filenames_l[i]); // Mac fonts are hires (except for the "big" one) |
||
| 195 | else |
||
| 196 | #endif |
||
| 197 | addfontconf(i,320,200,Gamefont_filenames_l[i]); |
||
| 198 | } |
||
| 199 | |||
| 200 | gamefont_choose_game_font(grd_curscreen->sc_canvas.cv_bitmap.bm_w,grd_curscreen->sc_canvas.cv_bitmap.bm_h); |
||
| 201 | } |
||
| 202 | } |
||
| 203 | |||
| 204 | |||
| 205 | void gamefont_close() |
||
| 206 | { |
||
| 207 | if (!Gamefont_installed) return; |
||
| 208 | Gamefont_installed = 0; |
||
| 209 | |||
| 210 | range_for (auto &&egf, enumerate(Gamefonts)) |
||
| 211 | { |
||
| 212 | gamefont_unloadfont(egf.idx); |
||
| 213 | } |
||
| 214 | |||
| 215 | } |