textdraw.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/textdraw.h $*
  25. * *
  26. * $Author:: Greg_h $*
  27. * *
  28. * $Modtime:: 3/15/01 3:41p $*
  29. * *
  30. * $Revision:: 4 $*
  31. * *
  32. *-------------------------------------------------------------------------*/
  33. #if defined(_MSC_VER)
  34. #pragma once
  35. #endif
  36. #ifndef TEXTDRAW_H
  37. #define TEXTDRAW_H
  38. #include "always.h"
  39. #include "dynamesh.h"
  40. // sgc : wwlib and wwmath contain different rect.h files...
  41. #include "..\wwmath\rect.h"
  42. class Font3DInstanceClass;
  43. /******************************************************************
  44. **
  45. ** TextDrawClass
  46. **
  47. ** This class provides a simple method to draw 2D text into a scene.
  48. ** Both strings and individual characters can be drawn to any normalized
  49. ** screen coordinates ( 0.. 1 ), or any scale/offset.
  50. ** This class uses a dynamic mesh for all polygon and vertex management
  51. **
  52. *******************************************************************/
  53. class TextDrawClass : public DynamicMeshClass
  54. {
  55. public:
  56. /*
  57. ** Constructor and Destructor
  58. */
  59. TextDrawClass( int max_chars );
  60. ~TextDrawClass();
  61. // Set Coordinate Range
  62. void Set_Coordinate_Ranges( const Vector2 & param_ul, const Vector2 & param_lr,
  63. const Vector2 & dest_ul, const Vector2 & dest_lr );
  64. // Reset all polys and verts
  65. virtual void Reset( void );
  66. /*
  67. ** class id of this render object
  68. */
  69. virtual int Class_ID(void) const { return CLASSID_TEXTDRAW; }
  70. /*
  71. **
  72. */
  73. float Get_Width( Font3DInstanceClass *font, const char *message );
  74. float Get_Char_Width( Font3DInstanceClass *font, const char c );
  75. float Get_Inter_Char_Width( Font3DInstanceClass *font );
  76. float Get_Height( Font3DInstanceClass *font, const char *message = "" );
  77. /*
  78. ** Print the given char/string with the given font at the given loation in screen pixels
  79. ** returns the pixel width of the drawn data.
  80. */
  81. float Print( Font3DInstanceClass *font, char ch, float screen_x, float screen_y);
  82. float Print( Font3DInstanceClass *font, const char *message, float screen_x, float screen_y);
  83. void Set_Text_Color( const Vector3 & color ) { Set_Vertex_Color(color); }
  84. /*
  85. ** dump the font image (debuging)
  86. */
  87. void Show_Font( Font3DInstanceClass *font, float screen_x, float screen_y );
  88. void Quad( float x0, float y0, float x1, float y1, float u0 = 0, float v0 = 0, float u1 = 1, float v1 = 1);
  89. void Quad( const RectClass & rect, const RectClass & uv = RectClass( 0, 0, 1, 1 ) );
  90. void Line( const Vector2 & a, const Vector2 & b, float width );
  91. void Line_Ends( const Vector2 & a, const Vector2 & b, float width, float end_percent );
  92. private:
  93. Vector3 TextColor;
  94. VertexMaterialClass *DefaultVertexMaterial;
  95. ShaderClass DefaultShader;
  96. Vector2 TranslateScale;
  97. Vector2 TranslateOffset;
  98. Vector2 PixelSize;
  99. };
  100. #endif // TEXTDRAW_H