From Jean-Sebastien Guay, "I've added a second ctor where no argument is optional, and documented that it's meant to be used when the InteractiveImage is going to be used in a fullscreen HUD.
"
This commit is contained in:
parent
60942d8e72
commit
77c35eabde
@ -418,7 +418,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
root->addChild(overlay);
|
root->addChild(overlay);
|
||||||
|
|
||||||
osgViewer::InteractiveImageHandler* handler = new osgViewer::InteractiveImageHandler(widgetImage.get(), camera);
|
osgViewer::InteractiveImageHandler* handler = new osgViewer::InteractiveImageHandler(widgetImage.get(), texture, camera);
|
||||||
quad->setEventCallback(handler);
|
quad->setEventCallback(handler);
|
||||||
quad->setCullCallback(handler);
|
quad->setCullCallback(handler);
|
||||||
}
|
}
|
||||||
|
@ -407,8 +407,10 @@ class OSGVIEWER_EXPORT InteractiveImageHandler : public osgGA::GUIEventHandler,
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
InteractiveImageHandler(osg::Image* image, osg::Camera* camera = 0):
|
/// Constructor to use when the InteractiveImage is in the 3D scene (i.e. not in a fullscreen HUD overlay).
|
||||||
_image(image), _fullscreen(camera != 0), _camera(camera) {}
|
InteractiveImageHandler(osg::Image* image);
|
||||||
|
/// Constructor to use when the InteractiveImage is in a fullscreen HUD overlay.
|
||||||
|
InteractiveImageHandler(osg::Image* image, osg::Texture2D* texture, osg::Camera* camera);
|
||||||
|
|
||||||
META_Object(osgViewer, InteractiveImageHandler);
|
META_Object(osgViewer, InteractiveImageHandler);
|
||||||
|
|
||||||
@ -428,7 +430,10 @@ protected:
|
|||||||
bool mousePosition(osgViewer::View* view, osg::NodeVisitor* nv, const osgGA::GUIEventAdapter& ea, int& x, int &y) const;
|
bool mousePosition(osgViewer::View* view, osg::NodeVisitor* nv, const osgGA::GUIEventAdapter& ea, int& x, int &y) const;
|
||||||
bool computeIntersections(osgViewer::View* view, float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff) const;
|
bool computeIntersections(osgViewer::View* view, float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff) const;
|
||||||
|
|
||||||
|
void resize(int width, int height);
|
||||||
|
|
||||||
osg::observer_ptr<osg::Image> _image;
|
osg::observer_ptr<osg::Image> _image;
|
||||||
|
osg::observer_ptr<osg::Texture2D> _texture;
|
||||||
|
|
||||||
bool _fullscreen;
|
bool _fullscreen;
|
||||||
osg::observer_ptr<osg::Camera> _camera;
|
osg::observer_ptr<osg::Camera> _camera;
|
||||||
|
@ -20,8 +20,10 @@
|
|||||||
|
|
||||||
#include <osgDB/FileNameUtils>
|
#include <osgDB/FileNameUtils>
|
||||||
|
|
||||||
|
#include <osg/Version>
|
||||||
#include <osg/Geometry>
|
#include <osg/Geometry>
|
||||||
#include <osg/TexMat>
|
#include <osg/TexMat>
|
||||||
|
#include <osg/Texture2D>
|
||||||
#include <osg/TextureRectangle>
|
#include <osg/TextureRectangle>
|
||||||
#include <osg/io_utils>
|
#include <osg/io_utils>
|
||||||
|
|
||||||
@ -624,6 +626,30 @@ void LODScaleHandler::getUsage(osg::ApplicationUsage& usage) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InteractiveImageHandler::InteractiveImageHandler(osg::Image* image) :
|
||||||
|
_image(image),
|
||||||
|
_texture(0),
|
||||||
|
_fullscreen(false),
|
||||||
|
_camera(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
InteractiveImageHandler::InteractiveImageHandler(osg::Image* image, osg::Texture2D* texture, osg::Camera* camera) :
|
||||||
|
_image(image),
|
||||||
|
_texture(texture),
|
||||||
|
_fullscreen(true),
|
||||||
|
_camera(camera)
|
||||||
|
{
|
||||||
|
if (_camera.valid() && _camera->getViewport())
|
||||||
|
{
|
||||||
|
// Send an initial resize event (with the same size) so the image can
|
||||||
|
// resize itself initially.
|
||||||
|
double width = _camera->getViewport()->width();
|
||||||
|
double height = _camera->getViewport()->height();
|
||||||
|
|
||||||
|
resize(width, height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool InteractiveImageHandler::computeIntersections(osgViewer::View* view, float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask) const
|
bool InteractiveImageHandler::computeIntersections(osgViewer::View* view, float x,float y, const osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask) const
|
||||||
{
|
{
|
||||||
@ -822,10 +848,11 @@ bool InteractiveImageHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUI
|
|||||||
}
|
}
|
||||||
case (osgGA::GUIEventAdapter::RESIZE):
|
case (osgGA::GUIEventAdapter::RESIZE):
|
||||||
{
|
{
|
||||||
if (_fullscreen)
|
if (_fullscreen && _camera.valid())
|
||||||
{
|
{
|
||||||
_camera->setViewport(0, 0, ea.getWindowWidth(), ea.getWindowHeight());
|
_camera->setViewport(0, 0, ea.getWindowWidth(), ea.getWindowHeight());
|
||||||
_image->scaleImage(ea.getWindowWidth(), ea.getWindowHeight(), 1);
|
|
||||||
|
resize(ea.getWindowWidth(), ea.getWindowHeight());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -846,4 +873,17 @@ bool InteractiveImageHandler::cull(osg::NodeVisitor* nv, osg::Drawable*, osg::Re
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InteractiveImageHandler::resize(int width, int height)
|
||||||
|
{
|
||||||
|
if (_image.valid())
|
||||||
|
{
|
||||||
|
_image->scaleImage(width, height, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the texture does not rescale the image because
|
||||||
|
// it thinks it should still be the previous size...
|
||||||
|
if (_texture.valid())
|
||||||
|
_texture->setTextureSize(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user