static void sp_dropper_context_setup(SPEventContext *ec) { SPDropperContext *dc = SP_DROPPER_CONTEXT(ec); if (((SPEventContextClass *) parent_class)->setup) { ((SPEventContextClass *) parent_class)->setup(ec); } /* TODO: have a look at sp_dyna_draw_context_setup where the same is done.. generalize? at least make it an arcto! */ SPCurve *c = new SPCurve(); const double C1 = 0.552; c->moveto(-1,0); c->curveto(-1, C1, -C1, 1, 0, 1 ); c->curveto(C1, 1, 1, C1, 1, 0 ); c->curveto(1, -C1, C1, -1, 0, -1 ); c->curveto(-C1, -1, -1, -C1, -1, 0 ); c->closepath(); dc->area = sp_canvas_bpath_new(sp_desktop_controls(ec->desktop), c); c->unref(); sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(dc->area), 0x00000000,(SPWindRule)0); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(dc->area), 0x0000007f, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); sp_canvas_item_hide(dc->area); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/dropper/selcue")) { ec->enableSelectionCue(); } if (prefs->getBool("/tools/dropper/gradientdrag")) { ec->enableGrDrag(); } }
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 fit_and_split(SPPencilContext *pc) { g_assert( pc->npoints > 1 ); double const tolerance_sq = 0; Geom::Point b[4]; g_assert(is_zero(pc->req_tangent) || is_unit_vector(pc->req_tangent)); Geom::Point const tHatEnd(0, 0); int const n_segs = Geom::bezier_fit_cubic_full(b, NULL, pc->p, pc->npoints, pc->req_tangent, tHatEnd, tolerance_sq, 1); if ( n_segs > 0 && unsigned(pc->npoints) < G_N_ELEMENTS(pc->p) ) { /* Fit and draw and reset state */ pc->red_curve->reset(); pc->red_curve->moveto(b[0]); pc->red_curve->curveto(b[1], b[2], b[3]); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve); pc->red_curve_is_valid = true; } else { /* Fit and draw and copy last point */ g_assert(!pc->red_curve->is_empty()); /* Set up direction of next curve. */ { Geom::CubicBezier const * last_seg = dynamic_cast<Geom::CubicBezier const *>(pc->red_curve->last_segment()); g_assert( last_seg ); // Relevance: validity of (*last_seg)[2] pc->p[0] = last_seg->finalPoint(); pc->npoints = 1; Geom::Point const req_vec( pc->p[0] - (*last_seg)[2] ); pc->req_tangent = ( ( Geom::is_zero(req_vec) || !in_svg_plane(req_vec) ) ? Geom::Point(0, 0) : Geom::unit_vector(req_vec) ); } pc->green_curve->append_continuous(pc->red_curve, 0.0625); SPCurve *curve = pc->red_curve->copy(); /// \todo fixme: SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(pc->desktop), curve); curve->unref(); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); pc->green_bpaths = g_slist_prepend(pc->green_bpaths, cshape); pc->red_curve_is_valid = false; } }
static void sp_draw_context_setup (SPEventContext *ec) { SPDrawContext *dc; SPDesktop *dt; dc = SP_DRAW_CONTEXT (ec); dt = ec->desktop; if (((SPEventContextClass *) draw_parent_class)->setup) ((SPEventContextClass *) draw_parent_class)->setup (ec); dc->selection = SP_DT_SELECTION (dt); /* Connect signals to track selection changes */ g_signal_connect (G_OBJECT (dc->selection), "changed", G_CALLBACK (spdc_selection_changed), dc); g_signal_connect (G_OBJECT (dc->selection), "modified", G_CALLBACK (spdc_selection_modified), dc); /* Create red bpath */ dc->red_bpath = sp_canvas_bpath_new (SP_DT_SKETCH (ec->desktop), NULL); sp_canvas_bpath_set_stroke (SP_CANVAS_BPATH (dc->red_bpath), dc->red_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); /* Create red curve */ dc->red_curve = sp_curve_new_sized (4); /* Create blue bpath */ dc->blue_bpath = sp_canvas_bpath_new (SP_DT_SKETCH (ec->desktop), NULL); sp_canvas_bpath_set_stroke (SP_CANVAS_BPATH (dc->blue_bpath), dc->blue_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); /* Create blue curve */ dc->blue_curve = sp_curve_new_sized (8); /* Create green curve */ dc->green_curve = sp_curve_new_sized (64); /* No green anchor by default */ dc->green_anchor = NULL; spdc_set_attach (dc, FALSE); }
void Inkscape::Rubberband::move(Geom::Point const &p) { if (!_started) return; _end = p; _desktop->scroll_to_point(p); _touchpath_curve->lineto(p); Geom::Point next = _desktop->d2w(p); // we want the points to be at most 0.5 screen pixels apart, // so that we don't lose anything small; // if they are farther apart, we interpolate more points if (_points.size() > 0 && Geom::L2(next-_points.back()) > 0.5) { Geom::Point prev = _points.back(); int subdiv = 2 * (int) round(Geom::L2(next-prev) + 0.5); for (int i = 1; i <= subdiv; i ++) { _points.push_back(prev + ((double)i/subdiv) * (next - prev)); } } else { _points.push_back(next); } if (_mode == RUBBERBAND_MODE_RECT) { if (_rect == NULL) { _rect = static_cast<CtrlRect *>(sp_canvas_item_new(sp_desktop_controls(_desktop), SP_TYPE_CTRLRECT, NULL)); } _rect->setRectangle(Geom::Rect(_start, _end)); sp_canvas_item_show(_rect); if (_touchpath) sp_canvas_item_hide(_touchpath); } else if (_mode == RUBBERBAND_MODE_TOUCHPATH) { if (_touchpath == NULL) { _touchpath = sp_canvas_bpath_new(sp_desktop_sketch(_desktop), NULL); sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(_touchpath), 0xff0000ff, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(_touchpath), 0, SP_WIND_RULE_NONZERO); } sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(_touchpath), _touchpath_curve); sp_canvas_item_show(_touchpath); if (_rect) sp_canvas_item_hide(_rect); } }
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; } }