Subversion Repositories Games.Descent

Rev

Blame | Last modification | View Log | Download | RSS feed

  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;
  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.         }
  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.         DXX_INHERIT_CONSTRUCTORS(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.  
  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:
  110.         explicit constexpr base_font_scaled_float(const float v) :
  111.                 f(v)
  112.         {
  113.         }
  114.         operator float() const
  115.         {
  116.                 return f;
  117.         }
  118. };
  119.  
  120. /* Use an otherwise unnecessary tag to prevent mixing x-scale with
  121.  * y-scale.
  122.  */
  123. template <char tag>
  124. class font_scaled_float : public base_font_scaled_float
  125. {
  126. public:
  127.         DXX_INHERIT_CONSTRUCTORS(font_scaled_float, base_font_scaled_float);
  128. };
  129.  
  130. template <char tag>
  131. class font_scale_float
  132. {
  133.         const float scale;
  134. public:
  135.         using scaled = font_scaled_float<tag>;
  136.         constexpr font_scale_float(const float s) :
  137.                 scale(s)
  138.         {
  139.         }
  140.         auto operator()(const int &i) const
  141.         {
  142.                 return scaled(scale * i);
  143.         }
  144. };
  145.  
  146. using font_x_scale_float = font_scale_float<'x'>;
  147. using font_y_scale_float = font_scale_float<'y'>;
  148. using font_x_scaled_float = font_x_scale_float::scaled;
  149. using font_y_scaled_float = font_y_scale_float::scaled;
  150.  
  151. static inline font_x_scale_float FSPACX()
  152. {
  153.         return FNTScaleX * (GAME_FONT->ft_w / 7);
  154. }
  155.  
  156. static inline auto FSPACX(const int &x)
  157. {
  158.         return FSPACX()(x);
  159. }
  160.  
  161. static inline font_y_scale_float FSPACY()
  162. {
  163.         return FNTScaleY * (GAME_FONT->ft_h / 5);
  164. }
  165.  
  166. static inline auto FSPACY(const int &y)
  167. {
  168.         return FSPACY()(y);
  169. }
  170.  
  171. #ifdef dsx
  172. namespace dsx {
  173. void gamefont_init();
  174. }
  175. #endif
  176. void gamefont_close();
  177. void gamefont_choose_game_font(int scrx,int scry);
  178.  
  179. #endif
  180.