Skip to content

Commit 0bcb334

Browse files
committed
onMouseDown handling
1 parent 13cd875 commit 0bcb334

File tree

3 files changed

+55
-12
lines changed

3 files changed

+55
-12
lines changed

src/plugins/globe/Controls.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,8 +1398,9 @@ bool
13981398
ControlCanvas::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
13991399
{
14001400
bool handled = false;
1401-
if ( ea.getEventType() == osgGA::GUIEventAdapter::FRAME )
1402-
return handled;
1401+
//Filtered in osgEarth
1402+
//if ( ea.getEventType() == osgGA::GUIEventAdapter::FRAME )
1403+
// return handled;
14031404

14041405
float invY = _context._vp->height() - ea.getY();
14051406

src/plugins/globe/globe_plugin.cpp

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,22 @@ struct MyClickHandler : public ControlEventHandler
113113
}
114114
};
115115

116+
struct PanControlHandler : public NavigationControlHandler
117+
{
118+
PanControlHandler( osgEarthUtil::EarthManipulator* manip, double dx, double dy ) : _manip(manip), _dx(dx), _dy(dy) { }
119+
virtual void onMouseDown( Control* control, int mouseButtonMask )
120+
{
121+
OE_NOTICE << "Thank you for clicking on " << typeid(control).name() << mouseButtonMask
122+
<< std::endl;
123+
_manip->pan( _dx, _dy );
124+
}
125+
private:
126+
osg::observer_ptr<osgEarthUtil::EarthManipulator> _manip;
127+
double _dx;
128+
double _dy;
129+
};
130+
131+
116132
void GlobePlugin::run()
117133
{
118134
#ifdef QGISDEBUG
@@ -304,13 +320,13 @@ void GlobePlugin::setupControls()
304320

305321
//Move Up
306322
osg::Image* moveUpImg = osgDB::readImageFile( imgDir + "/move-up.png" );
307-
ImageControl* moveUp = new ImageControl( moveUpImg );
308-
moveUp->addEventHandler( new MyClickHandler );
323+
ImageControl* moveUp = new NavigationControl( moveUpImg );
324+
moveUp->addEventHandler( new PanControlHandler( manip, 0, 0.05 ) );
309325

310326
//Move Down
311327
osg::Image* moveDownImg = osgDB::readImageFile( imgDir + "/move-down.png" );
312-
ImageControl* moveDown = new ImageControl( moveDownImg );
313-
moveDown->addEventHandler( new MyClickHandler );
328+
ImageControl* moveDown = new NavigationControl( moveDownImg );
329+
moveDown->addEventHandler( new PanControlHandler( manip, 0, -0.05 ) );
314330

315331
//add controls to moveControls group
316332
moveHControls->addControl( moveLeft );
@@ -654,13 +670,31 @@ bool ControlsHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIAction
654670
bool
655671
NavigationControl::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, ControlContext& cx )
656672
{
657-
if ( ea.getEventType() == osgGA::GUIEventAdapter::PUSH )
673+
switch ( ea.getEventType() )
674+
{
675+
case osgGA::GUIEventAdapter::PUSH:
676+
_mouse_down_event = &ea;
677+
break;
678+
case osgGA::GUIEventAdapter::FRAME:
679+
if ( _mouse_down_event )
680+
{
681+
_mouse_down_event = &ea;
682+
}
683+
break;
684+
case osgGA::GUIEventAdapter::RELEASE:
685+
_mouse_down_event = NULL;
686+
break;
687+
}
688+
if ( _mouse_down_event )
689+
{
690+
//OE_NOTICE << "NavigationControl::handle getEventType " << ea.getEventType() << std::endl;
691+
for( ControlEventHandlerList::const_iterator i = _eventHandlers.begin(); i != _eventHandlers.end(); ++i )
658692
{
659-
OE_NOTICE << "Thank you for pushing " << std::endl;
660-
aa.requestContinuousUpdate(true);
693+
NavigationControlHandler* handler = dynamic_cast<NavigationControlHandler*>(i->get());
694+
if ( handler ) handler->onMouseDown( this, ea.getButtonMask() );
661695
}
662-
OE_NOTICE << "getEventType " << ea.getEventType() << std::endl;
663-
return Control::handle( ea, aa, cx );
696+
}
697+
return Control::handle( ea, aa, cx );
664698
}
665699

666700
// ----------

src/plugins/globe/globe_plugin.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,22 @@ class ControlsHandler : public osgGA::GUIEventHandler
126126

127127
namespace osgEarthUtil { namespace Controls2
128128
{
129+
class NavigationControlHandler : public ControlEventHandler
130+
{
131+
public:
132+
virtual void onMouseDown( class Control* control, int mouseButtonMask ) { }
133+
};
134+
129135
class NavigationControl : public ImageControl
130136
{
131137
public:
132-
NavigationControl( osg::Image* image =0L ) : ImageControl(image) {}
138+
NavigationControl( osg::Image* image = 0L ) : ImageControl( image ), _mouse_down_event( NULL ) {}
133139

134140
protected:
135141
virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, ControlContext& cx );
136142

143+
private:
144+
osg::ref_ptr<const osgGA::GUIEventAdapter> _mouse_down_event;
137145
};
138146
}
139147
}

0 commit comments

Comments
 (0)