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 #ifdef __cplusplus
29 #include "gr.h"
30
31 // When adding a new font, don't forget to change the filename in
32 // gamefont.c!!!!!!!!!!!!!!!!!!!!!!!!!!!
33
34 // We are interleaving low & high resolution fonts, so to access a
35 // font you say fontnum+flag where flag is 0 for lowres, 1 for hires
36
37 #if defined(DXX_BUILD_DESCENT_I)
38 #define GFONT_BIG_1 MacPig // the Mac data doesn't have this in hires, in the automap the scaled/hires one won't fit
39 #elif defined(DXX_BUILD_DESCENT_II)
40 #define GFONT_BIG_1 0
41 #endif
42 #define GFONT_MEDIUM_1 1
43 #define GFONT_MEDIUM_2 2
44 #define GFONT_MEDIUM_3 3
45 #define GFONT_SMALL 4
46
47 #define GAME_FONT (Gamefonts[GFONT_SMALL])
48 #define MEDIUM1_FONT (Gamefonts[GFONT_MEDIUM_1])
49 #define MEDIUM2_FONT (Gamefonts[GFONT_MEDIUM_2])
50 #define MEDIUM3_FONT (Gamefonts[GFONT_MEDIUM_3])
51 #define HUGE_FONT (Gamefonts[GFONT_BIG_1])
52
53 constexpr std::integral_constant<unsigned, 5> MAX_FONTS{};
54
55 // add (scaled) spacing to given font coordinate
56
57 extern std::array<grs_font_ptr, MAX_FONTS> Gamefonts;
58
59 class base_font_scale_proportion
60 {
61 protected:
62 float f;
63 public:
64 base_font_scale_proportion() = default;
base_font_scale_proportion(const float v)65 explicit constexpr base_font_scale_proportion(const float v) :
66 f(v)
67 {
68 }
69 explicit operator float() const
70 {
71 return f;
72 }
73 float operator*(const float v) const
74 {
75 return f * v;
76 }
reset(const float v)77 void reset(const float v)
78 {
79 f = v;
80 }
81 };
82
83 template <char tag>
84 class font_scale_proportion : public base_font_scale_proportion
85 {
86 public:
87 using base_font_scale_proportion::base_font_scale_proportion;
88 bool operator!=(const font_scale_proportion &rhs) const
89 {
90 return f != rhs.f;
91 }
92 };
93
94 using font_x_scale_proportion = font_scale_proportion<'x'>;
95 using font_y_scale_proportion = font_scale_proportion<'y'>;
96
97 extern font_x_scale_proportion FNTScaleX;
98 extern font_y_scale_proportion FNTScaleY;
99
LINE_SPACING(const grs_font & active_font,const grs_font & game_font)100 static inline float LINE_SPACING(const grs_font &active_font, const grs_font &game_font)
101 {
102 return FNTScaleY * (active_font.ft_h + (game_font.ft_h / 5));
103 }
104
105 /* All the logic is in the base class */
106 class base_font_scaled_float
107 {
108 const float f;
109 public:
base_font_scaled_float(const float v)110 explicit constexpr base_font_scaled_float(const float v) :
111 f(v)
112 {
113 }
114 base_font_scaled_float(int) = delete;
115 operator float() const
116 {
117 return f;
118 }
119 };
120
121 /* Use an otherwise unnecessary tag to prevent mixing x-scale with
122 * y-scale.
123 */
124 template <char tag>
125 class font_scaled_float : public base_font_scaled_float
126 {
127 public:
128 using base_font_scaled_float::base_font_scaled_float;
129 };
130
131 template <char tag>
132 class font_scale_float
133 {
134 const float scale;
135 public:
136 using scaled = font_scaled_float<tag>;
font_scale_float(const float s)137 explicit constexpr font_scale_float(const float s) :
138 scale(s)
139 {
140 }
141 font_scale_float(int) = delete;
operator()142 auto operator()(const int &i) const
143 {
144 return scaled(scale * i);
145 }
146 };
147
148 using font_x_scale_float = font_scale_float<'x'>;
149 using font_y_scale_float = font_scale_float<'y'>;
150 using font_x_scaled_float = font_x_scale_float::scaled;
151 using font_y_scaled_float = font_y_scale_float::scaled;
152
FSPACX()153 static inline font_x_scale_float FSPACX()
154 {
155 return font_x_scale_float(FNTScaleX * (GAME_FONT->ft_w / 7));
156 }
157
FSPACX(const int & x)158 static inline auto FSPACX(const int &x)
159 {
160 return FSPACX()(x);
161 }
162
FSPACY()163 static inline font_y_scale_float FSPACY()
164 {
165 return font_y_scale_float(FNTScaleY * (GAME_FONT->ft_h / 5));
166 }
167
FSPACY(const int & y)168 static inline auto FSPACY(const int &y)
169 {
170 return FSPACY()(y);
171 }
172
173 #ifdef dsx
174 namespace dsx {
175 void gamefont_init();
176 }
177 #endif
178 void gamefont_close();
179 void gamefont_choose_game_font(int scrx,int scry);
180
181 #endif
182