First cut of new osgText implementation.
This commit is contained in:
@@ -59,7 +59,10 @@ class SG_EXPORT Texture2D : public Texture
|
||||
_textureHeight = height;
|
||||
}
|
||||
|
||||
/** Get the texture subload width. */
|
||||
int getTextureWidth() const { return _textureWidth; }
|
||||
int getTextureHeight() const { return _textureHeight; }
|
||||
|
||||
// deprecated.
|
||||
inline void getTextureSize(int& width, int& height) const
|
||||
{
|
||||
width = _textureWidth;
|
||||
|
||||
@@ -63,6 +63,47 @@ class buffered_value
|
||||
std::vector<T> _array;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class buffered_object
|
||||
{
|
||||
public:
|
||||
|
||||
inline buffered_object():
|
||||
_array(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts())
|
||||
{}
|
||||
|
||||
buffered_object& operator = (const buffered_object& rhs)
|
||||
{
|
||||
_array = rhs._array;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void clear() { _array.clear(); }
|
||||
|
||||
inline bool empty() const { return _array.empty(); }
|
||||
|
||||
inline unsigned int size() const { return _array.size(); }
|
||||
|
||||
inline T& operator[] (unsigned int pos)
|
||||
{
|
||||
// automatically resize array.
|
||||
if (_array.size()<=pos)
|
||||
_array.resize(pos+1);
|
||||
|
||||
return _array[pos];
|
||||
}
|
||||
/* // do we implement the const version???
|
||||
inline T operator[] (unsigned int pos) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
protected:
|
||||
|
||||
std::vector<T> _array;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
*
|
||||
* openscenegraph textLib / FTGL wrapper (http://homepages.paradise.net.nz/henryj/code/)
|
||||
*
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* prog: max rheiner;mrn@paus.ch
|
||||
* date: 4/25/2001 (m/d/y)
|
||||
*
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OSGTEXT_ENCODEDTEXT
|
||||
#define OSGTEXT_ENCODEDTEXT 1
|
||||
|
||||
#include <osg/Referenced>
|
||||
#include <osgText/Export>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace osgText {
|
||||
|
||||
class OSGTEXT_EXPORT EncodedText : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Types of string encodings supported
|
||||
*/
|
||||
enum Encoding
|
||||
{
|
||||
ENCODING_UNDEFINED, /// not using Unicode
|
||||
ENCODING_ASCII = ENCODING_UNDEFINED,/// unsigned char ASCII
|
||||
ENCODING_UTF8, /// 8-bit unicode transformation format
|
||||
ENCODING_UTF16, /// 16-bit signature
|
||||
ENCODING_UTF16_BE, /// 16-bit big-endian
|
||||
ENCODING_UTF16_LE, /// 16-bit little-endian
|
||||
ENCODING_UTF32, /// 32-bit signature
|
||||
ENCODING_UTF32_BE, /// 32-bit big-endian
|
||||
ENCODING_UTF32_LE, /// 32-bit little-endian
|
||||
ENCODING_SIGNATURE, /// detect encoding from signature
|
||||
};
|
||||
|
||||
EncodedText();
|
||||
|
||||
void setOverrideEncoding(Encoding encoding);
|
||||
Encoding getOverrideEncoding() const { return _overrideEncoding; }
|
||||
Encoding getEncoding() const { return _encoding; }
|
||||
|
||||
std::vector<int>::const_iterator begin() const { return _unicodeText.begin(); }
|
||||
std::vector<int>::const_iterator end() const { return _unicodeText.end(); }
|
||||
|
||||
protected:
|
||||
|
||||
friend class Text;
|
||||
|
||||
std::string convertWideString(const wchar_t* text);
|
||||
void setText(const unsigned char* text, int length = -1);
|
||||
int getNextCharacter(const unsigned char*& charString) const;
|
||||
|
||||
/// This method will extract any ZWNBSP signature at the start of the string
|
||||
Encoding findEncoding(const unsigned char*& charString) const;
|
||||
|
||||
Encoding _encoding;
|
||||
Encoding _overrideEncoding;
|
||||
std::vector<int> _unicodeText;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // OSGTEXT_TEXT
|
||||
@@ -10,9 +10,6 @@
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSGTEXT_EXPORT_
|
||||
#define OSGTEXT_EXPORT_ 1
|
||||
|
||||
@@ -10,269 +10,188 @@
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
*
|
||||
* openscenegraph textLib / FTGL wrapper
|
||||
*
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* prog: max rheiner;mrn@paus.ch
|
||||
* date: 4/25/2001 (m/d/y)
|
||||
*
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OSGTEXT_FONT
|
||||
#define OSGTEXT_FONT 1
|
||||
#define OSGTEXT_FONT 1
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osg/State>
|
||||
#include <osg/Vec2>
|
||||
#include <osg/Image>
|
||||
#include <osg/Texture2D>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/buffered_value>
|
||||
|
||||
#include <osgText/Export>
|
||||
#include <osgText/EncodedText>
|
||||
|
||||
#include <string>
|
||||
|
||||
// http://homepages.paradise.net.nz/henryj/code/
|
||||
|
||||
class FTFont;
|
||||
|
||||
namespace osgText {
|
||||
|
||||
/** META_Font macro define the standard clone, isSameKindAs,
|
||||
* className and getType methods.
|
||||
* Use when subclassing from Object to make it more convinient to define
|
||||
* the standard pure virtual methods which are required for all Object
|
||||
* subclasses.*/
|
||||
#define META_Font(library,name) \
|
||||
virtual osg::Object* cloneType() const { return new name(); } \
|
||||
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new name (*this,copyop); } \
|
||||
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const name *>(obj)!=NULL; } \
|
||||
virtual const char* libraryName() const { return #library; } \
|
||||
virtual const char* className() const { return #name; } \
|
||||
class Font;
|
||||
|
||||
/** read a font from specified file.*/
|
||||
extern OSGTEXT_EXPORT Font* readFontFile(const std::string& filename);
|
||||
|
||||
|
||||
/** Pure virtual base class for fonts.
|
||||
* Concrete implementation are the DefaultFont found in src/osgText/DefaultFont.cpp
|
||||
* and FreeTypeFont found in src/osgPlugins/freetype/FreeTypeFont.cpp*/
|
||||
class OSGTEXT_EXPORT Font : public osg::Object
|
||||
{
|
||||
public:
|
||||
|
||||
Font();
|
||||
Font(const Font& font,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
osg::Object(font,copyop),
|
||||
_init(false),
|
||||
_created(false),
|
||||
_font(0L),
|
||||
_fontName(font._fontName),
|
||||
_pointSize(font._pointSize),
|
||||
_res(font._res),
|
||||
_textureSize(font._textureSize)
|
||||
{}
|
||||
|
||||
|
||||
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Font *>(obj)!=NULL; }
|
||||
virtual const char* libraryName() const { return "osgText"; }
|
||||
virtual const char* className() const { return "Font"; }
|
||||
|
||||
bool open(const char* font);
|
||||
bool open(const std::string& font);
|
||||
|
||||
virtual bool create(osg::State& state,int pointSize, unsigned int res = 72 );
|
||||
virtual bool create(osg::State& state);
|
||||
virtual void output(osg::State& state, const EncodedText* text) const;
|
||||
|
||||
virtual bool isOk(void) const { return _init; }
|
||||
virtual bool isCreated(void) const { return isOk() && _created; }
|
||||
|
||||
virtual float getWidth(const EncodedText* text) const;
|
||||
virtual int getHeight() const;
|
||||
virtual int getDescender() const;
|
||||
virtual int getAscender() const;
|
||||
|
||||
int getPointSize(void) const { return _pointSize; }
|
||||
int getTextureSize(void) const { return _textureSize; }
|
||||
const std::string& getFontName() const { return _fontName; }
|
||||
|
||||
/// Transfer font settings to another Font object and invalidate this one.
|
||||
void copyAndInvalidate(Font &dest);
|
||||
|
||||
FTFont* getFont(void) { return _font; }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Font();
|
||||
|
||||
virtual void clear();
|
||||
|
||||
virtual FTFont* createFontObj(void)=0;
|
||||
|
||||
bool init(const std::string& font);
|
||||
|
||||
bool _init;
|
||||
bool _created;
|
||||
|
||||
FTFont* _font;
|
||||
std::string _fontName;
|
||||
int _pointSize;
|
||||
int _res;
|
||||
int _textureSize;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class OSGTEXT_EXPORT RasterFont:public Font
|
||||
{
|
||||
public:
|
||||
|
||||
RasterFont():Font(){}
|
||||
RasterFont(const RasterFont& font,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
Font(font,copyop) {}
|
||||
RasterFont(const std::string& /*font*/):Font() {}
|
||||
|
||||
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const RasterFont *>(obj)!=NULL; }
|
||||
virtual const char* libraryName() const { return "osgText"; }
|
||||
virtual const char* className() const { return "RasterFont"; }
|
||||
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
class OSGTEXT_EXPORT VectorFont:public Font
|
||||
{
|
||||
public:
|
||||
VectorFont():Font(),_precision(0.0) {}
|
||||
|
||||
VectorFont(const VectorFont& font,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
Font(font,copyop),
|
||||
_precision(font._precision) {}
|
||||
|
||||
VectorFont(const std::string& /*font*/):Font(){}
|
||||
|
||||
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const VectorFont *>(obj)!=NULL; }
|
||||
virtual const char* libraryName() const { return "osgText"; }
|
||||
virtual const char* className() const { return "VectorFont"; }
|
||||
|
||||
protected:
|
||||
double _precision;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class OSGTEXT_EXPORT BitmapFont:public RasterFont
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
BitmapFont() {}
|
||||
BitmapFont(const BitmapFont& font,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
RasterFont(font,copyop) {}
|
||||
BitmapFont(const std::string& font,
|
||||
int point_size);
|
||||
|
||||
META_Font(osgText,BitmapFont);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
virtual FTFont* createFontObj(void);
|
||||
};
|
||||
|
||||
|
||||
class OSGTEXT_EXPORT PixmapFont:public RasterFont
|
||||
{
|
||||
public:
|
||||
|
||||
PixmapFont() {}
|
||||
PixmapFont(const PixmapFont& font,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
RasterFont(font,copyop) {}
|
||||
|
||||
PixmapFont(const std::string& font,
|
||||
int point_size);
|
||||
|
||||
META_Font(osgText,PixmapFont);
|
||||
|
||||
protected:
|
||||
|
||||
virtual FTFont* createFontObj(void);
|
||||
|
||||
};
|
||||
|
||||
|
||||
class OSGTEXT_EXPORT TextureFont:public RasterFont
|
||||
{
|
||||
public:
|
||||
|
||||
TextureFont() {}
|
||||
TextureFont(const TextureFont& font,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
RasterFont(font,copyop) {}
|
||||
|
||||
TextureFont(const std::string& font,
|
||||
int point_size);
|
||||
|
||||
TextureFont(const std::string& font,
|
||||
int point_size,
|
||||
int textureSize );
|
||||
|
||||
META_Font(osgText,TextureFont);
|
||||
|
||||
protected:
|
||||
|
||||
virtual FTFont* createFontObj(void);
|
||||
|
||||
};
|
||||
|
||||
class OSGTEXT_EXPORT OutlineFont:public VectorFont
|
||||
{
|
||||
public:
|
||||
|
||||
OutlineFont() {}
|
||||
OutlineFont(const OutlineFont& font,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
VectorFont(font,copyop) {}
|
||||
|
||||
OutlineFont(const std::string& font,
|
||||
int point_size,
|
||||
double precision);
|
||||
|
||||
META_Font(osgText,OutlineFont);
|
||||
|
||||
protected:
|
||||
|
||||
virtual FTFont* createFontObj(void);
|
||||
|
||||
|
||||
};
|
||||
|
||||
class OSGTEXT_EXPORT PolygonFont:public VectorFont
|
||||
{
|
||||
// declare the interface to a font.
|
||||
public:
|
||||
|
||||
PolygonFont() {}
|
||||
PolygonFont(const PolygonFont& font,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||
VectorFont(font,copyop) {}
|
||||
// forward declare nested classes.
|
||||
class Glyph;
|
||||
class GlyphTexture;
|
||||
|
||||
Font();
|
||||
|
||||
virtual osg::Object* cloneType() const { return 0; } // cloneType() not appropriate
|
||||
virtual osg::Object* clone(const osg::CopyOp&) const { return 0; } // clone() not appropriate
|
||||
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Font*>(obj)!=NULL; }
|
||||
virtual const char* className() const { return "Font"; }
|
||||
virtual const char* libraryName() const { return "osgText"; }
|
||||
|
||||
virtual std::string getFileName() const = 0;
|
||||
|
||||
/** Set the pixel width and height */
|
||||
virtual void setSize(unsigned int width, unsigned int height) = 0;
|
||||
|
||||
PolygonFont(const std::string& font,
|
||||
int point_size,
|
||||
double precision);
|
||||
unsigned int getWidth() { return _width; }
|
||||
unsigned int getHeight() { return _height; }
|
||||
|
||||
virtual Glyph* getGlyph(unsigned int charcode) = 0;
|
||||
|
||||
PolygonFont(const char* font,
|
||||
int point_size,
|
||||
double precision);
|
||||
virtual osg::Vec2 getKerning(unsigned int leftcharcode,unsigned int rightcharcode) = 0;
|
||||
|
||||
META_Font(osgText,PolygonFont);
|
||||
virtual bool hasVertical() const = 0;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
virtual FTFont* createFontObj(void);
|
||||
virtual ~Font();
|
||||
|
||||
void addGlyph(unsigned int charcode, Glyph* glyph);
|
||||
|
||||
typedef std::vector< osg::ref_ptr<GlyphTexture> > GlyphTextureList;
|
||||
typedef std::vector< osg::ref_ptr<osg::StateSet> > StateSetList;
|
||||
typedef std::map< unsigned int, osg::ref_ptr<Glyph> > GlyphMap;
|
||||
|
||||
GlyphMap _glyphMap;
|
||||
GlyphTextureList _glyphTextureList;
|
||||
StateSetList _stateSetList;
|
||||
|
||||
// current active size of font
|
||||
unsigned int _width;
|
||||
unsigned int _height;
|
||||
|
||||
|
||||
// declare the nested classes.
|
||||
public:
|
||||
|
||||
class OSGTEXT_EXPORT GlyphTexture : public osg::Texture2D
|
||||
{
|
||||
public:
|
||||
|
||||
GlyphTexture();
|
||||
|
||||
void setStateSet(osg::StateSet* stateset) { _stateset = stateset; }
|
||||
osg::StateSet* getStateSet() { return _stateset; }
|
||||
const osg::StateSet* getStateSet() const { return _stateset; }
|
||||
|
||||
bool getSpaceForGlyph(Glyph* glyph, int& posX, int& posY);
|
||||
|
||||
void addGlyph(Glyph* glyph,int posX, int posY);
|
||||
|
||||
virtual void apply(osg::State& state) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~GlyphTexture();
|
||||
|
||||
osg::StateSet* _stateset;
|
||||
|
||||
// parameter used to compute the size and position of empty space
|
||||
// in the texture which could accomodate new glyphs.
|
||||
int _usedY;
|
||||
int _partUsedX;
|
||||
int _partUsedY;
|
||||
|
||||
typedef std::vector<Glyph*> GlyphList;
|
||||
typedef osg::buffered_object<GlyphList> GlyphBuffer;
|
||||
|
||||
GlyphList _glyphs;
|
||||
mutable GlyphBuffer _glyphsToSubload;
|
||||
|
||||
};
|
||||
|
||||
class OSGTEXT_EXPORT Glyph : public osg::Image
|
||||
{
|
||||
public:
|
||||
|
||||
Glyph();
|
||||
virtual ~Glyph();
|
||||
|
||||
unsigned int getGlyphCode() const { return _glyphCode; }
|
||||
|
||||
void setFont(Font* font) { _font = font; }
|
||||
Font* getFont() const { return _font; }
|
||||
|
||||
void setHorizontalBearing(const osg::Vec2& bearing) { _horizontalBearing=bearing; }
|
||||
const osg::Vec2& getHorizontalBearing() const { return _horizontalBearing; }
|
||||
|
||||
void setHorizontalAdvance(float advance) { _horizontalAdvance=advance; }
|
||||
float getHorizontalAdvance() const { return _horizontalAdvance; }
|
||||
|
||||
void setVerticalBearing(const osg::Vec2& bearing) { _verticalBearing=bearing; }
|
||||
const osg::Vec2& getVerticalBearing() const { return _verticalBearing; }
|
||||
|
||||
void setVerticalAdvance(float advance) { _verticalAdvance=advance; }
|
||||
float getVerticalAdvance() const { return _verticalAdvance; }
|
||||
|
||||
|
||||
void setTexture(GlyphTexture* texture) { _texture = texture; }
|
||||
GlyphTexture* getTexture() { return _texture.get(); }
|
||||
const GlyphTexture* getTexture() const { return _texture.get(); }
|
||||
|
||||
osg::StateSet* getStateSet() { return _texture.valid()?_texture->getStateSet():0; }
|
||||
const osg::StateSet* getStateSet() const { return _texture.valid()?_texture->getStateSet():0; }
|
||||
|
||||
void setTexturePosition(int posX,int posY) { _texturePosX = posX; _texturePosY = posY; }
|
||||
int getTexturePositionX() const { return _texturePosX; }
|
||||
int getTexturePositionY() const { return _texturePosY; }
|
||||
|
||||
void setMinTexCoord(const osg::Vec2& coord) { _minTexCoord=coord; }
|
||||
const osg::Vec2& getMinTexCoord() const { return _minTexCoord; }
|
||||
|
||||
void setMaxTexCoord(const osg::Vec2& coord) { _maxTexCoord=coord; }
|
||||
const osg::Vec2& getMaxTexCoord() const { return _maxTexCoord; }
|
||||
|
||||
void subload();
|
||||
|
||||
protected:
|
||||
|
||||
Font* _font;
|
||||
unsigned int _glyphCode;
|
||||
|
||||
osg::Vec2 _horizontalBearing;
|
||||
float _horizontalAdvance;
|
||||
|
||||
osg::Vec2 _verticalBearing;
|
||||
float _verticalAdvance;
|
||||
|
||||
osg::ref_ptr<GlyphTexture> _texture;
|
||||
int _texturePosX;
|
||||
int _texturePosY;
|
||||
osg::Vec2 _minTexCoord;
|
||||
osg::Vec2 _maxTexCoord;
|
||||
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // OSGTEXT_FONT
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSGTEXT_PARAGRAPH
|
||||
#define OSGTEXT_PARAGRAPH
|
||||
|
||||
#include <osg/Geode>
|
||||
#include <osgText/Text>
|
||||
|
||||
namespace osgText {
|
||||
|
||||
class OSGTEXT_EXPORT Paragraph : public osg::Geode
|
||||
{
|
||||
public:
|
||||
|
||||
Paragraph();
|
||||
Paragraph(const Paragraph& paragraph,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
Paragraph(const osg::Vec3& position,const std::string& text,osgText::Font* font);
|
||||
|
||||
META_Node(osgText,Paragraph);
|
||||
|
||||
|
||||
void setFont(osgText::Font* font);
|
||||
osgText::Font* getFont() { return _font.get(); }
|
||||
const osgText::Font* getFont() const { return _font.get(); }
|
||||
|
||||
void setMaximumNoCharactersPerLine(unsigned int maxCharsPerLine);
|
||||
unsigned int getMaximumNoCharactersPerLine() const { return _maxCharsPerLine; }
|
||||
|
||||
void setText(const std::string& text);
|
||||
std::string& getText() { return _text; }
|
||||
const std::string& getText() const { return _text; }
|
||||
|
||||
void setPosition(const osg::Vec3& position);
|
||||
const osg::Vec3& getPosition() const { return _position; }
|
||||
|
||||
void setAlignment(int alignment);
|
||||
int getAlignment() const { return _alignment; }
|
||||
|
||||
float getHeight() const;
|
||||
|
||||
static bool createFormatedText(unsigned int noCharsPerLine,const std::string& str,std::vector<std::string>& formatedText);
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Paragraph() {}
|
||||
|
||||
void createDrawables();
|
||||
|
||||
osg::Vec3 _position;
|
||||
std::string _text;
|
||||
osg::ref_ptr<osgText::Font> _font;
|
||||
int _alignment;
|
||||
unsigned int _maxCharsPerLine;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -10,173 +10,203 @@
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
*
|
||||
* openscenegraph textLib / FTGL wrapper (http://homepages.paradise.net.nz/henryj/code/)
|
||||
*
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* prog: max rheiner;mrn@paus.ch
|
||||
* date: 4/25/2001 (m/d/y)
|
||||
*
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#ifndef OSGTEXT_TEXT
|
||||
#define OSGTEXT_TEXT 1
|
||||
#define OSGTEXT_TEXT 1
|
||||
|
||||
#include <osg/Drawable>
|
||||
#include <osg/GL>
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Vec2>
|
||||
#include <osg/Quat>
|
||||
|
||||
#include <osgText/Font>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace osgText {
|
||||
|
||||
|
||||
class OSGTEXT_EXPORT Text : public osg::Drawable
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
enum AlignmentType
|
||||
{ // from left to right, top to bottom
|
||||
LEFT_TOP,
|
||||
LEFT_CENTER,
|
||||
LEFT_BOTTOM,
|
||||
Text();
|
||||
Text(const Text& text,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
CENTER_TOP,
|
||||
CENTER_CENTER,
|
||||
CENTER_BOTTOM,
|
||||
|
||||
RIGHT_TOP,
|
||||
RIGHT_CENTER,
|
||||
RIGHT_BOTTOM,
|
||||
};
|
||||
|
||||
enum BoundingBoxType
|
||||
{
|
||||
GEOMETRY,
|
||||
GLYPH,
|
||||
};
|
||||
|
||||
enum DrawModeType
|
||||
{ // from left to right, top to bottom
|
||||
TEXT = 1<<0,
|
||||
BOUNDINGBOX = 1<<1,
|
||||
ALIGNMENT = 1<<2,
|
||||
DEFAULT = TEXT,
|
||||
};
|
||||
|
||||
enum AxisAlignment
|
||||
{
|
||||
XY_PLANE,
|
||||
XZ_PLANE,
|
||||
YZ_PLANE
|
||||
};
|
||||
|
||||
Text();
|
||||
Text(const Text& text,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
Text(Font* font);
|
||||
|
||||
virtual osg::Object* cloneType() const { return new Text(); }
|
||||
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new Text(*this,copyop); }
|
||||
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Text*>(obj)!=NULL; }
|
||||
virtual const char* className() const { return "Text"; }
|
||||
virtual const char* libraryName() const { return "osgText"; }
|
||||
|
||||
void setPosition(const osg::Vec2& pos);
|
||||
void setPosition(const osg::Vec3& pos);
|
||||
const osg::Vec3& getPosition() const { return _pos; }
|
||||
virtual osg::Object* cloneType() const { return new Text(); }
|
||||
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new Text(*this,copyop); }
|
||||
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Text*>(obj)!=NULL; }
|
||||
virtual const char* className() const { return "Text"; }
|
||||
virtual const char* libraryName() const { return "osgText"; }
|
||||
|
||||
|
||||
void setColor(const osg::Vec4& color) { _color = color; }
|
||||
osg::Vec4& getColor() { return _color; }
|
||||
const osg::Vec4& getColor() const { return _color; }
|
||||
/** Set the Font to use to render the text.
|
||||
* setFont(0) sets the use of the default font.*/
|
||||
void setFont(Font* font=0);
|
||||
|
||||
/** Set the font, loaded from the specified front file, to use to render the text,
|
||||
* setFont("") sets the use of the default font.*/
|
||||
void setFont(const std::string& fontfile);
|
||||
|
||||
/** Get the font. Return 0 if default is being used.*/
|
||||
const Font* getFont() const { return _font.get(); }
|
||||
|
||||
/** Set the Font reference width and height resolution in texels.
|
||||
* Note, the size may not be supported by current font,
|
||||
* the closest supported font size will be selected.*/
|
||||
void setFontSize(unsigned int width, unsigned int height);
|
||||
|
||||
unsigned int getFontWidth() const { return _fontWidth; }
|
||||
unsigned int getFontHeight() const { return _fontWidth; }
|
||||
|
||||
|
||||
/** TextString is a general purpose vector of char codes (unsigned int's)
|
||||
* which is used internally by Text to represent strings.*/
|
||||
typedef std::vector<unsigned int> TextString;
|
||||
|
||||
/** Set the text using a TextString.*/
|
||||
void setText(const TextString& text);
|
||||
|
||||
/** Set the text using a std::string,
|
||||
* which is converted to an internal TextString.*/
|
||||
void setText(const std::string& text);
|
||||
|
||||
/** Set the text using a wchar_t string,
|
||||
* which is converted to an internal TextString.*/
|
||||
void setText(const wchar_t* text);
|
||||
|
||||
/** Get the const text string.*/
|
||||
const TextString& getText() const { return _text; }
|
||||
|
||||
|
||||
void setDrawMode(int mode) { _drawMode=mode; }
|
||||
int getDrawMode() const { return _drawMode; }
|
||||
/** Set the rendered character size in object coordinates.*/
|
||||
void setCharacterSize(float height,float ascpectRatio=1.0f);
|
||||
|
||||
float getCharacterHeight() const { return _characterHeight; }
|
||||
float getCharacterAspectRatio() const { return _characterAspectRatio; }
|
||||
|
||||
void setBoundingBox(int mode);
|
||||
int getBoundingBox() const { return _boundingBoxType; }
|
||||
|
||||
void setAlignment(int alignment);
|
||||
int getAlignment() const { return _alignment; }
|
||||
|
||||
void setAxisAlignment(AxisAlignment axis) { _axisAlignment = axis; dirtyDisplayList(); }
|
||||
AxisAlignment getAxisAlignment() const { return _axisAlignment; }
|
||||
/** Set the position of text.*/
|
||||
void setPosition(const osg::Vec3& pos);
|
||||
|
||||
/** Get the position of text.*/
|
||||
const osg::Vec3& getPosition() const { return _position; }
|
||||
|
||||
|
||||
void setFont(Font* font);
|
||||
Font* getFont() { return _font.get(); }
|
||||
const Font* getFont() const { return _font.get(); }
|
||||
enum AlignmentType
|
||||
{
|
||||
LEFT_TOP,
|
||||
LEFT_CENTER,
|
||||
LEFT_BOTTOM,
|
||||
|
||||
void setText(const char* text);
|
||||
void setText(const std::string& text);
|
||||
const std::string& getText() const { return _text; }
|
||||
void setText(const wchar_t* text);
|
||||
CENTER_TOP,
|
||||
CENTER_CENTER,
|
||||
CENTER_BOTTOM,
|
||||
|
||||
virtual bool supports(PrimitiveFunctor& pf) const;
|
||||
virtual void accept(PrimitiveFunctor& pf) const;
|
||||
RIGHT_TOP,
|
||||
RIGHT_CENTER,
|
||||
RIGHT_BOTTOM,
|
||||
BASE_LINE /// default.
|
||||
|
||||
};
|
||||
|
||||
void setAlignment(AlignmentType alignment);
|
||||
|
||||
virtual void drawImplementation(osg::State& state) const;
|
||||
virtual void drawBoundingBox(void) const;
|
||||
virtual void drawAlignment(void) const;
|
||||
AlignmentType getAlignment() const { return _alignment; }
|
||||
|
||||
const osg::Vec3& getAlignmentPos() const { return _alignmentPos; };
|
||||
|
||||
void setEncodedText(EncodedText* encodedText) { _encodedText = encodedText; }
|
||||
const EncodedText* getEncodedText() const { return _encodedText.get(); }
|
||||
enum AxisAlignment
|
||||
{
|
||||
XY_PLANE,
|
||||
XZ_PLANE,
|
||||
YZ_PLANE,
|
||||
SCREEN
|
||||
};
|
||||
|
||||
/// override the compile to set up the alignment etc.
|
||||
virtual void compile(osg::State& state) const;
|
||||
void setAxisAlignment(AxisAlignment axis);
|
||||
|
||||
AxisAlignment getAxisAlignment() const { return _axisAlignment; }
|
||||
|
||||
protected:
|
||||
|
||||
enum FontType
|
||||
{
|
||||
UNDEF,
|
||||
BITMAP,
|
||||
PIXMAP,
|
||||
OUTLINE,
|
||||
POLYGON,
|
||||
TEXTURE,
|
||||
};
|
||||
void setRotation(const osg::Quat& quat);
|
||||
|
||||
const osg::Quat& getRotation() const { return _rotation; }
|
||||
|
||||
virtual ~Text();
|
||||
|
||||
virtual void setDefaults(void);
|
||||
virtual bool computeBound(void) const;
|
||||
virtual void calcBounds(osg::Vec3* min,osg::Vec3* max) const;
|
||||
void initAlignment(osg::Vec3* min,osg::Vec3* max);
|
||||
bool initAlignment(void);
|
||||
enum Layout
|
||||
{
|
||||
LEFT_TO_RIGHT, /// default
|
||||
RIGHT_TO_LEFT,
|
||||
VERTICAL
|
||||
};
|
||||
|
||||
void setLayout(Layout layout);
|
||||
|
||||
Layout getLayout() const { return _layout; }
|
||||
|
||||
osg::ref_ptr<Font> _font;
|
||||
|
||||
bool _init;
|
||||
bool _initAlignment;
|
||||
std::string _text;
|
||||
int _fontType;
|
||||
int _alignment;
|
||||
int _drawMode;
|
||||
int _boundingBoxType;
|
||||
AxisAlignment _axisAlignment;
|
||||
void setColor(const osg::Vec4& color);
|
||||
|
||||
const osg::Vec4& getColor() const { return _color; }
|
||||
|
||||
|
||||
enum DrawModeMask
|
||||
{
|
||||
TEXT = 1, /// default
|
||||
BOUNDINGBOX = 2,
|
||||
ALIGNMENT = 4
|
||||
};
|
||||
|
||||
void setDrawMode(unsigned int mode) { _drawMode=mode; }
|
||||
|
||||
unsigned int getDrawMode() const { return _drawMode; }
|
||||
|
||||
|
||||
/** Draw the text.*/
|
||||
virtual void drawImplementation(osg::State& state) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Text();
|
||||
|
||||
virtual bool computeBound() const;
|
||||
|
||||
Font* getActiveFont();
|
||||
const Font* getActiveFont() const;
|
||||
|
||||
|
||||
// members which have public access.
|
||||
osg::ref_ptr<Font> _font;
|
||||
unsigned int _fontWidth;
|
||||
unsigned int _fontHeight;
|
||||
float _characterHeight;
|
||||
float _characterAspectRatio;
|
||||
|
||||
TextString _text;
|
||||
osg::Vec3 _position;
|
||||
AlignmentType _alignment;
|
||||
AxisAlignment _axisAlignment;
|
||||
osg::Quat _rotation;
|
||||
Layout _layout;
|
||||
osg::Vec4 _color;
|
||||
unsigned int _drawMode;
|
||||
|
||||
// internal structures, variable and methods used for rendering of characters.
|
||||
struct GlyphQuads
|
||||
{
|
||||
typedef std::vector<osg::Vec2> Coords;
|
||||
typedef std::vector<osg::Vec2> TexCoords;
|
||||
|
||||
Coords _coords;
|
||||
TexCoords _texcoords;
|
||||
};
|
||||
typedef std::map<osg::ref_ptr<osg::StateSet>,GlyphQuads> TextureGlyphQuadMap;
|
||||
|
||||
// iternal map used for rendering. Set up by the computeGlyphRepresentation() method.
|
||||
TextureGlyphQuadMap _textureGlyphQuadMap;
|
||||
mutable osg::BoundingBox _textBB;
|
||||
|
||||
void computeGlyphRepresentation();
|
||||
|
||||
osg::ref_ptr<EncodedText> _encodedText;
|
||||
|
||||
osg::Vec3 _pos;
|
||||
osg::Vec3 _alignmentPos;
|
||||
osg::Vec4 _color;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // OSGTEXT_TEXT
|
||||
|
||||
#endif
|
||||
|
||||
@@ -104,7 +104,6 @@ class OSGUTIL_EXPORT IntersectVisitor : public osg::NodeVisitor
|
||||
|
||||
protected:
|
||||
|
||||
/** \internal JAVA: SUPPRESS UNBRIDGABLE :JAVA */
|
||||
class IntersectState : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user