Files
OpenSceneGraph/src/osgPlugins/osgText/IO_Paragraph.cpp
Robert Osfield 00cc3a1833 Converted the instance of osgNew and osgDelete back to new and delete as part
of depecating the include/osg/MemoryManager
2002-12-16 13:40:58 +00:00

101 lines
2.4 KiB
C++

#include <osgText/Paragraph>
#include <osgText/Font>
#include <iostream>
#include <string>
#include <osg/Vec3>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
bool Paragraph_readLocalData(osg::Object &obj, osgDB::Input &fr);
bool Paragraph_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
// osgDB::RegisterDotOsgWrapperProxy Paragraph_Proxy
// (
// new osgText::Paragraph,
// "Paragraph",
// "Object Node Geode Paragraph",
// Paragraph_readLocalData,
// Paragraph_writeLocalData
// );
//
bool Paragraph_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
osgText::Paragraph &myobj = static_cast<osgText::Paragraph &>(obj);
bool itAdvanced = false;
// font
osgText::Font *font = dynamic_cast<osgText::Font *>(fr.readObject());
if (font) {
myobj.setFont(font);
itAdvanced = true;
}
// maximum chars
if (fr[0].matchWord("maximumNoCharactersPerLine")) {
int i;
if (fr[1].getInt(i)) {
myobj.setMaximumNoCharactersPerLine(i);
fr += 2;
itAdvanced = true;
}
}
// text
if (fr[0].matchWord("text") && fr[1].isString()) {
myobj.setText(std::string(fr[1].getStr()));
fr += 2;
itAdvanced = true;
}
// position
if (fr[0].matchWord("position")) {
osg::Vec3 p;
if (fr[1].getFloat(p.x()) && fr[2].getFloat(p.y()) && fr[3].getFloat(p.z())) {
myobj.setPosition(p);
fr += 4;
itAdvanced = true;
}
}
// alignment
if (fr[0].matchWord("alignment")) {
int i;
if (fr[1].getInt(i)) {
myobj.setAlignment(i);
fr += 2;
itAdvanced = true;
}
}
return itAdvanced;
}
bool Paragraph_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
{
const osgText::Paragraph &myobj = static_cast<const osgText::Paragraph &>(obj);
// font
fw.writeObject(*myobj.getFont());
// maximum chars
fw.indent() << "maximumNoCharactersPerLine " << myobj.getMaximumNoCharactersPerLine() << std::endl;
// text
fw.indent() << "text " << myobj.getText() << std::endl;
// position
osg::Vec3 p = myobj.getPosition();
fw.indent() << "position " << p.x() << " " << p.y() << " " << p.z() << std::endl;
// alignment
fw.indent() << "alignment " << myobj.getAlignment() << std::endl;
return true;
}