From: Thomas Geymayer Date: Fri, 15 Feb 2013 11:32:31 +0000 (+0100) Subject: CanvasImage: Use image/canvas size rather than texture size X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1784327c479d73b62623b151bb891e867422d816;p=simgear.git CanvasImage: Use image/canvas size rather than texture size --- diff --git a/simgear/canvas/elements/CanvasImage.cxx b/simgear/canvas/elements/CanvasImage.cxx index c41c4897..ee8f204b 100644 --- a/simgear/canvas/elements/CanvasImage.cxx +++ b/simgear/canvas/elements/CanvasImage.cxx @@ -324,24 +324,42 @@ namespace canvas _node_src_rect->setFloatValue("right", 1); _node_src_rect->setFloatValue("bottom", 1); } + + if( !_region.width() || !_region.height() ) + { + // Default to image size. + // TODO handle showing only part of image? + const SGRect& dim = getTextureDimensions(); + _node->setFloatValue("size[0]", dim.width()); + _node->setFloatValue("size[1]", dim.height()); + } } //---------------------------------------------------------------------------- SGRect Image::getTextureDimensions() const { - osg::Texture2D *texture = !_src_canvas.expired() - ? _src_canvas.lock()->getTexture() - : _texture.get(); - - if( !texture ) - return SGRect(); - - return SGRect - ( - 0,0, - texture->getTextureWidth(), - texture->getTextureHeight() - ); + CanvasPtr canvas = _src_canvas.lock(); + SGRect dim(0,0); + + // Use canvas/image dimensions rather than texture dimensions, as they could + // be resized internally by OpenSceneGraph (eg. to nearest power of two). + if( canvas ) + { + dim.setRight( canvas->getViewWidth() ); + dim.setBottom( canvas->getViewHeight() ); + } + else if( _texture ) + { + osg::Image* img = _texture->getImage(); + + if( img ) + { + dim.setRight( img->s() ); + dim.setBottom( img->t() ); + } + } + + return dim; } } // namespace canvas