From 213a370c25ade6af8bfcba37a5eeb14294d9d3dd Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 12 Dec 2007 17:48:20 +0000 Subject: [PATCH] Added new setFont(ref_ptr<>) variants to Text and Text3D --- include/osgText/Text | 5 ++- include/osgText/Text3D | 6 +++- src/osgText/Text.cpp | 6 ++-- src/osgText/Text3D.cpp | 4 +-- src/osgWrappers/osgText/Text.cpp | 49 ++++++++++++++++++++++++++++-- src/osgWrappers/osgText/Text3D.cpp | 49 ++++++++++++++++++++++++++++-- 6 files changed, 108 insertions(+), 11 deletions(-) diff --git a/include/osgText/Text b/include/osgText/Text index cc8a8f2e0..dca04fb3b 100644 --- a/include/osgText/Text +++ b/include/osgText/Text @@ -40,7 +40,10 @@ public: /** Set the Font to use to render the text. * setFont(0) sets the use of the default font.*/ - void setFont(Font* font=0); + inline void setFont(Font* font=0) { setFont(osg::ref_ptr(font)); }; + + /** Set the Font to use to render the text.*/ + void setFont(osg::ref_ptr font); /** Set the font, loaded from the specified front file, to use to render the text, * setFont("") sets the use of the default font. diff --git a/include/osgText/Text3D b/include/osgText/Text3D index ad7e78ffb..d864d6a7b 100644 --- a/include/osgText/Text3D +++ b/include/osgText/Text3D @@ -75,7 +75,11 @@ public: /** Set the Font to use to render the text. * setFont(0) sets the use of the default font.*/ - void setFont(Font3D* font=0); + inline void setFont(Font3D* font=0) { setFont(osg::ref_ptr(font)); }; + + /** Set the Font to use to render the text.*/ + void setFont(osg::ref_ptr font); + /** Set the font, loaded from the specified front file, to use to render the text, * setFont("") sets the use of the default font. diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index 16148d056..186b6a61c 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -67,12 +67,12 @@ Text::~Text() { } -void Text::setFont(Font* font) +void Text::setFont(osg::ref_ptr font) { if (_font==font) return; osg::StateSet* previousFontStateSet = _font.valid() ? _font->getStateSet() : DefaultFont::instance()->getStateSet(); - osg::StateSet* newFontStateSet = font ? font->getStateSet() : DefaultFont::instance()->getStateSet(); + osg::StateSet* newFontStateSet = font.valid() ? font->getStateSet() : DefaultFont::instance()->getStateSet(); if (getStateSet() == previousFontStateSet) { @@ -86,7 +86,7 @@ void Text::setFont(Font* font) void Text::setFont(const std::string& fontfile) { - setFont(readRefFontFile(fontfile).get()); + setFont(readRefFontFile(fontfile)); } diff --git a/src/osgText/Text3D.cpp b/src/osgText/Text3D.cpp index e6973a122..0dd3c34b9 100644 --- a/src/osgText/Text3D.cpp +++ b/src/osgText/Text3D.cpp @@ -42,7 +42,7 @@ Text3D::Text3D(const Text3D & text3D, const osg::CopyOp & copyop): // TODO //} -void Text3D::setFont(Font3D * font) +void Text3D::setFont(osg::ref_ptr font) { _font = font; @@ -51,7 +51,7 @@ void Text3D::setFont(Font3D * font) void Text3D::setFont(const std::string & fontfile) { - setFont(readRefFont3DFile(fontfile).get()); + setFont(readRefFont3DFile(fontfile)); } String::iterator Text3D::computeLastCharacterOnLine(osg::Vec2& cursor, String::iterator first,String::iterator last) diff --git a/src/osgWrappers/osgText/Text.cpp b/src/osgWrappers/osgText/Text.cpp index 7f352a56e..e446843a7 100644 --- a/src/osgWrappers/osgText/Text.cpp +++ b/src/osgWrappers/osgText/Text.cpp @@ -99,6 +99,11 @@ BEGIN_OBJECT_REFLECTOR(osgText::Text) __void__setFont__Font_P1, "Set the Font to use to render the text. ", "setFont(0) sets the use of the default font. "); + I_Method1(void, setFont, IN, osg::ref_ptr< osgText::Font >, font, + Properties::NON_VIRTUAL, + __void__setFont__osg_ref_ptrT1_Font_, + "Set the Font to use to render the text. ", + ""); I_Method1(void, setFont, IN, const std::string &, fontfile, Properties::NON_VIRTUAL, __void__setFont__C5_std_string_R1, @@ -421,9 +426,9 @@ BEGIN_OBJECT_REFLECTOR(osgText::Text) I_SimpleProperty(const osg::Vec4 &, ColorGradientTopRight, __C5_osg_Vec4_R1__getColorGradientTopRight, 0); - I_SimpleProperty(osgText::Font *, Font, + I_SimpleProperty(osg::ref_ptr< osgText::Font >, Font, 0, - __void__setFont__Font_P1); + __void__setFont__osg_ref_ptrT1_Font_); I_SimpleProperty(const osgText::Text::TextureGlyphQuadMap &, TextureGlyphQuadMap, __C5_TextureGlyphQuadMap_R1__getTextureGlyphQuadMap, 0); @@ -519,6 +524,46 @@ BEGIN_VALUE_REFLECTOR(osgText::Text::GlyphQuads) I_PublicMemberProperty(osgText::Text::GlyphQuads::ColorCoords, _colorCoords); END_REFLECTOR +BEGIN_VALUE_REFLECTOR(osg::ref_ptr< osgText::Font >) + I_DeclaringFile("osg/ref_ptr"); + I_Constructor0(____ref_ptr, + "", + ""); + I_Constructor1(IN, osgText::Font *, ptr, + Properties::NON_EXPLICIT, + ____ref_ptr__T_P1, + "", + ""); + I_Constructor1(IN, const osg::ref_ptr< osgText::Font > &, rp, + Properties::NON_EXPLICIT, + ____ref_ptr__C5_ref_ptr_R1, + "", + ""); + I_Method0(osgText::Font *, get, + Properties::NON_VIRTUAL, + __T_P1__get, + "", + ""); + I_Method0(bool, valid, + Properties::NON_VIRTUAL, + __bool__valid, + "", + ""); + I_Method0(osgText::Font *, release, + Properties::NON_VIRTUAL, + __T_P1__release, + "", + ""); + I_Method1(void, swap, IN, osg::ref_ptr< osgText::Font > &, rp, + Properties::NON_VIRTUAL, + __void__swap__ref_ptr_R1, + "", + ""); + I_SimpleProperty(osgText::Font *, , + __T_P1__get, + 0); +END_REFLECTOR + BEGIN_VALUE_REFLECTOR(osg::ref_ptr< osgText::Font::GlyphTexture >) I_DeclaringFile("osg/ref_ptr"); I_Constructor0(____ref_ptr, diff --git a/src/osgWrappers/osgText/Text3D.cpp b/src/osgWrappers/osgText/Text3D.cpp index 4261bca05..c2a5887d5 100644 --- a/src/osgWrappers/osgText/Text3D.cpp +++ b/src/osgWrappers/osgText/Text3D.cpp @@ -93,6 +93,11 @@ BEGIN_OBJECT_REFLECTOR(osgText::Text3D) __void__setFont__Font3D_P1, "Set the Font to use to render the text. ", "setFont(0) sets the use of the default font. "); + I_Method1(void, setFont, IN, osg::ref_ptr< osgText::Font3D >, font, + Properties::NON_VIRTUAL, + __void__setFont__osg_ref_ptrT1_Font3D_, + "Set the Font to use to render the text. ", + ""); I_Method1(void, setFont, IN, const std::string &, fontfile, Properties::NON_VIRTUAL, __void__setFont__C5_std_string_R1, @@ -171,9 +176,9 @@ BEGIN_OBJECT_REFLECTOR(osgText::Text3D) I_SimpleProperty(float, CharacterDepth, __float__getCharacterDepth, __void__setCharacterDepth__float); - I_SimpleProperty(osgText::Font3D *, Font, + I_SimpleProperty(osg::ref_ptr< osgText::Font3D >, Font, 0, - __void__setFont__Font3D_P1); + __void__setFont__osg_ref_ptrT1_Font3D_); I_SimpleProperty(osgText::Text3D::RenderMode, RenderMode, __RenderMode__getRenderMode, __void__setRenderMode__RenderMode); @@ -182,3 +187,43 @@ BEGIN_OBJECT_REFLECTOR(osgText::Text3D) __void__setThreadSafeRefUnref__bool); END_REFLECTOR +BEGIN_VALUE_REFLECTOR(osg::ref_ptr< osgText::Font3D >) + I_DeclaringFile("osg/ref_ptr"); + I_Constructor0(____ref_ptr, + "", + ""); + I_Constructor1(IN, osgText::Font3D *, ptr, + Properties::NON_EXPLICIT, + ____ref_ptr__T_P1, + "", + ""); + I_Constructor1(IN, const osg::ref_ptr< osgText::Font3D > &, rp, + Properties::NON_EXPLICIT, + ____ref_ptr__C5_ref_ptr_R1, + "", + ""); + I_Method0(osgText::Font3D *, get, + Properties::NON_VIRTUAL, + __T_P1__get, + "", + ""); + I_Method0(bool, valid, + Properties::NON_VIRTUAL, + __bool__valid, + "", + ""); + I_Method0(osgText::Font3D *, release, + Properties::NON_VIRTUAL, + __T_P1__release, + "", + ""); + I_Method1(void, swap, IN, osg::ref_ptr< osgText::Font3D > &, rp, + Properties::NON_VIRTUAL, + __void__swap__ref_ptr_R1, + "", + ""); + I_SimpleProperty(osgText::Font3D *, , + __T_P1__get, + 0); +END_REFLECTOR +