Panda3D
textGlyph.I
1 // Filename: textGlyph.I
2 // Created by: drose (08Feb02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: TextGlyph::Default constructor
18 // Access: Public
19 // Description: This constructor makes an invalid glyph.
20 ////////////////////////////////////////////////////////////////////
21 INLINE TextGlyph::
22 TextGlyph(int character) :
23  _character(character)
24 {
25  _geom = (Geom *)NULL;
26  _advance = 0.0f;
27 }
28 
29 ////////////////////////////////////////////////////////////////////
30 // Function: TextGlyph::Constructor
31 // Access: Public
32 // Description:
33 ////////////////////////////////////////////////////////////////////
34 INLINE TextGlyph::
35 TextGlyph(int character, const Geom *geom,
36  const RenderState *state, PN_stdfloat advance) :
37  _character(character),
38  _geom(geom),
39  _state(state),
40  _advance(advance)
41 {
42  if (_state == (RenderState *)NULL) {
43  _state = RenderState::make_empty();
44  }
45 }
46 
47 ////////////////////////////////////////////////////////////////////
48 // Function: TextGlyph::Copy Constructor
49 // Access: Public
50 // Description:
51 ////////////////////////////////////////////////////////////////////
52 INLINE TextGlyph::
53 TextGlyph(const TextGlyph &copy) :
54  _character(copy._character),
55  _geom(copy._geom),
56  _state(copy._state),
57  _advance(copy._advance)
58 {
59 }
60 
61 ////////////////////////////////////////////////////////////////////
62 // Function: TextGlyph::Copy Assignment Operator
63 // Access: Public
64 // Description:
65 ////////////////////////////////////////////////////////////////////
66 INLINE void TextGlyph::
67 operator = (const TextGlyph &copy) {
68  _character = copy._character;
69  _geom = copy._geom;
70  _state = copy._state;
71  _advance = copy._advance;
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: TextGlyph::get_character
76 // Access: Public
77 // Description: Returns the Unicode value that corresponds to the
78 // character this glyph represents.
79 ////////////////////////////////////////////////////////////////////
80 INLINE int TextGlyph::
81 get_character() const {
82  return _character;
83 }
84 
85 ////////////////////////////////////////////////////////////////////
86 // Function: TextGlyph::get_geom
87 // Access: Public
88 // Description: Returns a Geom that renders the particular glyph.
89 ////////////////////////////////////////////////////////////////////
90 INLINE PT(Geom) TextGlyph::
91 get_geom(Geom::UsageHint usage_hint) const {
92  if (_geom == (Geom *)NULL) {
93  return NULL;
94  }
95 
96  // We always return a copy of the geom. That will allow the caller
97  // to modify its vertices without fear of stomping on other copies;
98  // it is also critical for the DynamicTextGlyph, which depends on
99  // this behavior to properly count references to this glyph.
100  PT(Geom) new_geom = _geom->make_copy();
101  new_geom->set_usage_hint(usage_hint);
102  const GeomVertexData *vdata = new_geom->get_vertex_data();
103  nassertr(vdata != NULL, new_geom);
104  if (vdata->get_usage_hint() != usage_hint) {
105  new_geom->modify_vertex_data()->set_usage_hint(usage_hint);
106  }
107  return new_geom;
108 }
109 
110 ////////////////////////////////////////////////////////////////////
111 // Function: TextGlyph::get_state
112 // Access: Public
113 // Description: Returns the state in which the glyph should be
114 // rendered.
115 ////////////////////////////////////////////////////////////////////
116 INLINE const RenderState *TextGlyph::
117 get_state() const {
118  return _state;
119 }
120 
121 ////////////////////////////////////////////////////////////////////
122 // Function: TextGlyph::get_advance
123 // Access: Public
124 // Description: Returns the distance by which the character pointer
125 // should be advanced after placing this character;
126 // i.e. the approximate width the character takes up on
127 // the line.
128 ////////////////////////////////////////////////////////////////////
129 INLINE PN_stdfloat TextGlyph::
130 get_advance() const {
131  return _advance;
132 }
int get_character() const
Returns the Unicode value that corresponds to the character this glyph represents.
Definition: textGlyph.I:81
UsageHint get_usage_hint() const
Returns the usage hint that was passed to the constructor, and which will be passed to each array dat...
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
Definition: geom.h:58
A representation of a single glyph (character) from a font.
Definition: textGlyph.h:31
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
TextGlyph(int character)
This constructor makes an invalid glyph.
Definition: textGlyph.I:22