// Copyright (C) 2002-2003 Gideon May (gideon@computer.org) // // Permission to copy, use, sell and distribute this software is granted // provided this copyright notice appears in all copies. // Permission to modify the code and to distribute modified code is granted // provided this copyright notice appears in all copies, and a notice // that the code was modified is included with the copyright notice. // // This software is provided "as is" without express or implied warranty, // and with no claim as to its suitability for any purpose. #include #include #include #include #include #include #include #include #include #include "held_ptr.hpp" using namespace boost::python; namespace { void setFont(osgText::Text * text) { text->setFont(); } void setFont_1(osgText::Text * text, osgText::Font * font) { text->setFont(font); } void setFont_2(osgText::Text * text, const std::string &fontfile) { text->setFont(fontfile); } osgText::Text* asText(osg::Drawable * drawable) { return dynamic_cast(drawable); } } BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(setCharacterSize_overloads, osgText::Text::setCharacterSize, 1, 2); namespace PyOSGText { void init_Text() { def("asText", asText, return_value_policy()); class_, bases, boost::noncopyable > text("Text", no_init); scope text_scope(text); text.def(init<>()); text.def("setFont", &setFont); text.def("setFont", &setFont_1); /** Set the Font to use to render the text. * setFont(0) sets the use of the default font.*/ text.def("setFont", &setFont_2); /** Set the font, loaded from the specified front file, to use to render the text, * setFont("") sets the use of the default font.*/ text.def("getFont", &osgText::Text::getFont, return_value_policy()); /** Get the font. Return 0 if default is being used.*/ text.def("setFontResolution", &osgText::Text::setFontResolution); /** 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.*/ text.def("getFontWidth", &osgText::Text::getFontWidth); text.def("getFontHeight", &osgText::Text::getFontHeight); text.def("setText", (void (osgText::Text::*)(const osgText::String&)) &osgText::Text::setText); /** Set the text using a osgText::String.*/ text.def("setText", (void (osgText::Text::*)(const std::string&)) &osgText::Text::setText); text.def("setText", (void (osgText::Text::*)(const std::string&, osgText::String::Encoding)) &osgText::Text::setText); text.def("getText", (osgText::String &(osgText::Text::*)()) &osgText::Text::getText, return_internal_reference<>()); /** Get the text string. * Note, if you modify the string you must call Text::update() for * the internal glyph reprentation to be updated.*/ text.def("update", &osgText::Text::update); /** update internal glyph respresnetation used for rendering, * and bounding volume.*/ text.def("setPosition", &osgText::Text::setPosition); text.def("setColor", &osgText::Text::setColor); text.def("getPosition", &osgText::Text::getPosition, return_value_policy()); text.def("getColor", &osgText::Text::getColor, return_value_policy()); text.def("setDrawMode", &osgText::Text::setDrawMode); text.def("getDrawMode", &osgText::Text::getDrawMode); text.def("setAlignment", &osgText::Text::setAlignment); text.def("getAlignment", &osgText::Text::getAlignment); text.def("setAxisAlignment", &osgText::Text::setAxisAlignment); text.def("setCharacterSize", &osgText::Text::setCharacterSize, setCharacterSize_overloads()); text.def("getCharacterHeight", &osgText::Text::getCharacterHeight); text.def("getCharacterAspectRatio", &osgText::Text::getCharacterAspectRatio); text.def("setMaximumWidth", &osgText::Text::setMaximumWidth); /** Set the maximum width of the text box. * With horizontal layouts any characters which do not fit are wrapped around. * 0 or negative values indicate that no maximum width is set, lines can be as long as * they need be to fit thre required text*/ text.def("getMaximumWidth", &osgText::Text::getMaximumWidth); /** Get the maximim width of the text box.*/ text.def("setMaximumHeight", &osgText::Text::setMaximumHeight); /** Set the maximum height of the text box. * With horizontal layouts any characters which do not fit are wrapped around. * 0 or negative values indicate that no maximum height is set, lines can be as long as * they need be to fit thre required text*/ text.def("getMaximumHeight", &osgText::Text::getMaximumHeight); /** Get the maximum height of the text box.*/ text.def("setAlignment", &osgText::Text::setAlignment); text.def("getAlignment", &osgText::Text::getAlignment); text.def("setAxisAlignment", &osgText::Text::setAxisAlignment); text.def("setRotation", &osgText::Text::setRotation); text.def("setAutoRotateToScreen", &osgText::Text::setAutoRotateToScreen); text.def("getAutoRotateToScreen", &osgText::Text::getAutoRotateToScreen); text.def("setLayout", &osgText::Text::setLayout); text.def("setColor", &osgText::Text::setColor); text.def("setDrawMode", &osgText::Text::setDrawMode); text.def("setCharacterSizeMode", &osgText::Text::setCharacterSizeMode); text.def("getCharacterSizeMode", &osgText::Text::getCharacterSizeMode); enum_ alignment("AlignmentType"); # define OSG_ENUM_ALIGNMENT(VALUE) \ (alignment.value(#VALUE, osgText::Text::VALUE), \ text.def(#VALUE, object(osgText::Text::VALUE))) OSG_ENUM_ALIGNMENT(LEFT_TOP); OSG_ENUM_ALIGNMENT(LEFT_CENTER); OSG_ENUM_ALIGNMENT(LEFT_BOTTOM); OSG_ENUM_ALIGNMENT(CENTER_TOP); OSG_ENUM_ALIGNMENT(CENTER_CENTER); OSG_ENUM_ALIGNMENT(CENTER_BOTTOM); OSG_ENUM_ALIGNMENT(RIGHT_TOP); OSG_ENUM_ALIGNMENT(RIGHT_CENTER); OSG_ENUM_ALIGNMENT(RIGHT_BOTTOM); OSG_ENUM_ALIGNMENT(LEFT_BASE_LINE); OSG_ENUM_ALIGNMENT(CENTER_BASE_LINE); OSG_ENUM_ALIGNMENT(RIGHT_BASE_LINE); OSG_ENUM_ALIGNMENT(BASE_LINE); enum_ axis("AxisAlignment"); # define OSG_ENUM_AXIS(VALUE) \ (axis.value(#VALUE, osgText::Text::VALUE), \ text.def(#VALUE, object(osgText::Text::VALUE))) OSG_ENUM_AXIS(XY_PLANE); OSG_ENUM_AXIS(REVERSED_XY_PLANE); OSG_ENUM_AXIS(XZ_PLANE); OSG_ENUM_AXIS(REVERSED_XZ_PLANE); OSG_ENUM_AXIS(YZ_PLANE); OSG_ENUM_AXIS(REVERSED_YZ_PLANE); OSG_ENUM_AXIS(SCREEN); enum_ layout("Layout"); # define OSG_ENUM_LAYOUT(VALUE) \ (layout.value(#VALUE, osgText::Text::VALUE), \ text.def(#VALUE, object(osgText::Text::VALUE))) OSG_ENUM_LAYOUT(LEFT_TO_RIGHT); OSG_ENUM_LAYOUT(RIGHT_TO_LEFT); OSG_ENUM_LAYOUT(VERTICAL); enum_ draw("DrawModeMask"); # define OSG_ENUM_DRAW(VALUE) \ (draw.value(#VALUE, osgText::Text::VALUE), \ text.def(#VALUE, object(osgText::Text::VALUE))) OSG_ENUM_DRAW(TEXT); OSG_ENUM_DRAW(BOUNDINGBOX); OSG_ENUM_DRAW(ALIGNMENT); enum_ characterSizeMode("CharacterSizeMode"); # define OSG_ENUM_CHARACTER_SIZE_MODE(VALUE) \ (characterSizeMode.value(#VALUE, osgText::Text::VALUE), \ text.def(#VALUE, object(osgText::Text::VALUE))) OSG_ENUM_CHARACTER_SIZE_MODE(OBJECT_COORDS); OSG_ENUM_CHARACTER_SIZE_MODE(SCREEN_COORDS); OSG_ENUM_CHARACTER_SIZE_MODE(OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT); } }