- // find by how much we translate the pasted selection
- gnome_canvas_get_scroll_offsets(canvas, &sx, &sy);
- gdk_window_get_geometry(GTK_WIDGET(canvas)->window, NULL, NULL, &wx, &wy, NULL);
- gnome_canvas_window_to_world(canvas, sx + wx/2, sy + wy/2, &cx, &cy);
- cx -= ui.cur_page->hoffset;
- cy -= ui.cur_page->voffset;
- if (cx + (ui.selection->bbox.right-ui.selection->bbox.left)/2 > ui.cur_page->width)
- cx = ui.cur_page->width - (ui.selection->bbox.right-ui.selection->bbox.left)/2;
- if (cx - (ui.selection->bbox.right-ui.selection->bbox.left)/2 < 0)
- cx = (ui.selection->bbox.right-ui.selection->bbox.left)/2;
- if (cy + (ui.selection->bbox.bottom-ui.selection->bbox.top)/2 > ui.cur_page->height)
- cy = ui.cur_page->height - (ui.selection->bbox.bottom-ui.selection->bbox.top)/2;
- if (cy - (ui.selection->bbox.bottom-ui.selection->bbox.top)/2 < 0)
- cy = (ui.selection->bbox.bottom-ui.selection->bbox.top)/2;
- hoffset = cx - (ui.selection->bbox.right+ui.selection->bbox.left)/2;
- voffset = cy - (ui.selection->bbox.top+ui.selection->bbox.bottom)/2;
- ui.selection->bbox.left += hoffset;
- ui.selection->bbox.right += hoffset;
- ui.selection->bbox.top += voffset;
- ui.selection->bbox.bottom += voffset;
-
- ui.selection->canvas_item = gnome_canvas_item_new(ui.cur_layer->group,
- gnome_canvas_rect_get_type(), "width-pixels", 1,
- "outline-color-rgba", 0x000000ff,
- "fill-color-rgba", 0x80808040,
- "x1", ui.selection->bbox.left, "x2", ui.selection->bbox.right,
- "y1", ui.selection->bbox.top, "y2", ui.selection->bbox.bottom, NULL);
- make_dashed(ui.selection->canvas_item);
-
- while (nitems-- > 0) {
- item = g_new(struct Item, 1);
- ui.selection->items = g_list_append(ui.selection->items, item);
- ui.cur_layer->items = g_list_append(ui.cur_layer->items, item);
- ui.cur_layer->nitems++;
- g_memmove(&item->type, p, sizeof(int)); p+= sizeof(int);
- if (item->type == ITEM_STROKE) {
- g_memmove(&item->brush, p, sizeof(struct Brush)); p+= sizeof(struct Brush);
- g_memmove(&npts, p, sizeof(int)); p+= sizeof(int);
- item->path = gnome_canvas_points_new(npts);
- pf = (double *)p;
- for (i=0; i<npts; i++) {
- item->path->coords[2*i] = pf[2*i] + hoffset;
- item->path->coords[2*i+1] = pf[2*i+1] + voffset;
- }
- p+= 2*item->path->num_points*sizeof(double);
- update_item_bbox(item);
- item->canvas_item = gnome_canvas_item_new(ui.cur_layer->group,
- gnome_canvas_line_get_type(), "points", item->path,
- "cap-style", GDK_CAP_ROUND, "join-style", GDK_JOIN_ROUND,
- "fill-color-rgba", item->brush.color_rgba,
- "width-units", item->brush.thickness, NULL);
- }