Re: problems with motion notify event



You definitively can use the events in Gtk::DrawingArea, since it is a Gtk::Widget. Here is a primitive way how:

In constructor: 
MyWidget::MyWidget{
  this->mbDragging = false;
  this->mbPressed = false;

  set_events(
             Gdk::BUTTON_PRESS_MASK // mouse button pressed
             | Gdk::BUTTON_RELEASE_MASK // mouse button released
             | Gdk::BUTTON1_MOTION_MASK // dragging left mouse button pressed
             );

  /* ... lots of code ... */
}

bool
MyWidget::on_button_press_event(GdkEventButton* event)
{
  switch ( event->button ) // which mouse button?
    {
    case 2:
      break;
    case 3:
      break;
    }

   mbPressed = true;

  /* ... remember position here. Could be drag start! ... */

  return true;
}




bool
MyWidget::on_button_release_event ( GdkEventButton* event )
{
  mbPressed  = false;
  switch ( event->button )
    {
    case 1:
      break;
    case 2:
      break;
    case 3:
      m_pPopup->popup ( 3, event->time ); // Contextmenu
      break;
    }

  mbDragging = false;
  return true;
}




/*
  this is where it reacts on mouse dragging:
*/
bool
MyWidget::on_motion_notify_event ( GdkEventMotion* event )
{
  if ( mbPressed )
    {
      mbDragging = true;
    }

  if ( ! mbDragging )
    {
      return true;
    }

  /* ... do something with event->x_root or event->x ... */
}


______________________________________________________________________
XXL-Speicher, PC-Virenschutz, Spartarife & mehr: Nur im WEB.DE Club!		
Jetzt gratis testen! http://freemail.web.de/home/landingpad/?mc=021130




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]