Exemple #1
0
static void
sp_pen_context_setup (SPEventContext *ec)
{
	SPPenContext *pc;

	pc = SP_PEN_CONTEXT (ec);

	if (((SPEventContextClass *) pen_parent_class)->setup)
		((SPEventContextClass *) pen_parent_class)->setup (ec);

	/* Pen indicators */
	pc->c0 = sp_canvas_item_new (SP_DT_CONTROLS (SP_EVENT_CONTEXT_DESKTOP (ec)), SP_TYPE_CTRL, "shape", SP_CTRL_SHAPE_CIRCLE,
				     "size", 4.0, "filled", 0, "fill_color", 0xff00007f, "stroked", 1, "stroke_color", 0x0000ff7f, NULL);
	pc->c1 = sp_canvas_item_new (SP_DT_CONTROLS (SP_EVENT_CONTEXT_DESKTOP (ec)), SP_TYPE_CTRL, "shape", SP_CTRL_SHAPE_CIRCLE,
					"size", 4.0, "filled", 0, "fill_color", 0xff00007f, "stroked", 1, "stroke_color", 0x0000ff7f, NULL);
	pc->cl0 = sp_canvas_item_new (SP_DT_CONTROLS (SP_EVENT_CONTEXT_DESKTOP (ec)), SP_TYPE_CTRLLINE, NULL);
	sp_ctrlline_set_rgba32 (SP_CTRLLINE (pc->cl0), 0x0000007f);
	pc->cl1 = sp_canvas_item_new (SP_DT_CONTROLS (SP_EVENT_CONTEXT_DESKTOP (ec)), SP_TYPE_CTRLLINE, NULL);
	sp_ctrlline_set_rgba32 (SP_CTRLLINE (pc->cl1), 0x0000007f);

	sp_canvas_item_hide (pc->c0);
	sp_canvas_item_hide (pc->c1);
	sp_canvas_item_hide (pc->cl0);
	sp_canvas_item_hide (pc->cl1);

	sp_event_context_read (ec, "mode");
}
Exemple #2
0
SPCanvasItem *ControlManagerImpl::createControl(SPCanvasGroup *parent, ControlType type)
{
    SPCanvasItem *item = 0;
    double targetSize = _sizeTable[type][_size - 1];
    switch (type)
    {
        case CTRL_TYPE_ADJ_HANDLE:
            item = sp_canvas_item_new(parent, SP_TYPE_CTRL,
                                      "shape", SP_CTRL_SHAPE_CIRCLE,
                                      "size", targetSize,
                                      "filled", 0,
                                      "fill_color", 0xff00007f,
                                      "stroked", 1,
                                      "stroke_color", 0x0000ff7f,
                                      NULL);
            break;
        case CTRL_TYPE_ANCHOR:
            item = sp_canvas_item_new(parent, SP_TYPE_CTRL,
                                      "size", targetSize,
                                      "filled", 1,
                                      "fill_color", 0xffffff7f,
                                      "stroked", 1,
                                      "stroke_color", 0x000000ff,
                                      NULL);
            break;
        case CTRL_TYPE_NODE_AUTO:
        case CTRL_TYPE_NODE_CUSP:
        case CTRL_TYPE_NODE_SMOOTH:
        case CTRL_TYPE_NODE_SYMETRICAL:
        {
            SPCtrlShapeType shape = _ctrlToShape[_ctrlToShape.count(type) ? type : CTRL_TYPE_UNKNOWN];
            item = sp_canvas_item_new(parent, SP_TYPE_CTRL,
                                      "shape", shape,
                                      "size", targetSize,
                                      NULL);
            break;
        }
        case CTRL_TYPE_INVISIPOINT:
            item = sp_canvas_item_new(parent, SP_TYPE_CTRL,
                                      "shape", SP_CTRL_SHAPE_SQUARE,
                                      "size", targetSize,
                                      NULL);
            break;
        case CTRL_TYPE_UNKNOWN:
        default:
            item = sp_canvas_item_new(parent, SP_TYPE_CTRL, NULL);
    }
    if (item) {
        item->ctrlType = type;
    }
    return item;
}
Exemple #3
0
void SPSVGView::setDocument(SPDocument *document)
{
    if (doc()) {
        doc()->getRoot()->invoke_hide(_dkey);
    }

    if (!_drawing) {
        _drawing = sp_canvas_item_new (_parent, SP_TYPE_CANVAS_ARENA, NULL);
        g_signal_connect (G_OBJECT (_drawing), "arena_event", G_CALLBACK (arena_handler), this);
    }

    View::setDocument (document);

    if (document) {
        Inkscape::DrawingItem *ai = document->getRoot()->invoke_show(
                SP_CANVAS_ARENA (_drawing)->drawing,
                _dkey,
                SP_ITEM_SHOW_DISPLAY);

        if (ai) {
            SP_CANVAS_ARENA (_drawing)->drawing.root()->prependChild(ai);
        }

        doRescale (!_rescale);
    }
}
Exemple #4
0
/**
 * Creates an anchor object and initializes it.
 */
