@@ -113,6 +113,22 @@ struct MyClickHandler : public ControlEventHandler
113
113
}
114
114
};
115
115
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
+
116
132
void GlobePlugin::run ()
117
133
{
118
134
#ifdef QGISDEBUG
@@ -304,13 +320,13 @@ void GlobePlugin::setupControls()
304
320
305
321
// Move Up
306
322
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 ) );
309
325
310
326
// Move Down
311
327
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 ) );
314
330
315
331
// add controls to moveControls group
316
332
moveHControls->addControl ( moveLeft );
@@ -654,13 +670,31 @@ bool ControlsHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIAction
654
670
bool
655
671
NavigationControl::handle ( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, ControlContext& cx )
656
672
{
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 )
658
692
{
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 () );
661
695
}
662
- OE_NOTICE << " getEventType " << ea. getEventType () << std::endl;
663
- return Control::handle ( ea, aa, cx );
696
+ }
697
+ return Control::handle ( ea, aa, cx );
664
698
}
665
699
666
700
// ----------
0 commit comments