static void sp_dropper_context_init(SPDropperContext *dc) { SPEventContext *event_context = SP_EVENT_CONTEXT(dc); event_context->cursor_shape = cursor_dropper_xpm; event_context->hot_x = 7; event_context->hot_y = 7; }
static void sp_box3d_context_dispose(GObject *object) { Box3DContext *bc = SP_BOX3D_CONTEXT(object); SPEventContext *ec = SP_EVENT_CONTEXT(object); ec->enableGrDrag(false); delete (bc->_vpdrag); bc->_vpdrag = NULL; bc->sel_changed_connection.disconnect(); bc->sel_changed_connection.~connection(); delete ec->shape_editor; ec->shape_editor = NULL; /* fixme: This is necessary because we do not grab */ if (bc->item) { sp_box3d_finish(bc); } if (bc->_message_context) { delete bc->_message_context; } G_OBJECT_CLASS(parent_class)->dispose(object); }
static void spdc_pen_finish_segment (SPPenContext *pc, NRPointF *p, guint state) { SPDrawContext *dc; dc = SP_DRAW_CONTEXT (pc); if (!sp_curve_empty (dc->red_curve)) { SPCurve *curve; SPCanvasItem *cshape; sp_curve_append_continuous (dc->green_curve, dc->red_curve, 0.0625); curve = sp_curve_copy (dc->red_curve); /* fixme: */ cshape = sp_canvas_bpath_new (SP_DT_SKETCH (SP_EVENT_CONTEXT (dc)->desktop), curve); sp_curve_unref (curve); sp_canvas_bpath_set_stroke (SP_CANVAS_BPATH (cshape), dc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); dc->green_bpaths = g_slist_prepend (dc->green_bpaths, cshape); dc->p[0] = dc->p[3]; dc->p[1] = dc->p[4]; dc->npoints = 2; sp_curve_reset (dc->red_curve); } }
static void sp_gradient_context_add_stop_near_point (SPGradientContext *rc, SPItem *item, Geom::Point mouse_p, guint32 /*etime*/) { // item is the selected item. mouse_p the location in doc coordinates of where to add the stop SPEventContext *ec = SP_EVENT_CONTEXT(rc); SPDesktop *desktop = SP_EVENT_CONTEXT (rc)->desktop; double tolerance = (double) ec->tolerance; ec->get_drag()->addStopNearPoint (item, mouse_p, tolerance/desktop->current_zoom()); sp_document_done (sp_desktop_document (desktop), SP_VERB_CONTEXT_GRADIENT, _("Add gradient stop")); ec->get_drag()->updateDraggers(); }
static bool sp_select_context_abort(SPEventContext *event_context) { SPDesktop *desktop = event_context->desktop; SPSelectContext *sc = SP_SELECT_CONTEXT(event_context); Inkscape::SelTrans *seltrans = sc->_seltrans; if (sc->dragging) { if (sc->moved) { // cancel dragging an object seltrans->ungrab(); sc->moved = FALSE; sc->dragging = FALSE; sp_event_context_discard_delayed_snap_event(event_context); drag_escaped = 1; if (sc->item) { // only undo if the item is still valid if (SP_OBJECT_DOCUMENT( SP_OBJECT(sc->item))) { sp_document_undo(sp_desktop_document(desktop)); } sp_object_unref( SP_OBJECT(sc->item), NULL); } else if (sc->button_press_ctrl) { // NOTE: This is a workaround to a bug. // When the ctrl key is held, sc->item is not defined // so in this case (only), we skip the object doc check sp_document_undo(sp_desktop_document(desktop)); } sc->item = NULL; SP_EVENT_CONTEXT(sc)->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Move canceled.")); return true; } } else { if (Inkscape::Rubberband::get(desktop)->is_started()) { Inkscape::Rubberband::get(desktop)->stop(); rb_escaped = 1; SP_EVENT_CONTEXT(sc)->defaultMessageContext()->clear(); SP_EVENT_CONTEXT(sc)->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Selection canceled.")); return true; } } return false; }
/** \brief Callback that processes the "changed" signal on the selection; destroys old and creates new knotholder */ void sp_spiral_context_selection_changed(Inkscape::Selection *selection, gpointer data) { SPSpiralContext *sc = SP_SPIRAL_CONTEXT(data); SPEventContext *ec = SP_EVENT_CONTEXT(sc); ec->shape_editor->unset_item(SH_KNOTHOLDER); SPItem *item = selection->singleItem(); ec->shape_editor->set_item(item, SH_KNOTHOLDER); }
static bool sp_gradient_context_is_over_line (SPGradientContext *rc, SPItem *item, Geom::Point event_p) { SPDesktop *desktop = SP_EVENT_CONTEXT (rc)->desktop; //Translate mouse point into proper coord system rc->mousepoint_doc = desktop->w2d(event_p); SPCtrlLine* line = SP_CTRLLINE(item); Geom::Point nearest = snap_vector_midpoint (rc->mousepoint_doc, line->s, line->e, 0); double dist_screen = Geom::L2 (rc->mousepoint_doc - nearest) * desktop->current_zoom(); double tolerance = (double) SP_EVENT_CONTEXT(rc)->tolerance; bool close = (dist_screen < tolerance); return close; }
static void sp_zoom_context_init (SPZoomContext * zoom_context) { SPEventContext * event_context; event_context = SP_EVENT_CONTEXT (zoom_context); event_context->cursor_shape = cursor_zoom_xpm; event_context->hot_x = 6; event_context->hot_y = 6; }
static gint pencil_handle_key_press(SPPencilContext *const pc, guint const keyval, guint const state) { gint ret = FALSE; switch (keyval) { case GDK_Up: case GDK_Down: case GDK_KP_Up: case GDK_KP_Down: // Prevent the zoom field from activation. if (!mod_ctrl_only(state)) { ret = TRUE; } break; case GDK_Escape: if (pc->npoints != 0) { // if drawing, cancel, otherwise pass it up for deselecting if (pc->state != SP_PENCIL_CONTEXT_IDLE) { pencil_cancel (pc); ret = TRUE; } } break; case GDK_z: case GDK_Z: if (mod_ctrl_only(state) && pc->npoints != 0) { // if drawing, cancel, otherwise pass it up for undo if (pc->state != SP_PENCIL_CONTEXT_IDLE) { pencil_cancel (pc); ret = TRUE; } } break; case GDK_g: case GDK_G: if (mod_shift_only(state)) { sp_selection_to_guides(SP_EVENT_CONTEXT(pc)->desktop); ret = true; } break; case GDK_Alt_L: case GDK_Alt_R: case GDK_Meta_L: case GDK_Meta_R: if (pc->state == SP_PENCIL_CONTEXT_IDLE) { pc->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("<b>Sketch mode</b>: holding <b>Alt</b> interpolates between sketched paths. Release <b>Alt</b> to finalize.")); } break; default: break; } return ret; }
/** \brief Callback that processes the "changed" signal on the selection; destroys old and creates new knotholder */ static void sp_box3d_context_selection_changed(Inkscape::Selection *selection, gpointer data) { Box3DContext *bc = SP_BOX3D_CONTEXT(data); SPEventContext *ec = SP_EVENT_CONTEXT(bc); ec->shape_editor->unset_item(SH_KNOTHOLDER); SPItem *item = selection->singleItem(); ec->shape_editor->set_item(item, SH_KNOTHOLDER); if (selection->perspList().size() == 1) { // selecting a single box changes the current perspective ec->desktop->doc()->setCurrentPersp3D(selection->perspList().front()); } }
static void sp_gradient_context_init(SPGradientContext *gr_context) { SPEventContext *event_context = SP_EVENT_CONTEXT(gr_context); gr_context->cursor_addnode = false; event_context->cursor_shape = cursor_gradient_xpm; event_context->hot_x = 4; event_context->hot_y = 4; event_context->xp = 0; event_context->yp = 0; event_context->tolerance = 6; event_context->within_tolerance = false; event_context->item_to_select = NULL; }
static void fit_and_split (SPDrawContext * dc) { NRPointF b[4]; gdouble tolerance; g_assert (dc->npoints > 1); tolerance = SP_EVENT_CONTEXT (dc)->desktop->w2d[0] * TOLERANCE; tolerance = tolerance * tolerance; if (sp_bezier_fit_cubic (b, dc->p, dc->npoints, tolerance) > 0 && dc->npoints < SP_DRAW_POINTS_MAX) { /* Fit and draw and reset state */ sp_curve_reset (dc->red_curve); sp_curve_moveto (dc->red_curve, b[0].x, b[0].y); sp_curve_curveto (dc->red_curve, b[1].x, b[1].y, b[2].x, b[2].y, b[3].x, b[3].y); sp_canvas_bpath_set_bpath (SP_CANVAS_BPATH (dc->red_bpath), dc->red_curve); } else { SPCurve *curve; SPCanvasItem *cshape; /* Fit and draw and copy last point */ g_assert (!sp_curve_empty (dc->red_curve)); sp_curve_append_continuous (dc->green_curve, dc->red_curve, 0.0625); curve = sp_curve_copy (dc->red_curve); /* fixme: */ cshape = sp_canvas_bpath_new (SP_DT_SKETCH (SP_EVENT_CONTEXT (dc)->desktop), curve); sp_curve_unref (curve); sp_canvas_bpath_set_stroke (SP_CANVAS_BPATH (cshape), dc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); dc->green_bpaths = g_slist_prepend (dc->green_bpaths, cshape); dc->p[0] = dc->p[dc->npoints - 2]; dc->p[1] = dc->p[dc->npoints - 1]; dc->npoints = 2; } }
static void sp_star_context_init (SPStarContext * star_context) { SPEventContext * event_context; event_context = SP_EVENT_CONTEXT (star_context); event_context->cursor_shape = cursor_star_xpm; event_context->hot_x = 4; event_context->hot_y = 4; star_context->item = NULL; star_context->magnitude = 5; star_context->proportion = 0.5; }
static void gradient_selection_changed (Inkscape::Selection *, gpointer data) { SPGradientContext *rc = (SPGradientContext *) data; GrDrag *drag = rc->_grdrag; Inkscape::Selection *selection = sp_desktop_selection(SP_EVENT_CONTEXT(rc)->desktop); guint n_obj = g_slist_length((GSList *) selection->itemList()); if (!drag->isNonEmpty() || selection->isEmpty()) return; guint n_tot = drag->numDraggers(); guint n_sel = drag->numSelected(); //The use of ngettext in the following code is intentional even if the English singular form would never be used if (n_sel == 1) { if (drag->singleSelectedDraggerNumDraggables() == 1) { gchar * message = g_strconcat( //TRANSLATORS: %s will be substituted with the point name (see previous messages); This is part of a compound message _("%s selected"), //TRANSLATORS: Mind the space in front. This is part of a compound message ngettext(" out of %d gradient handle"," out of %d gradient handles",n_tot), ngettext(" on %d selected object"," on %d selected objects",n_obj),NULL); rc->_message_context->setF(Inkscape::NORMAL_MESSAGE, message,_(gr_handle_descr[drag->singleSelectedDraggerSingleDraggableType()]), n_tot, n_obj); } else { gchar * message = g_strconcat( //TRANSLATORS: This is a part of a compound message (out of two more indicating: grandint handle count & object count) ngettext("One handle merging %d stop (drag with <b>Shift</b> to separate) selected", "One handle merging %d stops (drag with <b>Shift</b> to separate) selected",drag->singleSelectedDraggerNumDraggables()), ngettext(" out of %d gradient handle"," out of %d gradient handles",n_tot), ngettext(" on %d selected object"," on %d selected objects",n_obj),NULL); rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,message,drag->singleSelectedDraggerNumDraggables(), n_tot, n_obj); } } else if (n_sel > 1) { //TRANSLATORS: The plural refers to number of selected gradient handles. This is part of a compound message (part two indicates selected object count) gchar * message = g_strconcat(ngettext("<b>%d</b> gradient handle selected out of %d","<b>%d</b> gradient handles selected out of %d",n_sel), //TRANSLATORS: Mind the space in front. (Refers to gradient handles selected). This is part of a compound message ngettext(" on %d selected object"," on %d selected objects",n_obj),NULL); rc->_message_context->setF(Inkscape::NORMAL_MESSAGE,message, n_sel, n_tot, n_obj); } else if (n_sel == 0) { rc->_message_context->setF(Inkscape::NORMAL_MESSAGE, //TRANSLATORS: The plural refers to number of selected objects ngettext("<b>No</b> gradient handles selected out of %d on %d selected object", "<b>No</b> gradient handles selected out of %d on %d selected objects",n_obj), n_tot, n_obj); } }
/** * Callback to initialize SPPencilContext object. */ static void sp_pencil_context_init(SPPencilContext *pc) { SPEventContext *event_context = SP_EVENT_CONTEXT(pc); event_context->cursor_shape = cursor_pencil_xpm; event_context->hot_x = 4; event_context->hot_y = 4; pc->npoints = 0; pc->state = SP_PENCIL_CONTEXT_IDLE; pc->req_tangent = Geom::Point(0, 0); // since SPPencilContext is not properly constructed... pc->sketch_interpolation = Geom::Piecewise<Geom::D2<Geom::SBasis> >(); pc->sketch_n = 0; }
static void sp_gradient_context_dispose(GObject *object) { SPGradientContext *rc = SP_GRADIENT_CONTEXT(object); SPEventContext *ec = SP_EVENT_CONTEXT(object); ec->enableGrDrag(false); if (rc->_message_context) { delete rc->_message_context; } rc->selcon->disconnect(); delete rc->selcon; rc->subselcon->disconnect(); delete rc->subselcon; G_OBJECT_CLASS(parent_class)->dispose(object); }
static void sp_select_context_dispose(GObject *object) { SPSelectContext *sc = SP_SELECT_CONTEXT(object); SPEventContext * ec = SP_EVENT_CONTEXT (object); ec->enableGrDrag(false); if (sc->grabbed) { sp_canvas_item_ungrab(sc->grabbed, GDK_CURRENT_TIME); sc->grabbed = NULL; } delete sc->_seltrans; sc->_seltrans = NULL; delete sc->_describer; sc->_describer = NULL; G_OBJECT_CLASS(parent_class)->dispose(object); }
static void sp_star_finish (SPStarContext * sc) { if (sc->item != NULL) { SPDesktop *desktop; SPObject *object; desktop = SP_EVENT_CONTEXT (sc)->desktop; object = SP_OBJECT(sc->item); sp_shape_set_shape (SP_SHAPE (sc->item)); sp_object_invoke_write (object, NULL, SP_OBJECT_WRITE_EXT); sp_selection_set_item (SP_DT_SELECTION (desktop), sc->item); sp_document_done (SP_DT_DOCUMENT (desktop)); sc->item = NULL; } }
static void sp_box3d_context_init(Box3DContext *box3d_context) { SPEventContext *event_context = SP_EVENT_CONTEXT(box3d_context); event_context->cursor_shape = SP_3DBOX_CURSOR; event_context->xp = 0; event_context->yp = 0; event_context->tolerance = 0; event_context->within_tolerance = false; event_context->item_to_select = NULL; box3d_context->item = NULL; box3d_context->ctrl_dragged = false; box3d_context->extruded = false; box3d_context->_vpdrag = NULL; new (&box3d_context->sel_changed_connection) sigc::connection(); }
static void sp_spiral_finish(SPSpiralContext *sc) { sc->_message_context->clear(); if (sc->item != NULL) { SPDesktop *desktop = SP_EVENT_CONTEXT(sc)->desktop; SPSpiral *spiral = SP_SPIRAL(sc->item); sp_shape_set_shape(SP_SHAPE(spiral)); SP_OBJECT(spiral)->updateRepr(SP_OBJECT_WRITE_EXT); sp_canvas_end_forced_full_redraws(desktop->canvas); sp_desktop_selection(desktop)->set(sc->item); sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_SPIRAL, _("Create spiral")); sc->item = NULL; } }
static void sp_spiral_context_init(SPSpiralContext *spiral_context) { SPEventContext *event_context = SP_EVENT_CONTEXT(spiral_context); event_context->cursor_shape = cursor_spiral_xpm; event_context->hot_x = 4; event_context->hot_y = 4; event_context->xp = 0; event_context->yp = 0; event_context->tolerance = 0; event_context->within_tolerance = false; event_context->item_to_select = NULL; spiral_context->item = NULL; spiral_context->revo = 3.0; spiral_context->exp = 1.0; spiral_context->t0 = 0.0; new (&spiral_context->sel_changed_connection) sigc::connection(); }
static void sp_spiral_context_dispose(GObject *object) { SPSpiralContext *sc = SP_SPIRAL_CONTEXT(object); SPEventContext *ec = SP_EVENT_CONTEXT(object); ec->enableGrDrag(false); sc->sel_changed_connection.disconnect(); sc->sel_changed_connection.~connection(); delete ec->shape_editor; ec->shape_editor = NULL; /* fixme: This is necessary because we do not grab */ if (sc->item) sp_spiral_finish(sc); if (sc->_message_context) { delete sc->_message_context; } G_OBJECT_CLASS(parent_class)->dispose(object); }
static void sp_gradient_drag(SPGradientContext &rc, Geom::Point const pt, guint /*state*/, guint32 etime) { SPDesktop *desktop = SP_EVENT_CONTEXT(&rc)->desktop; Inkscape::Selection *selection = sp_desktop_selection(desktop); SPDocument *document = sp_desktop_document(desktop); SPEventContext *ec = SP_EVENT_CONTEXT(&rc); if (!selection->isEmpty()) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int type = prefs->getInt("/tools/gradient/newgradient", 1); int fill_or_stroke = prefs->getInt("/tools/gradient/newfillorstroke", 1); SPGradient *vector; if (ec->item_to_select) { // pick color from the object where drag started vector = sp_gradient_vector_for_object(document, desktop, ec->item_to_select, fill_or_stroke); } else { // Starting from empty space: // Sort items so that the topmost comes last GSList *items = g_slist_copy ((GSList *) selection->itemList()); items = g_slist_sort(items, (GCompareFunc) sp_item_repr_compare_position); // take topmost vector = sp_gradient_vector_for_object(document, desktop, SP_ITEM(g_slist_last(items)->data), fill_or_stroke); g_slist_free (items); } // HACK: reset fill-opacity - that 0.75 is annoying; BUT remove this when we have an opacity slider for all tabs SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_set_property(css, "fill-opacity", "1.0"); for (GSList const *i = selection->itemList(); i != NULL; i = i->next) { //FIXME: see above sp_repr_css_change_recursive(SP_OBJECT_REPR(i->data), css, "style"); sp_item_set_gradient(SP_ITEM(i->data), vector, (SPGradientType) type, fill_or_stroke); if (type == SP_GRADIENT_TYPE_LINEAR) { sp_item_gradient_set_coords (SP_ITEM(i->data), POINT_LG_BEGIN, 0, rc.origin, fill_or_stroke, true, false); sp_item_gradient_set_coords (SP_ITEM(i->data), POINT_LG_END, 0, pt, fill_or_stroke, true, false); } else if (type == SP_GRADIENT_TYPE_RADIAL) { sp_item_gradient_set_coords (SP_ITEM(i->data), POINT_RG_CENTER, 0, rc.origin, fill_or_stroke, true, false); sp_item_gradient_set_coords (SP_ITEM(i->data), POINT_RG_R1, 0, pt, fill_or_stroke, true, false); } SP_OBJECT (i->data)->requestModified(SP_OBJECT_MODIFIED_FLAG); } if (ec->_grdrag) { ec->_grdrag->updateDraggers(); // prevent regenerating draggers by selection modified signal, which sometimes // comes too late and thus destroys the knot which we will now grab: ec->_grdrag->local_change = true; // give the grab out-of-bounds values of xp/yp because we're already dragging // and therefore are already out of tolerance ec->_grdrag->grabKnot (SP_ITEM(selection->itemList()->data), type == SP_GRADIENT_TYPE_LINEAR? POINT_LG_END : POINT_RG_R1, -1, // ignore number (though it is always 1) fill_or_stroke, 99999, 99999, etime); } // We did an undoable action, but sp_document_done will be called by the knot when released // status text; we do not track coords because this branch is run once, not all the time // during drag int n_objects = g_slist_length((GSList *) selection->itemList()); rc._message_context->setF(Inkscape::NORMAL_MESSAGE, ngettext("<b>Gradient</b> for %d object; with <b>Ctrl</b> to snap angle", "<b>Gradient</b> for %d objects; with <b>Ctrl</b> to snap angle", n_objects), n_objects); } else { sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>objects</b> on which to create gradient.")); } }
static void sp_box3d_drag(Box3DContext &bc, guint /*state*/) { SPDesktop *desktop = SP_EVENT_CONTEXT(&bc)->desktop; if (!bc.item) { if (Inkscape::have_viable_layer(desktop, bc._message_context) == false) { return; } /* Create object */ Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_EVENT_CONTEXT_DOCUMENT(&bc)); Inkscape::XML::Node *repr = xml_doc->createElement("svg:g"); repr->setAttribute("sodipodi:type", "inkscape:box3d"); /* Set style */ sp_desktop_apply_style_tool (desktop, repr, "/tools/shapes/3dbox", false); bc.item = (SPItem *) desktop->currentLayer()->appendChildRepr(repr); Inkscape::GC::release(repr); Inkscape::XML::Node *repr_side; // TODO: Incorporate this in box3d-side.cpp! for (int i = 0; i < 6; ++i) { repr_side = xml_doc->createElement("svg:path"); repr_side->setAttribute("sodipodi:type", "inkscape:box3dside"); repr->addChild(repr_side, NULL); Box3DSide *side = SP_BOX3D_SIDE(inkscape_active_document()->getObjectByRepr (repr_side)); guint desc = Box3D::int_to_face(i); Box3D::Axis plane = (Box3D::Axis) (desc & 0x7); plane = (Box3D::is_plane(plane) ? plane : Box3D::orth_plane_or_axis(plane)); side->dir1 = Box3D::extract_first_axis_direction(plane); side->dir2 = Box3D::extract_second_axis_direction(plane); side->front_or_rear = (Box3D::FrontOrRear) (desc & 0x8); /* Set style */ box3d_side_apply_style(side); SP_OBJECT(side)->updateRepr(); // calls box3d_side_write() and updates, e.g., the axes string description } box3d_set_z_orders(SP_BOX3D(bc.item)); bc.item->updateRepr(); // TODO: It would be nice to show the VPs during dragging, but since there is no selection // at this point (only after finishing the box), we must do this "manually" /* bc._vpdrag->updateDraggers(); */ desktop->canvas->force_full_redraw_after_interruptions(5); } g_assert(bc.item); SPBox3D *box = SP_BOX3D(bc.item); box->orig_corner0 = bc.drag_origin_proj; box->orig_corner7 = bc.drag_ptC_proj; box3d_check_for_swapped_coords(box); /* we need to call this from here (instead of from box3d_position_set(), for example) because z-order setting must not interfere with display updates during undo/redo */ box3d_set_z_orders (box); box3d_position_set(box); // status text bc._message_context->setF(Inkscape::NORMAL_MESSAGE, "%s", _("<b>3D Box</b>; with <b>Shift</b> to extrude along the Z axis")); }
static gint pencil_handle_button_release(SPPencilContext *const pc, GdkEventButton const &revent) { gint ret = FALSE; SPEventContext *event_context = SP_EVENT_CONTEXT(pc); if ( revent.button == 1 && pc->is_drawing && !event_context->space_panning) { SPDesktop *const dt = pc->desktop; pc->is_drawing = false; /* Find desktop coordinates */ Geom::Point p = dt->w2d(Geom::Point(revent.x, revent.y)); /* Test whether we hit any anchor. */ SPDrawAnchor *anchor = spdc_test_inside(pc, Geom::Point(revent.x, revent.y)); switch (pc->state) { case SP_PENCIL_CONTEXT_IDLE: /* Releasing button in idle mode means single click */ /* We have already set up start point/anchor in button_press */ if (!(revent.state & GDK_CONTROL_MASK)) { // Ctrl+click creates a single point so only set context in ADDLINE mode when Ctrl isn't pressed pc->state = SP_PENCIL_CONTEXT_ADDLINE; } ret = TRUE; break; case SP_PENCIL_CONTEXT_ADDLINE: /* Finish segment now */ if (anchor) { p = anchor->dp; } else { spdc_endpoint_snap(pc, p, revent.state); } pc->ea = anchor; spdc_set_endpoint(pc, p); spdc_finish_endpoint(pc); pc->state = SP_PENCIL_CONTEXT_IDLE; ret = TRUE; break; case SP_PENCIL_CONTEXT_FREEHAND: if (revent.state & GDK_MOD1_MASK) { /* sketch mode: interpolate the sketched path and improve the current output path with the new interpolation. don't finish sketch */ sketch_interpolate(pc); if (pc->green_anchor) { pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor); } pc->state = SP_PENCIL_CONTEXT_SKETCH; } else { /* Finish segment now */ /// \todo fixme: Clean up what follows (Lauris) if (anchor) { p = anchor->dp; } pc->ea = anchor; /* Write curves to object */ dt->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing freehand")); interpolate(pc); spdc_concat_colors_and_flush(pc, FALSE); pc->sa = NULL; pc->ea = NULL; if (pc->green_anchor) { pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor); } pc->state = SP_PENCIL_CONTEXT_IDLE; // reset sketch mode too pc->sketch_n = 0; } ret = TRUE; break; case SP_PENCIL_CONTEXT_SKETCH: default: break; } if (pc->grab) { /* Release grab now */ sp_canvas_item_ungrab(pc->grab, revent.time); pc->grab = NULL; } ret = TRUE; } return ret; }
static void sp_zoom_context_init (SPZoomContext *zoom_context) { SPEventContext *event_context = SP_EVENT_CONTEXT(zoom_context); event_context->cursor_shape = SP_ZOOM_CURSOR; }
static void sp_star_drag (SPStarContext * sc, double x, double y, guint state) { SPStar *star; SPDesktop * desktop; NRPointF p0, p1; gdouble sides, dx, dy, r1, arg1; GString * xs, * ys; gchar status[80]; NRPointF fp; desktop = SP_EVENT_CONTEXT (sc)->desktop; if (!sc->item) { SPRepr * repr, * style; SPCSSAttr * css; /* Create object */ repr = sp_repr_new ("polygon"); sp_repr_set_attr (repr, "sodipodi:type", "star"); /* Set style */ style = inkscape_get_repr (INKSCAPE, "tools.shapes.star"); if (style) { css = sp_repr_css_attr_inherited (style, "style"); sp_repr_css_set (repr, css, "style"); sp_repr_css_attr_unref (css); } sc->item = (SPItem *) sp_document_add_repr (SP_DT_DOCUMENT (desktop), repr); sp_repr_unref (repr); } /* This is bit ugly, but so we are */ /* if (state & GDK_CONTROL_MASK) { */ /* } else if (state & GDK_SHIFT_MASK) { */ /* Free movement for corner point */ sp_desktop_dt2root_xy_point (desktop, &fp, sc->center.x, sc->center.y); p0.x = fp.x; p0.y = fp.y; sp_desktop_dt2root_xy_point (desktop, &fp, x, y); p1.x = fp.x; p1.y = fp.y; sp_desktop_free_snap (desktop, &p1); star = SP_STAR(sc->item); sides = (gdouble) sc->magnitude; dx = p1.x - p0.x; dy = p1.y - p0.y; r1 = hypot (dx, dy); arg1 = atan2 (dy, dx); #if 0 sp_star_set (star, sc->magnitude, p0.x, p0.y, r1, r1 * (sides-2.0)/sides, arg1, arg1 + M_PI/sides); #else sp_star_position_set (star, sc->magnitude, p0.x, p0.y, r1, r1 * sc->proportion, arg1, arg1 + M_PI / sides); #endif /* status text */ xs = SP_PT_TO_METRIC_STRING (fabs(p0.x), SP_DEFAULT_METRIC); ys = SP_PT_TO_METRIC_STRING (fabs(p0.y), SP_DEFAULT_METRIC); sprintf (status, "Draw star at (%s,%s)", xs->str, ys->str); sp_view_set_status (SP_VIEW (desktop), status, FALSE); g_string_free (xs, FALSE); g_string_free (ys, FALSE); }
static gint pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mevent) { if ((mevent.state & GDK_CONTROL_MASK) && (mevent.state & GDK_BUTTON1_MASK)) { // mouse was accidentally moved during Ctrl+click; // ignore the motion and create a single point pc->is_drawing = false; return TRUE; } gint ret = FALSE; SPDesktop *const dt = pc->desktop; SPEventContext *event_context = SP_EVENT_CONTEXT(pc); if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { // allow scrolling return FALSE; } if ( ( mevent.state & GDK_BUTTON1_MASK ) && !pc->grab && pc->is_drawing) { /* Grab mouse, so release will not pass unnoticed */ pc->grab = SP_CANVAS_ITEM(dt->acetate); sp_canvas_item_grab(pc->grab, ( GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK ), NULL, mevent.time); } /* Find desktop coordinates */ Geom::Point p = dt->w2d(Geom::Point(mevent.x, mevent.y)); /* Test whether we hit any anchor. */ SPDrawAnchor *anchor = spdc_test_inside(pc, Geom::Point(mevent.x, mevent.y)); if (pencil_within_tolerance) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gint const tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); if ( Geom::LInfty( Geom::Point(mevent.x,mevent.y) - pencil_drag_origin_w ) < tolerance ) { return FALSE; // 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) pencil_within_tolerance = false; switch (pc->state) { case SP_PENCIL_CONTEXT_ADDLINE: /* Set red endpoint */ if (anchor) { p = anchor->dp; } else { Geom::Point ptnr(p); spdc_endpoint_snap(pc, ptnr, mevent.state); p = ptnr; } spdc_set_endpoint(pc, p); ret = TRUE; break; default: /* We may be idle or already freehand */ if ( mevent.state & GDK_BUTTON1_MASK && pc->is_drawing ) { pc->state = SP_PENCIL_CONTEXT_FREEHAND; if ( !pc->sa && !pc->green_anchor ) { /* Create green anchor */ pc->green_anchor = sp_draw_anchor_new(pc, pc->green_curve, TRUE, pc->p[0]); } /** \todo * fixme: I am not sure whether we want to snap to anchors * in middle of freehand (Lauris) */ SnapManager &m = dt->namedview->snap_manager; if (anchor) { p = anchor->dp; } else if ((mevent.state & GDK_SHIFT_MASK) == 0) { m.setup(dt); Inkscape::SnappedPoint const s = m.freeSnap(Inkscape::SnapPreferences::SNAPPOINT_NODE, p); if (s.getSnapped()) { s.getPoint(p); pc->prev_snap_was_succesful = true; } else { pc->prev_snap_was_succesful = false; } } if ( pc->npoints != 0) { // buttonpress may have happened before we entered draw context! if (!(pc->prev_snap_was_succesful && m.snapprefs.getSnapPostponedGlobally())) { // When snapping is enabled but temporarily on hold because the mouse is moving // fast, then we don't want to add nodes off-grid spdc_add_freehand_point(pc, p, mevent.state); ret = TRUE; } } if (anchor && !pc->anchor_statusbar) { pc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Release</b> here to close and finish the path.")); pc->anchor_statusbar = true; } else if (!anchor && pc->anchor_statusbar) { pc->_message_context->clear(); pc->anchor_statusbar = false; } else if (!anchor) { pc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("Drawing a freehand path")); } } else { if (anchor && !pc->anchor_statusbar) { pc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to continue the path from this point.")); pc->anchor_statusbar = true; } else if (!anchor && pc->anchor_statusbar) { pc->_message_context->clear(); pc->anchor_statusbar = false; } } break; } return ret; }
static gint sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event) { SPItem *item = NULL; SPItem *item_at_point = NULL, *group_at_point = NULL, *item_in_group = NULL; gint ret = FALSE; SPDesktop *desktop = event_context->desktop; SPSelectContext *sc = SP_SELECT_CONTEXT(event_context); Inkscape::SelTrans *seltrans = sc->_seltrans; Inkscape::Selection *selection = sp_desktop_selection(desktop); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); // make sure we still have valid objects to move around if (sc->item && SP_OBJECT_DOCUMENT( SP_OBJECT(sc->item))==NULL) { sp_select_context_abort(event_context); } switch (event->type) { case GDK_2BUTTON_PRESS: if (event->button.button == 1) { if (!selection->isEmpty()) { SPItem *clicked_item = (SPItem *) selection->itemList()->data; if (SP_IS_GROUP(clicked_item) && !SP_IS_BOX3D(clicked_item)) { // enter group if it's not a 3D box desktop->setCurrentLayer(reinterpret_cast<SPObject *>(clicked_item)); sp_desktop_selection(desktop)->clear(); sc->dragging = false; sp_event_context_discard_delayed_snap_event(event_context); desktop->canvas->end_forced_full_redraws(); } else { // switch tool Geom::Point const button_pt(event->button.x, event->button.y); Geom::Point const p(desktop->w2d(button_pt)); tools_switch_by_item (desktop, clicked_item, p); } } else { sp_select_context_up_one_layer(desktop); } ret = TRUE; } break; case GDK_BUTTON_PRESS: if (event->button.button == 1 && !event_context->space_panning) { // save drag origin xp = (gint) event->button.x; yp = (gint) event->button.y; within_tolerance = true; Geom::Point const button_pt(event->button.x, event->button.y); Geom::Point const p(desktop->w2d(button_pt)); if (event->button.state & GDK_MOD1_MASK) Inkscape::Rubberband::get(desktop)->setMode(RUBBERBAND_MODE_TOUCHPATH); Inkscape::Rubberband::get(desktop)->start(desktop, p); if (sc->grabbed) { sp_canvas_item_ungrab(sc->grabbed, event->button.time); sc->grabbed = NULL; } sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK, NULL, event->button.time); sc->grabbed = SP_CANVAS_ITEM(desktop->acetate); // remember what modifiers were on before button press sc->button_press_shift = (event->button.state & GDK_SHIFT_MASK) ? true : false; sc->button_press_ctrl = (event->button.state & GDK_CONTROL_MASK) ? true : false; sc->button_press_alt = (event->button.state & GDK_MOD1_MASK) ? true : false; sc->moved = FALSE; rb_escaped = drag_escaped = 0; ret = TRUE; } else if (event->button.button == 3) { // right click; do not eat it so that right-click menu can appear, but cancel dragging & rubberband sp_select_context_abort(event_context); } break; case GDK_MOTION_NOTIFY: tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); if (event->motion.state & GDK_BUTTON1_MASK && !event_context->space_panning) { Geom::Point const motion_pt(event->motion.x, event->motion.y); Geom::Point const p(desktop->w2d(motion_pt)); 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 (sc->button_press_ctrl || (sc->button_press_alt && !sc->button_press_shift && !selection->isEmpty())) { // if it's not click and ctrl or alt was pressed (the latter with some selection // but not with shift) we want to drag rather than rubberband sc->dragging = TRUE; desktop->setCursor(SP_SELECT_D_CURSOR); desktop->canvas->force_full_redraw_after_interruptions(5); } if (sc->dragging) { /* User has dragged fast, so we get events on root (lauris)*/ // not only that; we will end up here when ctrl-dragging as well // and also when we started within tolerance, but trespassed tolerance outside of item Inkscape::Rubberband::get(desktop)->stop(); SP_EVENT_CONTEXT(sc)->defaultMessageContext()->clear(); item_at_point = desktop->item_at_point(Geom::Point(event->button.x, event->button.y), FALSE); if (!item_at_point) // if no item at this point, try at the click point (bug 1012200) item_at_point = desktop->item_at_point(Geom::Point(xp, yp), FALSE); if (item_at_point || sc->moved || sc->button_press_alt) { // drag only if starting from an item, or if something is already grabbed, or if alt-dragging if (!sc->moved) { item_in_group = desktop->item_at_point(Geom::Point(event->button.x, event->button.y), TRUE); group_at_point = desktop->group_at_point(Geom::Point(event->button.x, event->button.y)); if (SP_IS_LAYER(selection->single())) group_at_point = SP_GROUP(selection->single()); // group-at-point is meant to be topmost item if it's a group, // not topmost group of all items at point if (group_at_point != item_in_group && !(group_at_point && item_at_point && group_at_point->isAncestorOf(item_at_point))) group_at_point = NULL; // if neither a group nor an item (possibly in a group) at point are selected, set selection to the item at point if ((!item_in_group || !selection->includes(item_in_group)) && (!group_at_point || !selection->includes(group_at_point)) && !sc->button_press_alt) { // select what is under cursor if (!seltrans->isEmpty()) { seltrans->resetState(); } // when simply ctrl-dragging, we don't want to go into groups if (item_at_point && !selection->includes(item_at_point)) selection->set(item_at_point); } // otherwise, do not change selection so that dragging selected-within-group items, as well as alt-dragging, is possible seltrans->grab(p, -1, -1, FALSE, TRUE); sc->moved = TRUE; } if (!seltrans->isEmpty()) seltrans->moveTo(p, event->button.state); desktop->scroll_to_point(p); gobble_motion_events(GDK_BUTTON1_MASK); ret = TRUE; } else { sc->dragging = FALSE; sp_event_context_discard_delayed_snap_event(event_context); desktop->canvas->end_forced_full_redraws(); } } else { if (Inkscape::Rubberband::get(desktop)->is_started()) { Inkscape::Rubberband::get(desktop)->move(p); if (Inkscape::Rubberband::get(desktop)->getMode() == RUBBERBAND_MODE_TOUCHPATH) { event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Draw over</b> objects to select them; release <b>Alt</b> to switch to rubberband selection")); } else { event_context->defaultMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag around</b> objects to select them; press <b>Alt</b> to switch to touch selection")); } gobble_motion_events(GDK_BUTTON1_MASK); } } } break; case GDK_BUTTON_RELEASE: xp = yp = 0; if ((event->button.button == 1) && (sc->grabbed) && !event_context->space_panning) { if (sc->dragging) { if (sc->moved) { // item has been moved seltrans->ungrab(); sc->moved = FALSE; } else if (sc->item && !drag_escaped) { // item has not been moved -> simply a click, do selecting if (!selection->isEmpty()) { if (event->button.state & GDK_SHIFT_MASK) { // with shift, toggle selection seltrans->resetState(); selection->toggle(sc->item); } else { SPObject* single = selection->single(); // without shift, increase state (i.e. toggle scale/rotation handles) if (selection->includes(sc->item)) { seltrans->increaseState(); } else if (SP_IS_LAYER(single) && single->isAncestorOf(sc->item)) { seltrans->increaseState(); } else { seltrans->resetState(); selection->set(sc->item); } } } else { // simple or shift click, no previous selection seltrans->resetState(); selection->set(sc->item); } } sc->dragging = FALSE; desktop->setCursor(SP_SELECT_CURSOR); sp_event_context_discard_delayed_snap_event(event_context); desktop->canvas->end_forced_full_redraws(); if (sc->item) { sp_object_unref( SP_OBJECT(sc->item), NULL); } sc->item = NULL; } else { Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); if (r->is_started() && !within_tolerance) { // this was a rubberband drag GSList *items = NULL; if (r->getMode() == RUBBERBAND_MODE_RECT) { Geom::OptRect const b = r->getRectangle(); items = sp_document_items_in_box(sp_desktop_document(desktop), desktop->dkey, *b); } else if (r->getMode() == RUBBERBAND_MODE_TOUCHPATH) { items = sp_document_items_at_points(sp_desktop_document(desktop), desktop->dkey, r->getPoints()); } seltrans->resetState(); r->stop(); SP_EVENT_CONTEXT(sc)->defaultMessageContext()->clear(); if (event->button.state & GDK_SHIFT_MASK) { // with shift, add to selection selection->addList (items); } else { // without shift, simply select anew selection->setList (items); } g_slist_free (items); } else { // it was just a click, or a too small rubberband r->stop(); if (sc->button_press_shift && !rb_escaped && !drag_escaped) { // this was a shift+click or alt+shift+click, select what was clicked upon sc->button_press_shift = false; if (sc->button_press_ctrl) { // go into groups, honoring Alt item = sp_event_context_find_item (desktop, Geom::Point(event->button.x, event->button.y), event->button.state & GDK_MOD1_MASK, TRUE); sc->button_press_ctrl = FALSE; } else { // don't go into groups, honoring Alt item = sp_event_context_find_item (desktop, Geom::Point(event->button.x, event->button.y), event->button.state & GDK_MOD1_MASK, FALSE); } if (item) { selection->toggle(item); item = NULL; } } else if ((sc->button_press_ctrl || sc->button_press_alt) && !rb_escaped && !drag_escaped) { // ctrl+click, alt+click item = sp_event_context_find_item (desktop, Geom::Point(event->button.x, event->button.y), sc->button_press_alt, sc->button_press_ctrl); sc->button_press_ctrl = FALSE; sc->button_press_alt = FALSE; if (item) { if (selection->includes(item)) { seltrans->increaseState(); } else { seltrans->resetState(); selection->set(item); } item = NULL; } } else { // click without shift, simply deselect, unless with Alt or something was cancelled if (!selection->isEmpty()) { if (!(rb_escaped) && !(drag_escaped) && !(event->button.state & GDK_MOD1_MASK)) selection->clear(); rb_escaped = 0; ret = TRUE; } } } ret = TRUE; } if (sc->grabbed) { sp_canvas_item_ungrab(sc->grabbed, event->button.time); sc->grabbed = NULL; } desktop->updateNow(); } if (event->button.button == 1) { Inkscape::Rubberband::get(desktop)->stop(); // might have been started in another tool! } sc->button_press_shift = false; sc->button_press_ctrl = false; sc->button_press_alt = false; break; case GDK_KEY_PRESS: // keybindings for select context { { guint keyval = get_group0_keyval(&event->key); bool alt = ( MOD__ALT || (keyval == GDK_Alt_L) || (keyval == GDK_Alt_R) || (keyval == GDK_Meta_L) || (keyval == GDK_Meta_R)); if (!key_is_a_modifier (keyval)) { event_context->defaultMessageContext()->clear(); } else if (sc->grabbed || seltrans->isGrabbed()) { if (Inkscape::Rubberband::get(desktop)->is_started()) { // if Alt then change cursor to moving cursor: if (alt) { Inkscape::Rubberband::get(desktop)->setMode(RUBBERBAND_MODE_TOUCHPATH); } } else { // do not change the statusbar text when mousekey is down to move or transform the object, // because the statusbar text is already updated somewhere else. break; } } else { sp_event_show_modifier_tip (event_context->defaultMessageContext(), event, _("<b>Ctrl</b>: click to select in groups; drag to move hor/vert"), _("<b>Shift</b>: click to toggle select; drag for rubberband selection"), _("<b>Alt</b>: click to select under; drag to move selected or select by touch")); // if Alt and nonempty selection, show moving cursor ("move selected"): if (alt && !selection->isEmpty() && !desktop->isWaitingCursor()) { desktop->setCursor(SP_SELECT_D_CURSOR); } //*/ break; } } gdouble const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000); // in px gdouble const offset = prefs->getDoubleLimited("/options/defaultscale/value", 2, 0, 1000); int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12); switch (get_group0_keyval (&event->key)) { case GDK_Left: // move selection left case GDK_KP_Left: case GDK_KP_4: if (!MOD__CTRL) { // not ctrl gint mul = 1 + gobble_key_events( get_group0_keyval(&event->key), 0); // with any mask if (MOD__ALT) { // alt if (MOD__SHIFT) sp_selection_move_screen(desktop, mul*-10, 0); // shift else sp_selection_move_screen(desktop, mul*-1, 0); // no shift } else { // no alt if (MOD__SHIFT) sp_selection_move(desktop, mul*-10*nudge, 0); // shift else sp_selection_move(desktop, mul*-nudge, 0); // no shift } ret = TRUE; } break; case GDK_Up: // move selection up case GDK_KP_Up: case GDK_KP_8: if (!MOD__CTRL) { // not ctrl gint mul = 1 + gobble_key_events( get_group0_keyval(&event->key), 0); // with any mask if (MOD__ALT) { // alt if (MOD__SHIFT) sp_selection_move_screen(desktop, 0, mul*10); // shift else sp_selection_move_screen(desktop, 0, mul*1); // no shift } else { // no alt if (MOD__SHIFT) sp_selection_move(desktop, 0, mul*10*nudge); // shift else sp_selection_move(desktop, 0, mul*nudge); // no shift } ret = TRUE; } break; case GDK_Right: // move selection right case GDK_KP_Right: case GDK_KP_6: if (!MOD__CTRL) { // not ctrl gint mul = 1 + gobble_key_events( get_group0_keyval(&event->key), 0); // with any mask if (MOD__ALT) { // alt if (MOD__SHIFT) sp_selection_move_screen(desktop, mul*10, 0); // shift else sp_selection_move_screen(desktop, mul*1, 0); // no shift } else { // no alt if (MOD__SHIFT) sp_selection_move(desktop, mul*10*nudge, 0); // shift else sp_selection_move(desktop, mul*nudge, 0); // no shift } ret = TRUE; } break; case GDK_Down: // move selection down case GDK_KP_Down: case GDK_KP_2: if (!MOD__CTRL) { // not ctrl gint mul = 1 + gobble_key_events( get_group0_keyval(&event->key), 0); // with any mask if (MOD__ALT) { // alt if (MOD__SHIFT) sp_selection_move_screen(desktop, 0, mul*-10); // shift else sp_selection_move_screen(desktop, 0, mul*-1); // no shift } else { // no alt if (MOD__SHIFT) sp_selection_move(desktop, 0, mul*-10*nudge); // shift else sp_selection_move(desktop, 0, mul*-nudge); // no shift } ret = TRUE; } break; case GDK_Escape: if (!sp_select_context_abort(event_context)) selection->clear(); ret = TRUE; break; case GDK_a: case GDK_A: if (MOD__CTRL_ONLY) { sp_edit_select_all(desktop); ret = TRUE; } break; case GDK_space: /* stamping mode: show outline mode moving */ /* FIXME: Is next condition ok? (lauris) */ if (sc->dragging && sc->grabbed) { seltrans->stamp(); ret = TRUE; } break; case GDK_x: case GDK_X: if (MOD__ALT_ONLY) { desktop->setToolboxFocusTo ("altx"); ret = TRUE; } break; case GDK_bracketleft: if (MOD__ALT) { gint mul = 1 + gobble_key_events( get_group0_keyval(&event->key), 0); // with any mask sp_selection_rotate_screen(selection, mul*1); } else if (MOD__CTRL) { sp_selection_rotate(selection, 90); } else if (snaps) { sp_selection_rotate(selection, 180.0/snaps); } ret = TRUE; break; case GDK_bracketright: if (MOD__ALT) { gint mul = 1 + gobble_key_events( get_group0_keyval(&event->key), 0); // with any mask sp_selection_rotate_screen(selection, -1*mul); } else if (MOD__CTRL) { sp_selection_rotate(selection, -90); } else if (snaps) { sp_selection_rotate(selection, -180.0/snaps); } ret = TRUE; break; case GDK_less: case GDK_comma: if (MOD__ALT) { gint mul = 1 + gobble_key_events( get_group0_keyval(&event->key), 0); // with any mask sp_selection_scale_screen(selection, -2*mul); } else if (MOD__CTRL) { sp_selection_scale_times(selection, 0.5); } else { gint mul = 1 + gobble_key_events( get_group0_keyval(&event->key), 0); // with any mask sp_selection_scale(selection, -offset*mul); } ret = TRUE; break; case GDK_greater: case GDK_period: if (MOD__ALT) { gint mul = 1 + gobble_key_events( get_group0_keyval(&event->key), 0); // with any mask sp_selection_scale_screen(selection, 2*mul); } else if (MOD__CTRL) { sp_selection_scale_times(selection, 2); } else { gint mul = 1 + gobble_key_events( get_group0_keyval(&event->key), 0); // with any mask sp_selection_scale(selection, offset*mul); } ret = TRUE; break; case GDK_Return: if (MOD__CTRL_ONLY) { if (selection->singleItem()) { SPItem *clicked_item = selection->singleItem(); if ( SP_IS_GROUP(clicked_item) || SP_IS_BOX3D(clicked_item)) { // enter group or a 3D box desktop->setCurrentLayer(reinterpret_cast<SPObject *>(clicked_item)); sp_desktop_selection(desktop)->clear(); } else { SP_EVENT_CONTEXT(sc)->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Selected object is not a group. Cannot enter.")); } } ret = TRUE; } break; case GDK_BackSpace: if (MOD__CTRL_ONLY) { sp_select_context_up_one_layer(desktop); ret = TRUE; } break; case GDK_s: case GDK_S: if (MOD__SHIFT_ONLY) { if (!selection->isEmpty()) { seltrans->increaseState(); } ret = TRUE; } break; case GDK_g: case GDK_G: if (MOD__SHIFT_ONLY) { sp_selection_to_guides(desktop); ret = true; } break; default: break; } break; } case GDK_KEY_RELEASE: { guint keyval = get_group0_keyval(&event->key); if (key_is_a_modifier (keyval)) event_context->defaultMessageContext()->clear(); bool alt = ( MOD__ALT || (keyval == GDK_Alt_L) || (keyval == GDK_Alt_R) || (keyval == GDK_Meta_L) || (keyval == GDK_Meta_R)); if (Inkscape::Rubberband::get(desktop)->is_started()) { // if Alt then change cursor to moving cursor: if (alt) { Inkscape::Rubberband::get(desktop)->setMode(RUBBERBAND_MODE_RECT); } } } // set cursor to default. if (!desktop->isWaitingCursor()) { desktop->setCursor(event_context->cursor_shape); } break; default: break; } if (!ret) { if (((SPEventContextClass *) parent_class)->root_handler) ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event); } return ret; }
static gint pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &bevent) { gint ret = FALSE; SPEventContext *event_context = SP_EVENT_CONTEXT(pc); if ( bevent.button == 1 && !event_context->space_panning) { SPDrawContext *dc = SP_DRAW_CONTEXT (pc); SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(dc); Inkscape::Selection *selection = sp_desktop_selection(desktop); if (Inkscape::have_viable_layer(desktop, dc->_message_context) == false) { return TRUE; } Geom::Point const button_w(bevent.x, bevent.y); /* Find desktop coordinates */ Geom::Point p = pc->desktop->w2d(button_w); /* Test whether we hit any anchor. */ SPDrawAnchor *anchor = spdc_test_inside(pc, button_w); pencil_drag_origin_w = Geom::Point(bevent.x,bevent.y); pencil_within_tolerance = true; switch (pc->state) { case SP_PENCIL_CONTEXT_ADDLINE: /* Current segment will be finished with release */ ret = TRUE; break; default: /* Set first point of sequence */ if (bevent.state & GDK_CONTROL_MASK) { spdc_create_single_dot(event_context, p, "/tools/freehand/pencil", bevent.state); ret = true; break; } if (anchor) { p = anchor->dp; desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Continuing selected path")); } else { if (!(bevent.state & GDK_SHIFT_MASK)) { // This is the first click of a new curve; deselect item so that // this curve is not combined with it (unless it is drawn from its // anchor, which is handled by the sibling branch above) selection->clear(); desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new path")); SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); Inkscape::SnappedPoint const s = m.freeSnap(Inkscape::SnapPreferences::SNAPPOINT_NODE, p); if (s.getSnapped()) { s.getPoint(p); pc->prev_snap_was_succesful = true; } else { pc->prev_snap_was_succesful = false; } } else if (selection->singleItem() && SP_IS_PATH(selection->singleItem())) { desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Appending to selected path")); } } pc->sa = anchor; spdc_set_startpoint(pc, p); ret = TRUE; break; } pc->is_drawing = true; } return ret; }