/** * Set flag in knot, with side effects. */ void sp_knot_set_flag(SPKnot *knot, guint flag, bool set) { g_assert(knot != NULL); g_assert(SP_IS_KNOT(knot)); if (set) { knot->flags |= flag; } else { knot->flags &= ~flag; } switch (flag) { case SP_KNOT_VISIBLE: if (set) { sp_canvas_item_show(knot->item); } else { sp_canvas_item_hide(knot->item); } break; case SP_KNOT_MOUSEOVER: case SP_KNOT_DRAGGING: sp_knot_set_ctrl_state(knot); break; case SP_KNOT_GRABBED: break; default: g_assert_not_reached(); break; } }
void create_canvas_line(Geom::Point const &p1, Geom::Point const &p2, guint32 rgba) { SPDesktop *desktop = inkscape_active_desktop(); SPCtrlLine *line = ControlManager::getManager().createControlLine(sp_desktop_controls(desktop), p1, p2); line->setRgba32(rgba); sp_canvas_item_show(line); }
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); } }
/** Create a line from p1 to p2 and add it to the lines list */ void VPDrag::addLine (Geom::Point p1, Geom::Point p2, guint32 rgba) { SPCanvasItem *line = sp_canvas_item_new(sp_desktop_controls(inkscape_active_desktop()), SP_TYPE_CTRLLINE, NULL); sp_ctrlline_set_coords(SP_CTRLLINE(line), p1, p2); if (rgba != VP_LINE_COLOR_FILL) // fill is the default, so don't set color for it to speed up redraw sp_ctrlline_set_rgba32 (SP_CTRLLINE(line), rgba); sp_canvas_item_show (line); this->lines = g_slist_append (this->lines, line); }
static void spdc_pen_set_ctrl (SPPenContext *pc, NRPointF *p, guint state) { SPDrawContext *dc; dc = SP_DRAW_CONTEXT (pc); sp_canvas_item_show (pc->c1); sp_canvas_item_show (pc->cl1); if (dc->npoints == 2) { dc->p[1] = *p; sp_canvas_item_hide (pc->c0); sp_canvas_item_hide (pc->cl0); sp_ctrl_moveto (SP_CTRL (pc->c1), dc->p[1].x, dc->p[1].y); sp_ctrlline_set_coords (SP_CTRLLINE (pc->cl1), dc->p[0].x, dc->p[0].y, dc->p[1].x, dc->p[1].y); } else if (dc->npoints == 5) { dc->p[4] = *p; sp_canvas_item_show (pc->c0); sp_canvas_item_show (pc->cl0); if (((pc->mode == SP_PEN_CONTEXT_MODE_CLICK) && (state & GDK_CONTROL_MASK)) || ((pc->mode == SP_PEN_CONTEXT_MODE_DRAG) && !(state & GDK_MOD1_MASK))) { gdouble dx, dy; dx = p->x - dc->p[3].x; dy = p->y - dc->p[3].y; dc->p[2].x = dc->p[3].x - dx; dc->p[2].y = dc->p[3].y - dy; sp_curve_reset (dc->red_curve); sp_curve_moveto (dc->red_curve, dc->p[0].x, dc->p[0].y); sp_curve_curveto (dc->red_curve, dc->p[1].x, dc->p[1].y, dc->p[2].x, dc->p[2].y, dc->p[3].x, dc->p[3].y); sp_canvas_bpath_set_bpath (SP_CANVAS_BPATH (dc->red_bpath), dc->red_curve); } sp_ctrl_moveto (SP_CTRL (pc->c0), dc->p[2].x, dc->p[2].y); sp_ctrlline_set_coords (SP_CTRLLINE (pc->cl0), dc->p[3].x, dc->p[3].y, dc->p[2].x, dc->p[2].y); sp_ctrl_moveto (SP_CTRL (pc->c1), dc->p[4].x, dc->p[4].y); sp_ctrlline_set_coords (SP_CTRLLINE (pc->cl1), dc->p[3].x, dc->p[3].y, dc->p[4].x, dc->p[4].y); } else { g_warning ("Something bad happened - npoints is %d", dc->npoints); } }
static void sp_sel_trans_handle_grab (SPKnot * knot, guint state, gpointer data) { SPDesktop * desktop; SPSelTrans * seltrans; SPSelTransHandle * handle; NRPointF p; NRPointF pf; desktop = knot->desktop; seltrans = &SP_SELECT_CONTEXT (desktop->event_context)->seltrans; handle = (SPSelTransHandle *) data; switch (handle->anchor) { case GTK_ANCHOR_CENTER: g_object_set (G_OBJECT (seltrans->grip), "shape", SP_CTRL_SHAPE_BITMAP, "size", 13.0, NULL); sp_canvas_item_show (seltrans->grip); break; default: g_object_set (G_OBJECT (seltrans->grip), "shape", SP_CTRL_SHAPE_CROSS, "size", 7.0, NULL); sp_canvas_item_show (seltrans->norm); sp_canvas_item_show (seltrans->grip); break; } sp_knot_position (knot, &p); pf.x = p.x; pf.y = p.y; sp_sel_trans_grab (seltrans, &pf, handle->x, handle->y, FALSE); }
void sp_sel_trans_grab (SPSelTrans * seltrans, NRPointF *p, gdouble x, gdouble y, gboolean show_handles) { SPSelection *selection; const GSList *l; int n; selection = SP_DT_SELECTION (seltrans->desktop); g_return_if_fail (!seltrans->grabbed); seltrans->grabbed = TRUE; seltrans->show_handles = show_handles; sp_sel_trans_update_volatile_state (seltrans); seltrans->changed = FALSE; if (seltrans->empty) return; l = sp_selection_item_list (selection); seltrans->nitems = g_slist_length ((GSList *) l); seltrans->items = nr_new (SPItem *, seltrans->nitems); seltrans->transforms = nr_new (NRMatrixF, seltrans->nitems); n = 0; while (l) { seltrans->items[n] = (SPItem *) sp_object_ref (SP_OBJECT (l->data), NULL); sp_item_i2d_affine (seltrans->items[n], &seltrans->transforms[n]); l = l->next; n += 1; } nr_matrix_d_set_identity (&seltrans->current); seltrans->point.x = p->x; seltrans->point.y = p->y; seltrans->spp_length = sp_selection_snappoints (selection, seltrans->spp, SP_SELTRANS_SPP_SIZE); seltrans->opposit.x = seltrans->box.x0 + (1 - x) * fabs (seltrans->box.x1 - seltrans->box.x0); seltrans->opposit.y = seltrans->box.y0 + (1 - y) * fabs (seltrans->box.y1 - seltrans->box.y0); if ((x != -1) && (y != -1)) { sp_canvas_item_show (seltrans->norm); sp_canvas_item_show (seltrans->grip); } if (seltrans->show == SP_SELTRANS_SHOW_OUTLINE) { sp_canvas_item_show (seltrans->l1); sp_canvas_item_show (seltrans->l2); sp_canvas_item_show (seltrans->l3); sp_canvas_item_show (seltrans->l4); } sp_sel_trans_update_handles (seltrans); g_return_if_fail(seltrans->stamp_cache == NULL); }
static gint sp_dropper_context_root_handler(SPEventContext *event_context, GdkEvent *event) { SPDropperContext *dc = (SPDropperContext *) event_context; int ret = FALSE; SPDesktop *desktop = event_context->desktop; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int pick = prefs->getInt("/tools/dropper/pick", SP_DROPPER_PICK_VISIBLE); bool setalpha = prefs->getBool("/tools/dropper/setalpha", true); switch (event->type) { case GDK_BUTTON_PRESS: if (event->button.button == 1 && !event_context->space_panning) { dc->centre = Geom::Point(event->button.x, event->button.y); dc->dragging = TRUE; ret = TRUE; } break; case GDK_MOTION_NOTIFY: if (event->motion.state & GDK_BUTTON2_MASK) { // pass on middle-drag ret = FALSE; break; } else if (!event_context->space_panning) { // otherwise, constantly calculate color no matter is any button pressed or not double rw = 0.0; double W(0), R(0), G(0), B(0), A(0); if (dc->dragging) { // calculate average // radius rw = std::min(Geom::L2(Geom::Point(event->button.x, event->button.y) - dc->centre), 400.0); if (rw == 0) { // happens sometimes, little idea why... break; } Geom::Point const cd = desktop->w2d(dc->centre); Geom::Matrix const w2dt = desktop->w2d(); const double scale = rw * w2dt.descrim(); Geom::Matrix const sm( Geom::Scale(scale, scale) * Geom::Translate(cd) ); sp_canvas_item_affine_absolute(dc->area, sm); sp_canvas_item_show(dc->area); /* Get buffer */ const int x0 = (int) floor(dc->centre[Geom::X] - rw); const int y0 = (int) floor(dc->centre[Geom::Y] - rw); const int x1 = (int) ceil(dc->centre[Geom::X] + rw); const int y1 = (int) ceil(dc->centre[Geom::Y] + rw); if ((x1 > x0) && (y1 > y0)) { NRPixBlock pb; nr_pixblock_setup_fast(&pb, NR_PIXBLOCK_MODE_R8G8B8A8P, x0, y0, x1, y1, TRUE); /* fixme: (Lauris) */ sp_canvas_arena_render_pixblock(SP_CANVAS_ARENA(sp_desktop_drawing(desktop)), &pb); for (int y = y0; y < y1; y++) { const unsigned char *s = NR_PIXBLOCK_PX(&pb) + (y - y0) * pb.rs; for (int x = x0; x < x1; x++) { const double dx = x - dc->centre[Geom::X]; const double dy = y - dc->centre[Geom::Y]; const double w = exp(-((dx * dx) + (dy * dy)) / (rw * rw)); W += w; R += w * s[0]; G += w * s[1]; B += w * s[2]; A += w * s[3]; s += 4; } } nr_pixblock_release(&pb); R = (R + 0.001) / (255.0 * W); G = (G + 0.001) / (255.0 * W); B = (B + 0.001) / (255.0 * W); A = (A + 0.001) / (255.0 * W); R = CLAMP(R, 0.0, 1.0); G = CLAMP(G, 0.0, 1.0); B = CLAMP(B, 0.0, 1.0); A = CLAMP(A, 0.0, 1.0); } } else { // pick single pixel NRPixBlock pb; int x = (int) floor(event->button.x); int y = (int) floor(event->button.y); nr_pixblock_setup_fast(&pb, NR_PIXBLOCK_MODE_R8G8B8A8P, x, y, x+1, y+1, TRUE); sp_canvas_arena_render_pixblock(SP_CANVAS_ARENA(sp_desktop_drawing(desktop)), &pb); const unsigned char *s = NR_PIXBLOCK_PX(&pb); R = s[0] / 255.0; G = s[1] / 255.0; B = s[2] / 255.0; A = s[3] / 255.0; } if (pick == SP_DROPPER_PICK_VISIBLE) { // compose with page color guint32 bg = sp_desktop_namedview(desktop)->pagecolor; R = R + (SP_RGBA32_R_F(bg)) * (1 - A); G = G + (SP_RGBA32_G_F(bg)) * (1 - A); B = B + (SP_RGBA32_B_F(bg)) * (1 - A); A = 1.0; } else { // un-premultiply color channels if (A > 0) { R /= A; G /= A; B /= A; } } if (fabs(A) < 1e-4) { A = 0; // suppress exponentials, CSS does not allow that } // remember color dc->R = R; dc->G = G; dc->B = B; dc->alpha = A; // status message double alpha_to_set = setalpha? dc->alpha : 1.0; guint32 c32 = SP_RGBA32_F_COMPOSE(R, G, B, alpha_to_set); gchar c[64]; sp_svg_write_color(c, sizeof(c), c32); // alpha of color under cursor, to show in the statusbar // locale-sensitive printf is OK, since this goes to the UI, not into SVG gchar *alpha = g_strdup_printf(_(" alpha %.3g"), alpha_to_set); // where the color is picked, to show in the statusbar gchar *where = dc->dragging ? g_strdup_printf(_(", averaged with radius %d"), (int) rw) : g_strdup_printf(_(" under cursor")); // message, to show in the statusbar const gchar *message = dc->dragging ? _("<b>Release mouse</b> to set color.") : _("<b>Click</b> to set fill, <b>Shift+click</b> to set stroke; <b>drag</b> to average color in area; with <b>Alt</b> to pick inverse color; <b>Ctrl+C</b> to copy the color under mouse to clipboard"); event_context->defaultMessageContext()->setF( Inkscape::NORMAL_MESSAGE, "<b>%s%s</b>%s. %s", c, (pick == SP_DROPPER_PICK_VISIBLE)? "" : alpha, where, message ); g_free(where); g_free(alpha); ret = TRUE; } break; case GDK_BUTTON_RELEASE: if (event->button.button == 1 && !event_context->space_panning) { sp_canvas_item_hide(dc->area); dc->dragging = FALSE; double alpha_to_set = setalpha? dc->alpha : 1.0; // do the actual color setting sp_desktop_set_color(desktop, (event->button.state & GDK_MOD1_MASK)? ColorRGBA(1 - dc->R, 1 - dc->G, 1 - dc->B, alpha_to_set) : ColorRGBA(dc->R, dc->G, dc->B, alpha_to_set), false, !(event->button.state & GDK_SHIFT_MASK)); // REJON: set aux. toolbar input to hex color! if (!(sp_desktop_selection(desktop)->isEmpty())) { sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_DROPPER, _("Set picked color")); } ret = TRUE; } break; case GDK_KEY_PRESS: switch (get_group0_keyval(&event->key)) { case GDK_Up: case GDK_Down: case GDK_KP_Up: case GDK_KP_Down: // prevent the zoom field from activation if (!MOD__CTRL_ONLY) { ret = TRUE; } break; case GDK_Escape: sp_desktop_selection(desktop)->clear(); default: break; } break; default: break; } if (!ret) { if (((SPEventContextClass *) parent_class)->root_handler) { ret = ((SPEventContextClass *) parent_class)->root_handler(event_context, event); } } return ret; }
virtual bool grabbed(GdkEventMotion *) { _cancel = false; _start = position(); sp_canvas_item_show(_rubber); return false; }