[vtkusers] Re: Mouse Event Problem

Scott J. Pearson scottjp at CLEMSON.EDU
Mon May 16 11:14:48 EDT 2005


We use a vtkCommand::MouseMoveEvent to handle mouse movements. Thus, one can
do something along the lines of the following code.

int currentEvent_;
int lastX_, lastY_;

const int PANNING = 1;
const int NOTHING = 2;

void left_button_press(vtkObject *caller, unsigned long eid,
                       void *clientdata, void *calldata)
{
   currentEvent_ = PANNING;
   POINT pos;
   ::GetCursorPos(&pos);
   lastX_ = pos.x;
   lastY_ = pos.y;
}

void left_button_release(vtkObject *caller, unsigned long eid,
                         void *clientdata, void *calldata)
{
   currentEvent_ = NOTHING;
}

void mouse_move_event(vtkObject *caller, unsigned long eid,
                      void *clientdata, void *calldata)
{
   if (currentEvent_ == PANNING)
   {
      POINT pos;
      ::GetCursorPos(&pos);
      ...   // act on the new pos vis-à-vis lastX_ and lastY_
      lastX_ = pos.x;
      lastY_ = pos.y;
   }
}

void VtkControl::VtkControl()
{
   //...

   unsigned eventID1 = vtkCommand::LeftButtonPressEvent;
   vtkCallbackCommand *cb1 = vtkCallbackCommand::New();
   cb1->SetCallback(left_button_press);
   iren->AddObserver(eventID1, cb1);

   unsigned eventID2 = vtkCommand::LeftButtonReleaseEvent;
   vtkCallbackCommand *cb2 = vtkCallbackCommand::New();
   cb2->SetCallback(left_button_release);
   iren->AddObserver(eventID2, cb2);

   unsigned eventID3 = vtkCommand::MouseMoveEvent;
   vtkCallbackCommand *cb3 = vtkCallbackCommand::New();
   cb3->SetCallback(mouse_move_event);
   iren->AddObserver(eventID3, cb3);

   //...
}






More information about the vtkusers mailing list