SPDrawAnchor *sp_draw_anchor_new(SPDrawContext *dc, SPCurve *curve, gboolean start, Geom::Point delta)
{
    if (SP_IS_LPETOOL_CONTEXT(dc)) {
        // suppress all kinds of anchors in LPEToolContext
        return NULL;
    }

    SPDesktop *dt = SP_EVENT_CONTEXT_DESKTOP(dc);

    SPDrawAnchor *a = g_new(SPDrawAnchor, 1);

    a->dc = dc;
    a->curve = curve;
    curve->ref();
    a->start = start;
    a->active = FALSE;
    a->dp = delta;
    a->ctrl = sp_canvas_item_new(sp_desktop_controls(dt), SP_TYPE_CTRL,
                                 "size", 6.0,
                                 "filled", 1,
                                 "fill_color", FILL_COLOR_NORMAL,
                                 "stroked", 1,
                                 "stroke_color", 0x000000ff,
                                 NULL);

    SP_CTRL(a->ctrl)->moveto(delta);

    return a;
}
/**
 * Return new knot object.
 */
SPKnot *sp_knot_new(SPDesktop *desktop, const gchar *tip)
{
    g_return_val_if_fail(desktop != NULL, NULL);

    SPKnot * knot = (SPKnot*) g_object_new(SP_TYPE_KNOT, 0);

    knot->desktop = desktop;
    knot->flags = SP_KNOT_VISIBLE;
    if (tip) {
        knot->tip = g_strdup (tip);
    }

    knot->item = sp_canvas_item_new(sp_desktop_controls (desktop),
                                    SP_TYPE_CTRL,
                                    "anchor", GTK_ANCHOR_CENTER,
                                    "size", 8.0,
                                    "filled", TRUE,
                                    "fill_color", 0xffffff00,
                                    "stroked", TRUE,
                                    "stroke_color", 0x01000000,
                                    "mode", SP_KNOT_MODE_XOR,
                                    NULL);

    knot->_event_handler_id = gtk_signal_connect(GTK_OBJECT(knot->item), "event",
                                                 GTK_SIGNAL_FUNC(sp_knot_handler), knot);

    return knot;
}
Exemple #6
0
static SPDrawAnchor *
sp_draw_anchor_new (SPDrawContext *dc, SPCurve *curve, gboolean start, gdouble dx, gdouble dy)
{
	SPDrawAnchor *a;

	g_print ("Creating anchor at %g %g\n", dx, dy);

	a = g_new (SPDrawAnchor, 1);

	a->dc = dc;
	a->curve = curve;
	a->start = start;
	a->active = FALSE;
	a->dp.x = dx;
	a->dp.y = dy;
	sp_desktop_d2w_xy_point (SP_EVENT_CONTEXT_DESKTOP (dc), &a->wp, dx, dy);
	a->ctrl = sp_canvas_item_new (SP_DT_CONTROLS (SP_EVENT_CONTEXT_DESKTOP (dc)), SP_TYPE_CTRL,
					 "size", 4.0,
					 "filled", 0,
					 "fill_color", 0xff00007f,
					 "stroked", 1,
					 "stroke_color", 0x000000ff,
					 NULL);

	sp_ctrl_moveto (SP_CTRL (a->ctrl), dx, dy);

	return a;
}
Exemple #7
0
/**
 * Callback to initialize SPSVGSPViewWidget object.
 */
