From 91c3f6311027d65a235162d7408f1b486ab52eb6 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Tue, 17 Jul 2012 01:02:03 +0200 Subject: [PATCH] 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 --- src/Canvas/elements/element.cxx | 7 +++++++ src/Canvas/elements/path.cxx | 20 ++++++++++++++++++++ src/Canvas/elements/text.cxx | 8 +++++++- src/GUI/CanvasWidget.cxx | 2 +- src/Instrumentation/od_gauge.cxx | 2 +- 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/Canvas/elements/element.cxx b/src/Canvas/elements/element.cxx index 15934556f..b01b36966 100644 --- a/src/Canvas/elements/element.cxx +++ b/src/Canvas/elements/element.cxx @@ -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); } diff --git a/src/Canvas/elements/path.cxx b/src/Canvas/elements/path.cxx index a002f509b..63b34f170 100644 --- a/src/Canvas/elements/path.cxx +++ b/src/Canvas/elements/path.cxx @@ -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 _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() ); } diff --git a/src/Canvas/elements/text.cxx b/src/Canvas/elements/text.cxx index dd23e921f..291765d3c 100644 --- a/src/Canvas/elements/text.cxx +++ b/src/Canvas/elements/text.cxx @@ -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() ); } diff --git a/src/GUI/CanvasWidget.cxx b/src/GUI/CanvasWidget.cxx index f1647d496..003660de5 100644 --- a/src/GUI/CanvasWidget.cxx +++ b/src/GUI/CanvasWidget.cxx @@ -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); diff --git a/src/Instrumentation/od_gauge.cxx b/src/Instrumentation/od_gauge.cxx index 6daab2ba8..6314e734a 100644 --- a/src/Instrumentation/od_gauge.cxx +++ b/src/Instrumentation/od_gauge.cxx @@ -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(