| 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-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. |
| 18 |
*/ |
| 19 |
|
| 20 |
/* |
| 21 |
* |
| 22 |
* Font declarations for the game. |
| 23 |
* |
| 24 |
*/ |
| 25 |
|
| 26 |
#pragma once |
| 27 |
|
| 28 |
#include "dsx-ns.h" |
| 29 |
#include "gr.h" |
| 30 |
#include "fwd-d_array.h" |
| 31 |
|
| 32 |
// When adding a new font, don't forget to change the filename in |
| 33 |
// gamefont.c!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 34 |
|
| 35 |
// We are interleaving low & high resolution fonts, so to access a |
| 36 |
// font you say fontnum+flag where flag is 0 for lowres, 1 for hires |
| 37 |
|
| 38 |
namespace dcx { |
| 39 |
|
| 40 |
enum class gamefont_index : uint8_t |
| 41 |
{ |
| 42 |
big, |
| 43 |
medium1, |
| 44 |
medium2, |
| 45 |
medium3, |
| 46 |
small, |
| 47 |
}; |
| 48 |
|
| 49 |
#define GAME_FONT (Gamefonts[gamefont_index::small].font) |
| 50 |
#define MEDIUM1_FONT (Gamefonts[gamefont_index::medium1].font) |
| 51 |
#define MEDIUM2_FONT (Gamefonts[gamefont_index::medium2].font) |
| 52 |
#define MEDIUM3_FONT (Gamefonts[gamefont_index::medium3].font) |
| 53 |
|
| 54 |
#ifdef DXX_BUILD_DESCENT |
| 55 |
#if DXX_BUILD_DESCENT == 1 |
| 56 |
// The Mac data doesn't have this in hires, in the automap the scaled/hires one won't fit |
| 57 |
#define HUGE_FONT (Gamefonts[MacPig ? gamefont_index::medium1 : gamefont_index::big].font) |
| 58 |
#elif DXX_BUILD_DESCENT == 2 |
| 59 |
#define HUGE_FONT (Gamefonts[gamefont_index::big].font) |
| 60 |
#endif |
| 61 |
#endif |
| 62 |
|
| 63 |
constexpr std::integral_constant<unsigned, 5> MAX_FONTS{}; |
| 64 |
|
| 65 |
struct loaded_game_font |
| 66 |
{ |
| 67 |
//code to allow variable GAME_FONT, added 10/7/99 Matt Mueller - updated 11/18/99 to handle all fonts, not just GFONT_SMALL |
| 68 |
// take scry into account? how/when? |
| 69 |
struct a_gamefont_conf |
| 70 |
{ |
| 71 |
uint16_t expected_screen_resolution_x; |
| 72 |
uint16_t expected_screen_resolution_y; |
| 73 |
std::array<char, 16> name; |
| 74 |
}; |
| 75 |
uint8_t total_fonts_loaded; |
| 76 |
std::array<a_gamefont_conf, 2> fontconf; |
| 77 |
grs_font_ptr font; |
| 78 |
}; |
| 79 |
|
| 80 |
extern enumerated_array<loaded_game_font, MAX_FONTS, gamefont_index> Gamefonts; |
| 81 |
|
| 82 |
class base_font_scale_proportion |
| 83 |
{ |
| 84 |
protected: |
| 85 |
float f{1.f}; |
| 86 |
public: |
| 87 |
constexpr base_font_scale_proportion() = default; |
| 88 |
explicit constexpr base_font_scale_proportion(const float v) : |
| 89 |
f{v} |
| 90 |
{ |
| 91 |
} |
| 92 |
explicit operator float() const |
| 93 |
{ |
| 94 |
return f; |
| 95 |
} |
| 96 |
float operator*(const float v) const |
| 97 |
{ |
| 98 |
return f * v; |
| 99 |
} |
| 100 |
void reset(const float v) |
| 101 |
{ |
| 102 |
f = v; |
| 103 |
} |
| 104 |
constexpr bool operator==(const base_font_scale_proportion &rhs) const = default; |
| 105 |
}; |
| 106 |
|
| 107 |
template <char tag> |
| 108 |
class font_scale_proportion : public base_font_scale_proportion |
| 109 |
{ |
| 110 |
public: |
| 111 |
using base_font_scale_proportion::base_font_scale_proportion; |
| 112 |
bool operator==(const font_scale_proportion &rhs) const = default; /* no `constexpr` due to gcc bug #98712 */ |
| 113 |
}; |
| 114 |
|
| 115 |
using font_x_scale_proportion = font_scale_proportion<'x'>; |
| 116 |
using font_y_scale_proportion = font_scale_proportion<'y'>; |
| 117 |
|
| 118 |
extern font_x_scale_proportion FNTScaleX; |
| 119 |
extern font_y_scale_proportion FNTScaleY; |
| 120 |
|
| 121 |
} |
| 122 |
|
| 123 |
static inline float LINE_SPACING(const grs_font &active_font, const grs_font &game_font) |
| 124 |
{ |
| 125 |
return FNTScaleY * (active_font.ft_h + (game_font.ft_h / 5)); |
| 126 |
} |
| 127 |
|
| 128 |
/* All the logic is in the base class */ |
| 129 |
class base_font_scaled_float |
| 130 |
{ |
| 131 |
const float f; |
| 132 |
public: |
| 133 |
explicit constexpr base_font_scaled_float(const float v) : |
| 134 |
f{v} |
| 135 |
{ |
| 136 |
} |
| 137 |
base_font_scaled_float(int) = delete; |
| 138 |
operator float() const |
| 139 |
{ |
| 140 |
return f; |
| 141 |
} |
| 142 |
}; |
| 143 |
|
| 144 |
/* Use an otherwise unnecessary tag to prevent mixing x-scale with |
| 145 |
* y-scale. |
| 146 |
*/ |
| 147 |
template <char tag> |
| 148 |
class font_scaled_float : public base_font_scaled_float |
| 149 |
{ |
| 150 |
public: |
| 151 |
using base_font_scaled_float::base_font_scaled_float; |
| 152 |
}; |
| 153 |
|
| 154 |
template <char tag> |
| 155 |
class font_scale_float |
| 156 |
{ |
| 157 |
const float scale; |
| 158 |
public: |
| 159 |
using scaled = font_scaled_float<tag>; |
| 160 |
explicit constexpr font_scale_float(const float s) : |
| 161 |
scale{s} |
| 162 |
{ |
| 163 |
} |
| 164 |
font_scale_float(int) = delete; |
| 165 |
auto operator()(const int &i) const |
| 166 |
{ |
| 167 |
return scaled(scale * i); |
| 168 |
} |
| 169 |
}; |
| 170 |
|
| 171 |
using font_x_scale_float = font_scale_float<'x'>; |
| 172 |
using font_y_scale_float = font_scale_float<'y'>; |
| 173 |
using font_x_scaled_float = font_x_scale_float::scaled; |
| 174 |
using font_y_scaled_float = font_y_scale_float::scaled; |
| 175 |
|
| 176 |
static inline font_x_scale_float FSPACX() |
| 177 |
{ |
| 178 |
return font_x_scale_float(FNTScaleX * (GAME_FONT->ft_w / 7)); |
| 179 |
} |
| 180 |
|
| 181 |
static inline auto FSPACX(const int &x) |
| 182 |
{ |
| 183 |
return FSPACX()(x); |
| 184 |
} |
| 185 |
|
| 186 |
static inline font_y_scale_float FSPACY() |
| 187 |
{ |
| 188 |
return font_y_scale_float(FNTScaleY * (GAME_FONT->ft_h / 5)); |
| 189 |
} |
| 190 |
|
| 191 |
static inline auto FSPACY(const int &y) |
| 192 |
{ |
| 193 |
return FSPACY()(y); |
| 194 |
} |
| 195 |
|
| 196 |
#ifdef DXX_BUILD_DESCENT |
| 197 |
namespace dsx { |
| 198 |
void gamefont_init(); |
| 199 |
} |
| 200 |
#endif |
| 201 |
void gamefont_choose_game_font(int scrx,int scry); |