static void sp_svg_view_widget_init(SPSVGSPViewWidget *vw)
{
	SPCanvasItem *parent;

	/* Settings */
	vw->resize = FALSE;
	vw->maxwidth = 400.0;
	vw->maxheight = 400.0;

	/* ScrolledWindow */
	vw->sw = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(vw->sw), GTK_SHADOW_NONE);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (vw->sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
	gtk_container_add (GTK_CONTAINER (vw), vw->sw);
	gtk_widget_show (vw->sw);

	/* Canvas */
#if !GTK_CHECK_VERSION(3,0,0)
	GdkColormap *cmap = gdk_colormap_get_system();
	gtk_widget_push_colormap(cmap);
#endif

	vw->canvas = SPCanvas::createAA();

#if GTK_CHECK_VERSION(3,0,0)
        GtkCssProvider  *css_provider  = gtk_css_provider_new();
        GtkStyleContext *style_context = gtk_widget_get_style_context(GTK_WIDGET(vw->canvas));

        gtk_css_provider_load_from_data(css_provider,
                                        "SPCanvas {\n"
                                        " background-color: white;\n"
                                        "}\n",
                                        -1, NULL);

        gtk_style_context_add_provider(style_context,
                                       GTK_STYLE_PROVIDER(css_provider),
                                       GTK_STYLE_PROVIDER_PRIORITY_USER);
#else
	gtk_widget_pop_colormap ();
	GtkStyle *style = gtk_style_copy (gtk_widget_get_style (vw->canvas));
	style->bg[GTK_STATE_NORMAL] = style->white;
	gtk_widget_set_style (vw->canvas, style);
#endif

#if GTK_CHECK_VERSION(3,0,0)
	gtk_container_add (GTK_CONTAINER (vw->sw), vw->canvas);
#else
	gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (vw->sw), vw->canvas);
