~ubuntu-branches/ubuntu/trusty/openscenegraph/trusty

« back to all changes in this revision

Viewing changes to OpenSceneGraph/include/osgText/TextBase

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-07-29 04:34:38 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 lenny)
  • Revision ID: james.westby@ubuntu.com-20080729043438-no1h9h0dpsrlzp1y
* Non-maintainer upload.
* No longer try to detect (using /proc/cpuinfo when available) how many
  CPUs are available, fixing the FTBFS (due to -j0) on various platforms
  (Closes: #477353). The right way to do it is to support parallel=n in
  DEB_BUILD_OPTIONS (see Debian Policy §4.9.1), and adequate support has
  been implemented.
* Add patch to fix FTBFS due to the build system now refusing to handle
  whitespaces (Policy CMP0004 say the logs), thanks to Andreas Putzo who
  provided it (Closes: #482239):
   - debian/patches/fix-cmp0004-build-failure.dpatch
* Remove myself from Uploaders, as requested a while ago, done by Luk in
  his 2.2.0-2.1 NMU, which was never acknowledged.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
22
namespace osgText {
 
23
 
 
24
 
 
25
class OSGTEXT_EXPORT TextBase : public osg::Drawable
 
26
{
 
27
public:
 
28
 
 
29
    TextBase();
 
30
    TextBase(const TextBase& text,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
 
31
 
 
32
    //virtual osg::Object* cloneType() const { return new Text(); }
 
33
    //virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new Text(*this,copyop); }
 
34
    virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const TextBase*>(obj)!=NULL; }
 
35
    virtual const char* className() const { return "TextBase"; }
 
36
    virtual const char* libraryName() const { return "osgText"; }
 
37
 
 
38
    
 
39
    /** Set the Font reference width and height resolution in texels.
 
40
      * Note, the size may not be supported by current font, 
 
41
      * the closest supported font size will be selected.*/
 
42
    void setFontResolution(unsigned int width, unsigned int height);
 
43
 
 
44
    unsigned int getFontWidth() const { return _fontSize.first; }
 
45
    unsigned int getFontHeight() const { return _fontSize.second; }
 
46
    
 
47
    
 
48
    /** Set the text using a osgText::String.*/
 
49
    void setText(const String& text);
 
50
 
 
51
    /** Set the text using a std::string, 
 
52
      * which is converted to an internal TextString.*/
 
53
    void setText(const std::string& text);
 
54
 
 
55
    /** Set the text using a Unicode encoded std::string, which is converted to an internal TextString.
 
56
      * The encoding parameter specificies which Unicode encodeding is used in the std::string. */
 
57
    void setText(const std::string& text,String::Encoding encoding);
 
58
 
 
59
    /** Set the text using a wchar_t string, 
 
60
      * which is converted to an internal TextString.*/
 
61
    void setText(const wchar_t* text);
 
62
    
 
63
    /** Get the text string. 
 
64
      * Note, if you modify the string you must call Text::update() for
 
65
      * the internal glyph reprentation to be updated.*/
 
66
    String& getText() { return _text; }
 
67
 
 
68
    /** Get the const text string.*/
 
69
    const String& getText() const { return _text; }
 
70
    
 
71
    /** update internal glyph respresentation used for rendering, 
 
72
      * and bounding volume.*/
 
73
    void update() { computeGlyphRepresentation(); }
 
74
 
 
75
 
 
76
    /** Set the rendered character size in object coordinates.*/
 
77
    void setCharacterSize(float height,float aspectRatio=1.0f);
 
78
    
 
79
    float getCharacterHeight() const { return _characterHeight; }
 
80
    float getCharacterAspectRatio() const { return _characterAspectRatio; }
 
81
 
 
82
    enum CharacterSizeMode
 
83
    {
 
84
        OBJECT_COORDS, /// default
 
85
        SCREEN_COORDS, /// internally scale the characters to be constant screen size.
 
86
        OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT /// text that behavaves like OBJECT_COORDS sized text when a long distance way, but has its screen sized capped automatically when the viewer gets near.
 
87
    };
 
88
 
 
89
    /** Set how the CharacterSize value relates to the final rendered character.*/
 
90
    void setCharacterSizeMode(CharacterSizeMode mode) { _characterSizeMode = mode; }
 
91
    
 
92
    /** Get the CharacterSizeMode.*/
 
93
    CharacterSizeMode getCharacterSizeMode() const { return _characterSizeMode; }
 
94
 
 
95
 
 
96
    /** Set the maximum width of the text box.
 
97
      * With horizontal layouts any characters which do not fit are wrapped around.
 
98
      * 0 or negative values indicate that no maximum width is set, lines can be as long as 
 
99
      * they need be to fit thre required text*/
 
100
    void setMaximumWidth(float maximumWidth);
 
101
    
 
102
    /** Get the maximim width of the text box.*/
 
103
    float getMaximumWidth() const { return _maximumWidth; }
 
104
 
 
105
    /** Set the maximum height of the text box.
 
106
      * With horizontal layouts any characters which do not fit are wrapped around.
 
107
      * 0 or negative values indicate that no maximum height is set, lines can be as long as 
 
108
      * they need be to fit the required text*/
 
109
    void setMaximumHeight(float maximumHeight);
 
110
    
 
111
    /** Get the maximum height of the text box.*/
 
112
    float getMaximumHeight() const { return _maximumHeight; }
 
113
 
 
114
    /** Set the line spacing of the text box, given as a percentage of
 
115
      * the character height. The default value is 0 for backward 
 
116
      * compatibility. For longer paragraphs of text, a value of at 
 
117
      * least 25% (i.e. set line spacing to 0.25) is recommended. */
 
118
    void setLineSpacing(float lineSpacing);
 
119
 
 
120
    /** Get the line spacing of the text box. */
 
121
    float getLineSpacing() const { return _lineSpacing; }
 
122
 
 
123
 
 
124
 
 
125
    /** Set the position of text.*/
 
126
    void setPosition(const osg::Vec3& pos);
 
127
    
 
128
    /** Get the position of text.*/
 
129
    const osg::Vec3& getPosition() const { return _position; }
 
130
    
 
131
 
 
132
    enum AlignmentType
 
133
    {
 
134
        LEFT_TOP,
 
135
        LEFT_CENTER,
 
136
        LEFT_BOTTOM,
 
137
 
 
138
        CENTER_TOP,
 
139
        CENTER_CENTER,
 
140
        CENTER_BOTTOM,
 
141
 
 
142
        RIGHT_TOP,
 
143
        RIGHT_CENTER,
 
144
        RIGHT_BOTTOM,
 
145
        
 
146
        LEFT_BASE_LINE,
 
147
        CENTER_BASE_LINE,
 
148
        RIGHT_BASE_LINE,
 
149
    
 
150
        LEFT_BOTTOM_BASE_LINE,
 
151
        CENTER_BOTTOM_BASE_LINE,
 
152
        RIGHT_BOTTOM_BASE_LINE,
 
153
    
 
154
        BASE_LINE = LEFT_BASE_LINE /// default.
 
155
    
 
156
    };
 
157
    
 
158
    void setAlignment(AlignmentType alignment);
 
159
    AlignmentType getAlignment() const { return _alignment; }
 
160
 
 
161
 
 
162
    enum AxisAlignment
 
163
    {
 
164
        XY_PLANE,
 
165
        REVERSED_XY_PLANE,
 
166
        XZ_PLANE,
 
167
        REVERSED_XZ_PLANE,
 
168
        YZ_PLANE,
 
169
        REVERSED_YZ_PLANE,
 
170
        SCREEN,
 
171
        USER_DEFINED_ROTATION
 
172
    };
 
173
 
 
174
    void setAxisAlignment(AxisAlignment axis);
 
175
    AxisAlignment getAxisAlignment() const { return _axisAlignment; }
 
176
    
 
177
    void setRotation(const osg::Quat& quat);
 
178
    const osg::Quat& getRotation() const { return _rotation; }
 
179
 
 
180
    void setAutoRotateToScreen(bool autoRotateToScreen);
 
181
    bool getAutoRotateToScreen() const { return _autoRotateToScreen; }
 
182
 
 
183
    enum Layout
 
184
    {
 
185
        LEFT_TO_RIGHT, /// default
 
186
        RIGHT_TO_LEFT,
 
187
        VERTICAL
 
188
    };
 
189
    
 
190
    void setLayout(Layout layout);
 
191
    
 
192
    Layout getLayout() const { return _layout; }
 
193
 
 
194
 
 
195
    enum DrawModeMask
 
196
    {
 
197
        TEXT        = 1, /// default
 
198
        BOUNDINGBOX = 2,
 
199
        ALIGNMENT   = 4
 
200
    };
 
201
 
 
202
    void setDrawMode(unsigned int mode);
 
203
    
 
204
    unsigned int getDrawMode() const { return _drawMode; }
 
205
 
 
206
    
 
207
    void setKerningType(KerningType kerningType) { _kerningType = kerningType; }
 
208
 
 
209
    KerningType getKerningType() const { return _kerningType; }
 
210
 
 
211
    /** Get the number of wrapped lines - only valid after computeGlyphRepresentation() has been called, returns 0 otherwise */
 
212
    unsigned int getLineCount() const { return _lineCount; }
 
213
 
 
214
    /** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/
 
215
    virtual void setThreadSafeRefUnref(bool threadSafe);
 
216
 
 
217
    /** Resize any per context GLObject buffers to specified size. */
 
218
    virtual void resizeGLObjectBuffers(unsigned int maxSize);
 
219
 
 
220
    /** If State is non-zero, this function releases OpenGL objects for
 
221
      * the specified graphics context. Otherwise, releases OpenGL objexts
 
222
      * for all graphics contexts. */
 
223
    virtual void releaseGLObjects(osg::State* state=0) const;
 
224
 
 
225
    
 
226
    virtual osg::BoundingBox computeBound() const;
 
227
 
 
228
protected:
 
229
 
 
230
    virtual ~TextBase();
 
231
 
 
232
    void positionCursor(const osg::Vec2 & endOfLine_coords, osg::Vec2 & cursor, unsigned int linelength);
 
233
    void computePositions();
 
234
    String::iterator computeLastCharacterOnLine(osg::Vec2& cursor, String::iterator first,String::iterator last);
 
235
 
 
236
 
 
237
    virtual void computePositions(unsigned int contextID) const = 0;
 
238
    virtual void computeGlyphRepresentation() = 0;
 
239
    
 
240
    
 
241
    // members which have public access.
 
242
    FontResolution                          _fontSize;
 
243
    float                                   _characterHeight;
 
244
    float                                   _characterAspectRatio;
 
245
    CharacterSizeMode                       _characterSizeMode;
 
246
    float                                   _maximumWidth;
 
247
    float                                   _maximumHeight;
 
248
    float                                   _lineSpacing;
 
249
 
 
250
    String                                  _text;
 
251
    osg::Vec3                               _position;
 
252
    AlignmentType                           _alignment;
 
253
    AxisAlignment                           _axisAlignment;
 
254
    osg::Quat                               _rotation;
 
255
    bool                                    _autoRotateToScreen;
 
256
    Layout                                  _layout;
 
257
    unsigned int                            _drawMode;
 
258
    KerningType                             _kerningType;
 
259
    unsigned int                            _lineCount;
 
260
 
 
261
    
 
262
 
 
263
    // internal caches of the positioning of the text.
 
264
    
 
265
    struct AutoTransformCache
 
266
    {    
 
267
        AutoTransformCache():
 
268
            _traversalNumber(-1),
 
269
            _width(0),
 
270
            _height(0) {}
 
271
    
 
272
        int         _traversalNumber;
 
273
        int         _width;
 
274
        int         _height;
 
275
        osg::Vec3   _transformedPosition;
 
276
        osg::Matrix _modelview;
 
277
        osg::Matrix _projection;
 
278
        osg::Matrix _matrix;
 
279
    };
 
280
    
 
281
    mutable osg::buffered_object<AutoTransformCache>    _autoTransformCache;
 
282
    mutable osg::Vec3                                   _offset;
 
283
    mutable osg::Vec3                                   _normal;
 
284
    mutable osg::BoundingBox                            _textBB;
 
285
};
 
286
 
 
287
}
 
288
 
 
289
 
 
290
#endif
 
291