OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

adding tool tips to objects in a 3D scene


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
cbuchner1
Appreciator


Joined: 14 Mar 2012
Posts: 316

PostPosted: Mon Sep 17, 2012 1:13 pm    Post subject:
adding tool tips to objects in a 3D scene
Reply with quote

Hi,

I've been asked to add some tool tips to objects in a 3D scene, and I
wonder if there is anything existing in OSG that would facilitate an
implementation.

Essentially as you hover over a 3D object and leave the mouse there
for about one second, it should pop up with a small overlay containing
some text string that is associated with that object. As soon as the
mouse is moved again, the overlay should vanish.

Could anyone here offer some advice into how to implement this such
behavior with least programming effort, and if possible in a portable
manner?

Christian


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
cbuchner1
Appreciator


Joined: 14 Mar 2012
Posts: 316

PostPosted: Wed Sep 19, 2012 1:46 pm    Post subject:
adding tool tips to objects in a 3D scene
Reply with quote

Quote:
I've been asked to add some tool tips to objects in a 3D scene, and I
wonder if there is anything existing in OSG that would facilitate an
implementation.

I figured it out myself - and I think I got that done with quite minimal effort.

We're already integrating Qt and OpenSceneGraph by means of a
QGraphicsView which displays a QGraphicsScene. The OSG scene graph is
rendered in the drawBackground() implementation of the QGraphicsScene,
and as an added bonus it is even possible to display floating Qt
windows (encapsulated as QGraphicsItems) on top of the scene.

So here's how I integrated Qt's existing tool tip system with the
scene graph. I am overriding the QGraphicsView's event() handler, so
whenever a tool tip is requested by Qt, I will ask the underlying
QGraphicsScene implementation whether a tool tip is required at the
mouse position and display that. Otherwise I fall back to the default
event handler.

bool MyGraphicsView::event(QEvent* e)
{
QHelpEvent *he = static_cast<QHelpEvent*>(e);
QMouseEvent *me = static_cast<QMouseEvent*>(e);

if(he && he->type() == QEvent::ToolTip)
{
QString tip;
bool handle =
((MyGraphicsScene*)scene())->toolTipAt((qreal)he->pos().x(),
(qreal)he->pos().y(), tip);

if (handle)
{
QToolTip::showText(he->globalPos(), tip);
e->accept();
return true;
}
else QToolTip::hideText();
}
else if (me)
{
QToolTip::hideText();
}
return QGraphicsView::event(e);
}

The QGraphicsScene provides a hint as to whether a tool tip is
supposed to be shown by first checking whether a QGraphicsItem under
the mouse position - if not it means that the mouse is hovering over
content rendered by OSG. So it will shoot an intersector into the
scene graph under the mouse position. Our OpenGLScene implementation
also implements an osg::Viewer instance through multiple inheritance -
so I can just cast our object pointer to osgViewer::View and use the
computeIntersections() member. But for some unknown reason I had to
invert the vertical coordinate.

For now I display the osg geode's name (if defines) as tool tip (if it
is defined). Other uses like context sensitive pop up menus are now
within reach. Cool!

bool MyGraphicsScene::toolTipAt(qreal x, qreal y, QString& tmp)
{
QGraphicsItem *item;

// first make sure we're not hovering over a displayed QGraphicsItem
if ((item = itemAt(x, y)) == NULL)
{
osgUtil::LineSegmentIntersector::Intersections intersections;

osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(this);
osgViewer::View* view = dynamic_cast<osgViewer::View*>(viewer);

// compute intersections with geometry cylinders
if (view->computeIntersections(x, sceneRect().height()-y,
intersections, 4))
{
for(osgUtil::LineSegmentIntersector::Intersections::iterator
hitr = intersections.begin();
hitr != intersections.end();
++hitr)
{
std::ostringstream os;
if (!hitr->nodePath.empty() &&
!(hitr->nodePath.back()->getName().empty()))
{
tmp = QString(hitr->nodePath.back()->getName().c_str());
return true;
}
}
}
}
return false;
}

I hope this code is of some use to other people, so I am posting it here.

Ciao,

Christian


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Different views hide/show different n... icf80 General 13 Wed Apr 17, 2019 9:56 am View latest post
No new posts Removing objects with shared GL state... AnyOldName3 General 8 Wed Mar 20, 2019 5:05 pm View latest post
No new posts Deep cloning an active root scene node Robert Lockyer General 7 Thu Feb 28, 2019 5:52 pm View latest post
No new posts why does the adding of lighting shade... mirro General 0 Mon Feb 11, 2019 3:03 am View latest post
No new posts Could not find plugin to load objects sdef General [3rdparty] 1 Sat Oct 27, 2018 6:10 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP