1
0
Fork 0

Canvas: UTF-8 support and more settings exposed.

- Allow hiding objects
 - Use UTF-8 encoding for text elements
 - Add paramter max-width to text elements
 - Support stroke-linecap for path elements
 - Fix mouse coords
 - Set better mipmap filter
This commit is contained in:
Thomas Geymayer 2012-07-17 01:02:03 +02:00
parent e81db175f4
commit 91c3f63110
5 changed files with 36 additions and 3 deletions

View file

@ -40,6 +40,10 @@ namespace canvas
//----------------------------------------------------------------------------
void Element::update(double dt)
{
if( !_transform->getNodeMask() )
// Don't do anything if element is hidden
return;
if( _transform_dirty )
{
osg::Matrix m;
@ -201,6 +205,9 @@ namespace canvas
{
if( child->getNameString() == "update" )
update(0);
else if( child->getNameString() == "visible" )
// TODO check if we need another nodemask
_transform->setNodeMask( child->getBoolValue() ? 0xffffffff : 0 );
else
childChanged(child);
}

View file

@ -41,6 +41,7 @@ namespace canvas
_paint_fill(VG_INVALID_HANDLE),
_attributes_dirty(~0),
_stroke_width(1),
_stroke_linecap(VG_CAP_BUTT),
_fill(false)
{
setSupportsDisplayList(false);
@ -114,6 +115,21 @@ namespace canvas
_attributes_dirty |= FILL_COLOR;
}
/**
* Set stroke-linecap
*
* @see http://www.w3.org/TR/SVG/painting.html#StrokeLinecapProperty
*/
void setStrokeLinecap(const std::string& linecap)
{
if( linecap == "round" )
_stroke_linecap = VG_CAP_ROUND;
else if( linecap == "square" )
_stroke_linecap = VG_CAP_SQUARE;
else
_stroke_linecap = VG_CAP_BUTT;
}
/**
* Draw callback
*/
@ -175,6 +191,7 @@ namespace canvas
vgSetPaint(_paint, VG_STROKE_PATH);
vgSetf(VG_STROKE_LINE_WIDTH, _stroke_width);
vgSeti(VG_STROKE_CAP_STYLE, _stroke_linecap);
vgSetfv( VG_STROKE_DASH_PATTERN,
_stroke_dash.size(),
_stroke_dash.empty() ? 0 : &_stroke_dash[0] );
@ -244,6 +261,7 @@ namespace canvas
VGfloat _stroke_color[4];
VGfloat _stroke_width;
std::vector<VGfloat> _stroke_dash;
VGCapStyle _stroke_linecap;
bool _fill;
VGfloat _fill_color[4];
@ -371,6 +389,8 @@ namespace canvas
else if( child->getNameString() == "stroke-width"
|| child->getNameString() == "stroke-dasharray" )
_attributes_dirty |= STROKE;
else if( child->getNameString() == "stroke-linecap" )
_path->setStrokeLinecap( child->getStringValue() );
else if( child->getNameString() == "fill" )
_path->enableFill( child->getBoolValue() );
}

View file

@ -149,7 +149,13 @@ namespace canvas
if( _font_size == child || _font_aspect == child )
_attributes_dirty |= FONT_SIZE;
else if( child->getNameString() == "text" )
_text->setText( child->getStringValue() );
_text->setText
(
osgText::String( child->getStringValue(),
osgText::String::ENCODING_UTF8 )
);
else if( child->getNameString() == "max-width" )
_text->setMaximumWidth( child->getFloatValue() );
else if( child->getNameString() == "font" )
setFont( child->getStringValue() );
}

View file

@ -95,7 +95,7 @@ void CanvasWidget::doHit(int button, int updown, int x, int y)
return;
_mouse_x->setIntValue(x - abox.min[0]);
_mouse_y->setIntValue(y - abox.min[1]);
_mouse_y->setIntValue(abox.max[1] - y);
if( updown == PU_DRAG )
_mouse_drag->setIntValue(button);

View file

@ -255,7 +255,7 @@ void FGODGauge::updateSampling()
texture->setFilter(
osg::Texture2D::MIN_FILTER,
_use_mipmapping ? osg::Texture2D::LINEAR_MIPMAP_NEAREST
_use_mipmapping ? osg::Texture2D::LINEAR_MIPMAP_LINEAR
: osg::Texture2D::LINEAR
);
camera->attach(