HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_ViewportFont.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GR_ViewportFont.h ( GR Library, C++)
7  *
8  * COMMENTS:
9  * Renders a fixed width bitmap font to screen positions.
10  */
11 #ifndef GR_ViewportFont_h
12 #define GR_ViewportFont_h
13 
14 #include "GR_API.h"
15 #include "GR_Defines.h"
16 
17 #include <SYS/SYS_Types.h>
18 #include <UT/UT_Vector2.h>
19 
20 class RE_Render;
21 class UT_String;
22 
24 {
25 public:
26 
30  GR_DecorFontType charset);
31  virtual ~GR_ViewportFont();
32 
33  /// @{
34  /// The line number and text direction
35  enum YPosition
36  {
38  TOP,
39  ELEVATED
40  };
41  enum XPosition
42  {
45  CENTRE
46  };
47  /// @}
48 
49  /// @{
50  /// Functions for drawing certain types of data to the screen.
51  /// eg. fpreal, int, string, and then vectors of these types
52  /// pos is the screen position
53  /// x_offset is an initial offset from pos (useful for rendering
54  // over multiple calls to label)
55  int label (RE_Render *r,
56  fpreal64 num,
57  const UT_Vector3F &pos,
58  const UT_Vector3F &col,
59  fpreal32 *&dst_points,
60  fpreal32 *&dst_texcoord,
61  fpreal32 *&dst_colors,
62  XPosition xpos, YPosition ypos,
63  fpreal &x_offset) const;
64 
65  int label (RE_Render *r,
66  int32 num,
67  const UT_Vector3F &pos,
68  const UT_Vector3F &col,
69  fpreal32 *&dst_points,
70  fpreal32 *&dst_texcoord,
71  fpreal32 *&dst_colors,
72  XPosition xpos, YPosition ypos,
73  fpreal &x_offset) const
74  {
75  return label (r, static_cast<int64>(num), pos, col,
76  dst_points, dst_texcoord, dst_colors,
77  xpos, ypos, x_offset);
78  }
79 
80  int label (RE_Render *r,
81  int64 num,
82  const UT_Vector3F &pos,
83  const UT_Vector3F &col,
84  fpreal32 *&dst_points,
85  fpreal32 *&dst_texcoord,
86  fpreal32 *&dst_colors,
87  XPosition xpos, YPosition ypos,
88  fpreal &x_offset) const;
89 
90  int label (RE_Render *r, const UT_String &str,
91  const UT_Vector3F &pos, const UT_Vector3F &col,
92  fpreal32 *&dst_points,
93  fpreal32 *&dst_texcoord,
94  fpreal32 *&dst_colors,
95  XPosition xpos, YPosition ypos,
96  fpreal &x_offset) const;
97 
98  template <typename T>
99  int vectorLabel (RE_Render *r,
100  T vec,
101  const UT_Vector3F &pos,
102  const UT_Vector3F &col,
103  fpreal32 *&dst_points,
104  fpreal32 *&dst_texcoord,
105  fpreal32 *&dst_colors,
106  XPosition xpos, YPosition ypos,
107  fpreal &x_offset) const;
108  /// @}
109 
110 
111  /// The offset from the vertex when drawing vertex label decor
113  {
114  return 0.75 * (myWidth - myHeight) * myPixelSize;
115  }
116 
117 private:
118  /// Draws a single glyph
119  void glyph(fpreal32 *&dst_points,
120  fpreal32 *&dst_texcoord,
121  fpreal32 *&dst_colors,
122  const UT_Vector3F &pos, // Position of start of line
123  const UT_Vector3F &col, // Color of text
124  const UT_Vector2F &offset, // Offset into line
125  fpreal w, fpreal h, // Size of character
126  fpreal u, fpreal u1) const; // Position in character map
127 
128  /// Moves x_offset one space forward
129  void space(fpreal &x_offset, int dir) const
130  {
131  x_offset += dir * (myWidth * 0.66);
132  }
133 
134  UT_Vector3F normalizeIntCoord(const UT_Vector2F &offset) const;
135 
136 
137  // These reference screen sizes in pixels
138  // myPad is the default kerning.
139  // myHeight and myWidth are the
140  fpreal myPad, myHeight, myWidth;
141 
142  // These reference uv coords [0,1]
143  fpreal myWidthTexture, myPadTexture;
144 
145  // Size of a pixel in either direction in NDC
146  UT_Vector2F myPixelSize;
147 };
148 
149 
150 template <typename T>
151 int
153  const UT_Vector3F &pos, const UT_Vector3F &col,
154  fpreal32 *&dst_points,
155  fpreal32 *&dst_texcoord,
156  fpreal32 *&dst_colors,
157  XPosition xpos, YPosition ypos,
158  fpreal &x_offset) const
159 {
160  T numbers;
161  if (xpos == LEFT)
162  {
163  // We draw the last component first if we are drawing left
164  for (int i=0; i<vec.tuple_size; i++)
165  {
166  int j = vec.tuple_size - 1 - i;
167  numbers[j] = vec[i];
168  }
169  }
170  else
171  for (int i=0; i<vec.tuple_size; i++)
172  numbers[i] = vec[i];
173 
174  int digit_count = 0;
175  for (int j=0; j<vec.tuple_size; j++)
176  {
177  digit_count += label(r, numbers[j], pos, col,
178  dst_points, dst_texcoord, dst_colors,
179  xpos, ypos, x_offset);
180  if (j != vec.tuple_size-1)
181  space(x_offset, (xpos == LEFT) ? -1 : 1);
182  }
183 
184  return digit_count;
185 }
186 
187 #endif
int int32
Definition: SYS_Types.h:39
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
GR_DecorFontType
Definition: GR_Defines.h:199
UT_Vector2F getVertexOffsetDist()
The offset from the vertex when drawing vertex label decor.
float fpreal32
Definition: SYS_Types.h:200
GLdouble u1
Definition: glad.h:2676
double fpreal64
Definition: SYS_Types.h:201
GLintptr offset
Definition: glcorearb.h:665
int vectorLabel(RE_Render *r, T vec, const UT_Vector3F &pos, const UT_Vector3F &col, fpreal32 *&dst_points, fpreal32 *&dst_texcoord, fpreal32 *&dst_colors, XPosition xpos, YPosition ypos, fpreal &x_offset) const
GR_DecorFontSize
Definition: GR_Defines.h:189
#define GR_API
Definition: GR_API.h:10
long long int64
Definition: SYS_Types.h:116
int label(RE_Render *r, int32 num, const UT_Vector3F &pos, const UT_Vector3F &col, fpreal32 *&dst_points, fpreal32 *&dst_texcoord, fpreal32 *&dst_colors, XPosition xpos, YPosition ypos, fpreal &x_offset) const
int label(RE_Render *r, fpreal64 num, const UT_Vector3F &pos, const UT_Vector3F &col, fpreal32 *&dst_points, fpreal32 *&dst_texcoord, fpreal32 *&dst_colors, XPosition xpos, YPosition ypos, fpreal &x_offset) const
GLint j
Definition: glad.h:2733
GLsizeiptr size
Definition: glcorearb.h:664
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
fpreal64 fpreal
Definition: SYS_Types.h:277
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
GLboolean r
Definition: glcorearb.h:1222