Logo Search packages:      
Sourcecode: inkscape version File versions

static int sp_knot_handler ( SPCanvasItem ,
GdkEvent *  event,
SPKnot knot 
) [static]

Called to handle events on knots.

Definition at line 285 of file knot.cpp.

References SPKnot::_click_signal, SPEventContext::_delayed_snap_event, SPEventContext::_snap_window_open, SPKnot::_ungrabbed_signal, Inkscape::MessageContext::clear(), SPEventContext::defaultMessageContext(), SPKnot::desktop, SPDesktop::event_context, Inkscape::MessageStack::flash(), Inkscape::Preferences::get(), get_group0_keyval(), Inkscape::Preferences::getIntLimited(), SPKnot::item, Inkscape::UI::View::View::messageStack(), SPKnot::pressure, Inkscape::MessageContext::set(), sp_canvas_item_ungrab(), sp_knot_set_flag(), sp_knot_start_dragging(), SPEventContext::space_panning, SPKnot::tip, and SPDesktop::w2d().

{
      static bool snap_delay_temporarily_active = false;

      g_assert(knot != NULL);
    g_assert(SP_IS_KNOT(knot));

    /* Run client universal event handler, if present */

    gboolean consumed = FALSE;

    g_signal_emit(knot, knot_signals[EVENT], 0, event, &consumed);

    if (consumed) {
        return TRUE;
    }

    g_object_ref(knot);
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);

    switch (event->type) {
      case GDK_2BUTTON_PRESS:
            if (event->button.button == 1) {
                g_signal_emit(knot, knot_signals[DOUBLECLICKED], 0, event->button.state);

                grabbed = FALSE;
                moved = FALSE;
                consumed = TRUE;
            }
            break;
      case GDK_BUTTON_PRESS:
            if (event->button.button == 1 && !knot->desktop->event_context->space_panning) {
                Geom::Point const p = knot->desktop->w2d(Geom::Point(event->button.x, event->button.y));
                sp_knot_start_dragging(knot, p, (gint) event->button.x, (gint) event->button.y, event->button.time);
                if (knot->desktop->event_context->_snap_window_open == false) {
                              sp_event_context_snap_window_open(knot->desktop->event_context);
                              snap_delay_temporarily_active = true;
                        }
                consumed = TRUE;
            }
            break;
      case GDK_BUTTON_RELEASE:
                  if (event->button.button == 1 && !knot->desktop->event_context->space_panning) {
                        // If we have any pending snap event, then invoke it now
                        if (knot->desktop->event_context->_delayed_snap_event) {
                              sp_event_context_snap_watchdog_callback(knot->desktop->event_context->_delayed_snap_event);
                        }

                        // now we can safely close the snapping window
                        if (snap_delay_temporarily_active) {
                  if (knot->desktop->event_context->_snap_window_open == true) {
                        sp_event_context_snap_window_closed(knot->desktop->event_context);
                  }
                              snap_delay_temporarily_active = false;
                        }

                  knot->pressure = 0;
                if (transform_escaped) {
                    transform_escaped = false;
                    consumed = TRUE;
                } else {
                    sp_knot_set_flag(knot, SP_KNOT_GRABBED, FALSE);
                    if (!nograb) {
                        sp_canvas_item_ungrab(knot->item, event->button.time);
                    }
                    if (moved) {
                        sp_knot_set_flag(knot,
                                         SP_KNOT_DRAGGING,
                                         FALSE);
                        g_signal_emit(knot,
                                      knot_signals[UNGRABBED], 0,
                                      event->button.state);
                        knot->_ungrabbed_signal.emit(knot);
                    } else {
                        g_signal_emit(knot,
                                      knot_signals[CLICKED], 0,
                                      event->button.state);
                        knot->_click_signal.emit(knot, event->button.state);
                    }
                    grabbed = FALSE;
                    moved = FALSE;
                    consumed = TRUE;
                }
            }
            break;
      case GDK_MOTION_NOTIFY:
            if (grabbed && !knot->desktop->event_context->space_panning) {
                consumed = TRUE;

                if ( within_tolerance
                     && ( abs( (gint) event->motion.x - xp ) < tolerance )
                     && ( abs( (gint) event->motion.y - yp ) < tolerance ) ) {
                    break; // do not drag if we're within tolerance from origin
                }

                // Once the user has moved farther than tolerance from the original location
                // (indicating they intend to move the object, not click), then always process the
                // motion notify coordinates as given (no snapping back to origin)
                within_tolerance = false;

                if (gdk_event_get_axis (event, GDK_AXIS_PRESSURE, &knot->pressure))
                    knot->pressure = CLAMP (knot->pressure, 0, 1);
                else
                    knot->pressure = 0.5;

                if (!moved) {
                    g_signal_emit(knot,
                                  knot_signals[GRABBED], 0,
                                  event->motion.state);
                    sp_knot_set_flag(knot,
                                     SP_KNOT_DRAGGING,
                                     TRUE);
                }
                sp_event_context_snap_delay_handler(knot->desktop->event_context, NULL, knot, (GdkEventMotion *)event, DelayedSnapEvent::KNOT_HANDLER);
                sp_knot_handler_request_position(event, knot);
                moved = TRUE;
            }
            break;
      case GDK_ENTER_NOTIFY:
            sp_knot_set_flag(knot, SP_KNOT_MOUSEOVER, TRUE);
            sp_knot_set_flag(knot, SP_KNOT_GRABBED, FALSE);

            if (knot->tip) {
                knot->desktop->event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, knot->tip);
            }

            grabbed = FALSE;
            moved = FALSE;
            consumed = TRUE;
            break;
      case GDK_LEAVE_NOTIFY:
            sp_knot_set_flag(knot, SP_KNOT_MOUSEOVER, FALSE);
            sp_knot_set_flag(knot, SP_KNOT_GRABBED, FALSE);

            if (knot->tip) {
                knot->desktop->event_context->defaultMessageContext()->clear();
            }

            grabbed = FALSE;
            moved = FALSE;
            consumed = TRUE;
            break;
      case GDK_KEY_PRESS: // keybindings for knot
            switch (get_group0_keyval(&event->key)) {
                        case GDK_Escape:
                                          sp_knot_set_flag(knot, SP_KNOT_GRABBED, FALSE);
                                          if (!nograb) {
                                                sp_canvas_item_ungrab(knot->item, event->button.time);
                                          }
                                          if (moved) {
                                                sp_knot_set_flag(knot,
                                                                         SP_KNOT_DRAGGING,
                                                                         FALSE);
                                                g_signal_emit(knot,
                                                                    knot_signals[UNGRABBED], 0,
                                                                    event->button.state);
                                                sp_document_undo(sp_desktop_document(knot->desktop));
                                                knot->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Node or handle drag canceled."));
                                                transform_escaped = true;
                                                consumed = TRUE;
                                          }
                                          grabbed = FALSE;
                                          moved = FALSE;
                                          if (snap_delay_temporarily_active) {
                                                sp_event_context_snap_window_closed(knot->desktop->event_context);
                                                snap_delay_temporarily_active = false;
                                          }
                                          break;
                        default:
                                          consumed = FALSE;
                                          break;
                              }
                              break;
      default:
            break;
    }

    g_object_unref(knot);

    return consumed;
}


Generated by  Doxygen 1.6.0   Back to index