OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TextBase.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 #ifndef OSGTEXT_TEXTBASE
15 #define OSGTEXT_TEXTBASE 1
16 
17 #include <osg/Drawable>
18 
19 #include <osgText/String>
20 #include <osgText/KerningType>
21 #include <osgText/Font>
22 
23 namespace osgText {
24 
25 
27 {
28 public:
29 
30  TextBase();
31  TextBase(const TextBase& text,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
32 
33  //virtual osg::Object* cloneType() const { return new Text(); }
34  //virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new Text(*this,copyop); }
35  virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const TextBase*>(obj)!=NULL; }
36  virtual const char* className() const { return "TextBase"; }
37  virtual const char* libraryName() const { return "osgText"; }
38 
39  void setColor(const osg::Vec4& color);
40  const osg::Vec4& getColor() const { return _color; }
41 
44  virtual void setFont(Font* font=0) { setFont(osg::ref_ptr<Font>(font)); };
45 
47  virtual void setFont(osg::ref_ptr<Font> font);
48 
52  virtual void setFont(const std::string& fontfile);
53 
55  const Font* getFont() const { return _font.get(); }
56 
57 
59  void setStyle(Style* style) { _style = style; }
61  Style* getStyle() { return _style.get(); }
63  const Style* getStyle() const { return _style.get(); }
64 
66  Style* getOrCreateStyle() { if (!_style) _style = new Style; return _style.get(); }
67 
71  void setFontResolution(unsigned int width, unsigned int height);
72 
73  unsigned int getFontWidth() const { return _fontSize.first; }
74  unsigned int getFontHeight() const { return _fontSize.second; }
75 
76 
78  void setText(const String& text);
79 
82  void setText(const std::string& text);
83 
86  void setText(const std::string& text,String::Encoding encoding);
87 
90  void setText(const wchar_t* text);
91 
95  String& getText() { return _text; }
96 
98  const String& getText() const { return _text; }
99 
102  void update() { computeGlyphRepresentation(); }
103 
104 
106  void setCharacterSize(float height);
107 
109  void setCharacterSize(float height, float aspectRatio);
110 
111  float getCharacterHeight() const { return _characterHeight; }
112  float getCharacterAspectRatio() const { return _style.valid()? _style->getWidthRatio() : 1.0f; }
113 
115  {
118  OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT
119  };
120 
122  void setCharacterSizeMode(CharacterSizeMode mode) { _characterSizeMode = mode; }
123 
125  CharacterSizeMode getCharacterSizeMode() const { return _characterSizeMode; }
126 
127 
132  void setMaximumWidth(float maximumWidth);
133 
135  float getMaximumWidth() const { return _maximumWidth; }
136 
141  void setMaximumHeight(float maximumHeight);
142 
144  float getMaximumHeight() const { return _maximumHeight; }
145 
150  void setLineSpacing(float lineSpacing);
151 
153  float getLineSpacing() const { return _lineSpacing; }
154 
155 
156 
158  void setPosition(const osg::Vec3& pos);
159 
161  const osg::Vec3& getPosition() const { return _position; }
162 
163 
165  {
169 
173 
177 
181 
185 
186  BASE_LINE = LEFT_BASE_LINE
187 
188  };
189 
190  void setAlignment(AlignmentType alignment);
191  AlignmentType getAlignment() const { return _alignment; }
192 
193 
195  {
203  USER_DEFINED_ROTATION
204  };
205 
206  void setAxisAlignment(AxisAlignment axis);
207  AxisAlignment getAxisAlignment() const { return _axisAlignment; }
208 
209  void setRotation(const osg::Quat& quat);
210  const osg::Quat& getRotation() const { return _rotation; }
211 
212  void setAutoRotateToScreen(bool autoRotateToScreen);
213  bool getAutoRotateToScreen() const { return _autoRotateToScreen; }
214 
215  enum Layout
216  {
219  VERTICAL
220  };
221 
222  void setLayout(Layout layout);
223 
224  Layout getLayout() const { return _layout; }
225 
226 
228  {
229  TEXT = 1,
230  BOUNDINGBOX = 2,
231  FILLEDBOUNDINGBOX = 4,
232  ALIGNMENT = 8
233  };
234 
235  void setDrawMode(unsigned int mode);
236 
237  unsigned int getDrawMode() const { return _drawMode; }
238 
239  void setBoundingBoxMargin(float margin);
240 
241  float getBoundingBoxMargin() const { return _textBBMargin; }
242 
243  void setBoundingBoxColor(const osg::Vec4& color){ _textBBColor = color; }
244 
245  const osg::Vec4& getBoundingBoxColor() const { return _textBBColor; }
246 
247 
248  void setKerningType(KerningType kerningType) { _kerningType = kerningType; }
249 
250  KerningType getKerningType() const { return _kerningType; }
251 
253  unsigned int getLineCount() const { return _lineCount; }
254 
256  virtual void setThreadSafeRefUnref(bool threadSafe);
257 
259  virtual void resizeGLObjectBuffers(unsigned int maxSize);
260 
264  virtual void releaseGLObjects(osg::State* state=0) const;
265 
266 
267  virtual osg::BoundingBox computeBoundingBox() const;
268 
269 protected:
270 
271  virtual ~TextBase();
272 
273  void positionCursor(const osg::Vec2 & endOfLine_coords, osg::Vec2 & cursor, unsigned int linelength);
274  void computePositions();
275  String::iterator computeLastCharacterOnLine(osg::Vec2& cursor, String::iterator first,String::iterator last);
276 
277 
278  virtual void computePositions(unsigned int contextID) const = 0;
279  virtual void computeGlyphRepresentation() = 0;
280 
281 
282  // members which have public access.
292 
300  unsigned int _drawMode;
304  unsigned int _lineCount;
305 
306 
307 
308  // internal caches of the positioning of the text.
309 
311  {
313  _traversalNumber(-1),
314  _width(0),
315  _height(0) {}
316 
318  int _width;
319  int _height;
324  };
325 
330 };
331 
332 }
333 
334 
335 #endif
336 
void setStyle(Style *style)
Definition: TextBase.h:59
std::pair< unsigned int, unsigned int > FontResolution
Definition: KerningType.h:20
Style * getOrCreateStyle()
Definition: TextBase.h:66
Layout getLayout() const
Definition: TextBase.h:224
virtual void setFont(Font *font=0)
Definition: TextBase.h:44
bool getAutoRotateToScreen() const
Definition: TextBase.h:213
unsigned int getFontHeight() const
Definition: TextBase.h:74
#define NULL
Definition: Export.h:59
const Font * getFont() const
Definition: TextBase.h:55
void setCharacterSizeMode(CharacterSizeMode mode)
Definition: TextBase.h:122
virtual bool isSameKindAs(const osg::Object *obj) const
Definition: TextBase.h:35
float getCharacterHeight() const
Definition: TextBase.h:111
const osg::Vec4 & getBoundingBoxColor() const
Definition: TextBase.h:245
float _maximumHeight
Definition: TextBase.h:290
unsigned int getFontWidth() const
Definition: TextBase.h:73
osg::Vec4 _textBBColor
Definition: TextBase.h:302
AlignmentType _alignment
Definition: TextBase.h:295
float _lineSpacing
Definition: TextBase.h:291
float getCharacterAspectRatio() const
Definition: TextBase.h:112
Style * getStyle()
Definition: TextBase.h:61
virtual const char * className() const
Definition: TextBase.h:36
float _textBBMargin
Definition: TextBase.h:301
AxisAlignment _axisAlignment
Definition: TextBase.h:296
FontResolution _fontSize
Definition: TextBase.h:286
void setKerningType(KerningType kerningType)
Definition: TextBase.h:248
virtual const char * libraryName() const
Definition: TextBase.h:37
GLint GLenum GLsizei width
Definition: GLU.h:71
osg::Vec3 _position
Definition: TextBase.h:294
const String & getText() const
Definition: TextBase.h:98
float getLineSpacing() const
Definition: TextBase.h:153
float getBoundingBoxMargin() const
Definition: TextBase.h:241
osg::buffered_object< AutoTransformCache > _autoTransformCache
Definition: TextBase.h:326
AxisAlignment getAxisAlignment() const
Definition: TextBase.h:207
float getMaximumWidth() const
Definition: TextBase.h:135
unsigned int getLineCount() const
Definition: TextBase.h:253
bool _autoRotateToScreen
Definition: TextBase.h:298
const Style * getStyle() const
Definition: TextBase.h:63
osg::Vec4 _color
Definition: TextBase.h:283
GLint GLenum GLsizei GLsizei height
Definition: GLU.h:71
String & getText()
Definition: TextBase.h:95
float _maximumWidth
Definition: TextBase.h:289
osg::ref_ptr< Font > _font
Definition: TextBase.h:284
osg::Vec3 _normal
Definition: TextBase.h:328
osg::Vec3 _offset
Definition: TextBase.h:327
unsigned int _lineCount
Definition: TextBase.h:304
unsigned int getDrawMode() const
Definition: TextBase.h:237
CharacterSizeMode _characterSizeMode
Definition: TextBase.h:288
AlignmentType getAlignment() const
Definition: TextBase.h:191
CharacterSizeMode getCharacterSizeMode() const
Definition: TextBase.h:125
const osg::Vec4 & getColor() const
Definition: TextBase.h:40
osg::BoundingBox _textBB
Definition: TextBase.h:329
float _characterHeight
Definition: TextBase.h:287
osg::ref_ptr< Style > _style
Definition: TextBase.h:285
unsigned int _drawMode
Definition: TextBase.h:300
const osg::Quat & getRotation() const
Definition: TextBase.h:210
KerningType _kerningType
Definition: TextBase.h:303
void setBoundingBoxColor(const osg::Vec4 &color)
Definition: TextBase.h:243
float getMaximumHeight() const
Definition: TextBase.h:144
Definition: Quat.h:29
const osg::Vec3 & getPosition() const
Definition: TextBase.h:161
osg::Quat _rotation
Definition: TextBase.h:297
#define OSGTEXT_EXPORT
Definition: Export.h:39
KerningType getKerningType() const
Definition: TextBase.h:250