#endif

	gtk_widget_show (vw->canvas);

	/* View */
	parent = sp_canvas_item_new(SP_CANVAS(vw->canvas)->getRoot(), SP_TYPE_CANVAS_GROUP, NULL);
	Inkscape::UI::View::View *view = Inkscape::GC::release(new SPSVGView (SP_CANVAS_GROUP (parent)));
	sp_view_widget_set_view (SP_VIEW_WIDGET (vw), view);
}
Exemple #8
0
/**
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);
}
Exemple #9
0
SPCtrlLine *ControlManager::createControlLine(SPCanvasGroup *parent, CtrlLineType type)
{
    SPCtrlLine *line = SP_CTRLLINE(sp_canvas_item_new(parent, SP_TYPE_CTRLLINE, NULL));
    if (line) {
        line->ctrlType = CTRL_TYPE_LINE;

        line->setRgba32((type == CTLINE_PRIMARY) ? LINE_COLOR_PRIMARY :
                        (type == CTLINE_SECONDARY) ? LINE_COLOR_SECONDARY : LINE_COLOR_TERTIARY);
    }
    return line;
}
Exemple #10
0
 SelectorPoint(SPDesktop *d, SPCanvasGroup *group, Selector *s)
     : ControlPoint(d, Geom::Point(0,0), Gtk::ANCHOR_CENTER, SP_CTRL_SHAPE_SQUARE,
         1, &invisible_cset, group)
     , _selector(s)
     , _cancel(false)
 {
     setVisible(false);
     _rubber = static_cast<CtrlRect*>(sp_canvas_item_new(sp_desktop_controls(_desktop),
     SP_TYPE_CTRLRECT, NULL));
     sp_canvas_item_hide(_rubber);
 }
Exemple #11
0
SPCtrlCurve *ControlManager::createControlCurve(SPCanvasGroup *parent, Geom::Point const &p0, Geom::Point const &p1, Geom::Point const &p2, Geom::Point const &p3, CtrlLineType type)
{
    SPCtrlCurve *line = SP_CTRLCURVE(sp_canvas_item_new(parent, SP_TYPE_CTRLCURVE, NULL));
    if (line) {
        line->ctrlType = CTRL_TYPE_LINE;

        line->setRgba32((type == CTLINE_PRIMARY) ? LINE_COLOR_PRIMARY :
                        (type == CTLINE_SECONDARY) ? LINE_COLOR_SECONDARY : LINE_COLOR_TERTIARY);
        line->setCoords(p0, p1, p2, p3);
    }
    return line;
}
Exemple #12
0
void create_canvas_point(Geom::Point const &pos, double size, guint32 rgba)
{
    SPDesktop *desktop = inkscape_active_desktop();
    SPCanvasItem * canvas_pt = sp_canvas_item_new(sp_desktop_controls(desktop), SP_TYPE_CTRL,
                          "size", size,
                          "filled", 1,
                          "fill_color", rgba,
                          "stroked", 1,
                          "stroke_color", 0x000000ff,
                          NULL);
    SP_CTRL(canvas_pt)->moveto(pos);
}
Exemple #13
0
SPCanvasItem *
sp_canvas_bpath_new (SPCanvasGroup *parent, SPCurve *curve)
{
    g_return_val_if_fail (parent != NULL, NULL);
    g_return_val_if_fail (SP_IS_CANVAS_GROUP (parent), NULL);

    SPCanvasItem *item = sp_canvas_item_new (parent, SP_TYPE_CANVAS_BPATH, NULL);

    sp_canvas_bpath_set_bpath (SP_CANVAS_BPATH (item), curve);

    return item;
}
SPCanvasText *sp_canvastext_new(SPCanvasGroup *parent, SPDesktop *desktop, Geom::Point pos, gchar const *new_text)
{
    // Pos specifies the position of the anchor, which is at the bounding box of the text itself (i.e. not at the border of the filled background rectangle)
    // The relative position of the anchor can be set using e.g. anchor_position = TEXT_ANCHOR_LEFT
    SPCanvasItem *item = sp_canvas_item_new(parent, SP_TYPE_CANVASTEXT, NULL);

    SPCanvasText *ct = SP_CANVASTEXT(item);

    ct->desktop = desktop;

    ct->s = pos;
    g_free(ct->text);
    ct->text = g_strdup(new_text);

    return ct;
}
Exemple #15
0
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);
    }
}
Exemple #16
0
void
sp_sel_trans_init (SPSelTrans * seltrans, SPDesktop * desktop)
{
	gint i;

	g_return_if_fail (seltrans != NULL);
	g_return_if_fail (desktop != NULL);
	g_return_if_fail (SP_IS_DESKTOP (desktop));

	seltrans->desktop = desktop;

	seltrans->state = SP_SELTRANS_STATE_SCALE;
	seltrans->show = SP_SELTRANS_SHOW_CONTENT;
	seltrans->transform = SP_SELTRANS_TRANSFORM_OPTIMIZE;

	seltrans->items = NULL;
	seltrans->transforms = NULL;
	seltrans->nitems = 0;

	seltrans->spp = nr_new (NRPointF, SP_SELTRANS_SPP_SIZE);

	seltrans->grabbed = FALSE;
	seltrans->show_handles = TRUE;
	for (i = 0; i < 8; i++) seltrans->shandle[i] = NULL;
	for (i = 0; i < 8; i++) seltrans->rhandle[i] = NULL;
	seltrans->chandle = NULL;

	sp_sel_trans_update_volatile_state (seltrans);
	
	seltrans->center.x = (seltrans->box.x0 + seltrans->box.x1) / 2;
	seltrans->center.y = (seltrans->box.y0 + seltrans->box.y1) / 2;

	sp_sel_trans_update_handles (seltrans);

	seltrans->selection = SP_DT_SELECTION (desktop);
	g_signal_connect (G_OBJECT (seltrans->selection), "changed", G_CALLBACK (sp_sel_trans_sel_changed), seltrans);
	g_signal_connect (G_OBJECT (seltrans->selection), "modified", G_CALLBACK (sp_sel_trans_sel_modified), seltrans);

	seltrans->norm = sp_canvas_item_new (SP_DT_CONTROLS (desktop),
		SP_TYPE_CTRL,
		"anchor", GTK_ANCHOR_CENTER,
		"mode", SP_CTRL_MODE_COLOR,
		"shape", SP_CTRL_SHAPE_BITMAP,
		"size", 13.0,
		"filled", TRUE,
		"fill_color", 0x00000000,
		"stroked", TRUE,
		"stroke_color", 0x000000a0,
		"pixbuf", handles[12],
		NULL);
	seltrans->grip = sp_canvas_item_new (SP_DT_CONTROLS (desktop),
		SP_TYPE_CTRL,
		"anchor", GTK_ANCHOR_CENTER,
		"mode", SP_CTRL_MODE_XOR,
		"shape", SP_CTRL_SHAPE_CROSS,
		"size", 7.0,
		"filled", TRUE,
		"fill_color", 0xffffff7f,
		"stroked", TRUE,
		"stroke_color", 0xffffffff,
		"pixbuf", handles[12],
		NULL);
	sp_canvas_item_hide (seltrans->grip);
	sp_canvas_item_hide (seltrans->norm);

	seltrans->l1 = sp_canvas_item_new (SP_DT_CONTROLS (desktop), SP_TYPE_CTRLLINE, NULL);
	sp_canvas_item_hide (seltrans->l1);
	seltrans->l2 = sp_canvas_item_new (SP_DT_CONTROLS (desktop), SP_TYPE_CTRLLINE, NULL);
	sp_canvas_item_hide (seltrans->l2);
	seltrans->l3 = sp_canvas_item_new (SP_DT_CONTROLS (desktop), SP_TYPE_CTRLLINE, NULL);
	sp_canvas_item_hide (seltrans->l3);
	seltrans->l4 = sp_canvas_item_new (SP_DT_CONTROLS (desktop), SP_TYPE_CTRLLINE, NULL);
	sp_canvas_item_hide (seltrans->l4);

	seltrans->stamp_cache = NULL;
}