osgWidget.Box
osgWidget.Box
是一个矩形部件,由 osgWidget
库提供支持,它具有以下特点:
osgWidget::Box(const std::string& name);
name
:矩形部件的名称,可选参数。void setWidth(float width);
float getWidth() const;
void setHeight(float height);
float getHeight() const;
setWidth
:设置矩形的宽度(单位:像素)。getWidth
:获取矩形的宽度。setHeight
:设置矩形的高度(单位:像素)。getHeight
:获取矩形的高度。void setBorderWidth(float borderWidth);
float getBorderWidth() const;
void setBorderColor(const osg::Vec4& borderColor);
osg::Vec4 getBorderColor() const;
setBorderWidth
:设置边框的宽度(单位:像素)。getBorderWidth
:获取边框的宽度。setBorderColor
:设置边框的颜色,参数为四元组,分别表示 RGBA 值(每个分量的范围为 0~1)。getBorderColor
:获取边框的颜色。void setBackgroundColor(const osg::Vec4& color);
osg::Vec4 getBackgroundColor() const;
void setBackgroundAlpha(float alpha);
float getBackgroundAlpha() const;
setBackgroundColor
:设置背景色,参数为四元组,分别表示 RGBA 值(每个分量的范围为 0~1)。getBackgroundColor
:获取背景色。setBackgroundAlpha
:设置背景透明度,取值范围为 0~1。getBackgroundAlpha
:获取背景透明度。下面是一个简单的示例,使用 osgWidget.Box
创建一个绿色的矩形,边框为蓝色,大小为 200x100 像素:
#include <osgWidget/Box>
int main()
{
osg::ref_ptr<osgWidget::Box> box = new osgWidget::Box();
box->setWidth(200);
box->setHeight(100);
box->setBackgroundColor(osg::Vec4(0, 1, 0, 1));
box->setBorderWidth(2);
box->setBorderColor(osg::Vec4(0, 0, 1, 1));
return 0;
}