Panda3D
 All Classes Functions Variables Enumerations
textGlyph.I
00001 // Filename: textGlyph.I
00002 // Created by:  drose (08Feb02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: TextGlyph::Default constructor
00018 //       Access: Public
00019 //  Description: This constructor makes an invalid glyph.
00020 ////////////////////////////////////////////////////////////////////
00021 INLINE TextGlyph::
00022 TextGlyph(int character) :
00023   _character(character)
00024 {
00025   _geom = (Geom *)NULL;
00026   _advance = 0.0f;
00027 }
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //     Function: TextGlyph::Constructor
00031 //       Access: Public
00032 //  Description:
00033 ////////////////////////////////////////////////////////////////////
00034 INLINE TextGlyph::
00035 TextGlyph(int character, const Geom *geom, 
00036           const RenderState *state, PN_stdfloat advance) :
00037   _character(character),
00038   _geom(geom), 
00039   _state(state),
00040   _advance(advance) 
00041 { 
00042   if (_state == (RenderState *)NULL) {
00043     _state = RenderState::make_empty();
00044   }
00045 }
00046 
00047 ////////////////////////////////////////////////////////////////////
00048 //     Function: TextGlyph::Copy Constructor
00049 //       Access: Public
00050 //  Description:
00051 ////////////////////////////////////////////////////////////////////
00052 INLINE TextGlyph::
00053 TextGlyph(const TextGlyph &copy) :
00054   _character(copy._character),
00055   _geom(copy._geom),
00056   _state(copy._state),
00057   _advance(copy._advance) 
00058 { 
00059 }
00060 
00061 ////////////////////////////////////////////////////////////////////
00062 //     Function: TextGlyph::Copy Assignment Operator
00063 //       Access: Public
00064 //  Description:
00065 ////////////////////////////////////////////////////////////////////
00066 INLINE void TextGlyph::
00067 operator = (const TextGlyph &copy) {
00068   _character = copy._character;
00069   _geom = copy._geom;
00070   _state = copy._state;
00071   _advance = copy._advance;
00072 }
00073 
00074 ////////////////////////////////////////////////////////////////////
00075 //     Function: TextGlyph::get_character
00076 //       Access: Public
00077 //  Description: Returns the Unicode value that corresponds to the
00078 //               character this glyph represents.
00079 ////////////////////////////////////////////////////////////////////
00080 INLINE int TextGlyph::
00081 get_character() const {
00082   return _character;
00083 }
00084 
00085 ////////////////////////////////////////////////////////////////////
00086 //     Function: TextGlyph::get_geom
00087 //       Access: Public
00088 //  Description: Returns a Geom that renders the particular glyph.
00089 ////////////////////////////////////////////////////////////////////
00090 INLINE PT(Geom) TextGlyph::
00091 get_geom(Geom::UsageHint usage_hint) const {
00092   if (_geom == (Geom *)NULL) {
00093     return NULL;
00094   }
00095 
00096   // We always return a copy of the geom.  That will allow the caller
00097   // to modify its vertices without fear of stomping on other copies;
00098   // it is also critical for the DynamicTextGlyph, which depends on
00099   // this behavior to properly count references to this glyph.
00100   PT(Geom) new_geom = _geom->make_copy();
00101   new_geom->set_usage_hint(usage_hint);
00102   const GeomVertexData *vdata = new_geom->get_vertex_data();
00103   nassertr(vdata != NULL, new_geom);
00104   if (vdata->get_usage_hint() != usage_hint) {
00105     new_geom->modify_vertex_data()->set_usage_hint(usage_hint);
00106   }
00107   return new_geom;
00108 }
00109 
00110 ////////////////////////////////////////////////////////////////////
00111 //     Function: TextGlyph::get_state
00112 //       Access: Public
00113 //  Description: Returns the state in which the glyph should be
00114 //               rendered.
00115 ////////////////////////////////////////////////////////////////////
00116 INLINE const RenderState *TextGlyph::
00117 get_state() const {
00118   return _state;
00119 }
00120 
00121 ////////////////////////////////////////////////////////////////////
00122 //     Function: TextGlyph::get_advance
00123 //       Access: Public
00124 //  Description: Returns the distance by which the character pointer
00125 //               should be advanced after placing this character;
00126 //               i.e. the approximate width the character takes up on
00127 //               the line.
00128 ////////////////////////////////////////////////////////////////////
00129 INLINE PN_stdfloat TextGlyph::
00130 get_advance() const {
00131   return _advance;
00132 }
 All Classes Functions Variables Enumerations