osgUI.TextSettings是一个用于设置OSG中文本属性的类。它可以设置字体、字号、粗细、颜色、对齐方式等。
osgUI::TextSettings(std::string fontPath = "", float fontSize = 20, bool bold = false, bool italic = false);
fontPath: 字体文件的路径。fontSize: 字号大小。bold: 是否粗体。italic: 是否斜体。void setFontPath(std::string fontPath);
std::string getFontPath() const;
setFontPath: 设置字体文件路径。getFontPath: 获取字体文件路径。void setFontSize(float fontSize);
float getFontSize() const;
setFontSize: 设置字号大小。getFontSize: 获取字号大小。void setBold(bool bold);
bool isBold() const;
setBold: 设置是否粗体。isBold: 是否为粗体。void setItalic(bool italic);
bool isItalic() const;
setItalic: 设置是否斜体。isItalic: 是否为斜体。void setColor(osg::Vec4f color);
osg::Vec4f getColor() const;
setColor: 设置字体颜色,使用osg::Vec4f类型来表示颜色。getColor: 获取字体颜色。void setAlignment(osgText::Text::AlignmentType align);
osgText::Text::AlignmentType getAlignment() const;
setAlignment:设置文本的对齐方式,使用osgText::Text::AlignmentType类型,包含LEFT、CENTER、RIGHT三种。getAlignment: 获取文本的对齐方式。osgUI::TextSettings settings("D:/fonts/simhei.ttf", 30, true, false);
settings.setColor(osg::Vec4f(1.0, 0.0, 0.0, 1.0));
settings.setAlignment(osgText::Text::CENTER_CENTER);
以上示例创建了一个文本设置对象,设置字体文件路径、字号、粗体、颜色和对齐方式。