diff options
Diffstat (limited to 'src/interface.cpp')
| -rw-r--r-- | src/interface.cpp | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/src/interface.cpp b/src/interface.cpp index 77c1e36b7..e7a3d6f28 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -76,7 +76,8 @@ typedef enum { JPEG_DATA, IMAGE_DATA, APP_X_INKY_COLOR, - APP_X_COLOR + APP_X_COLOR, + APP_X_NOCOLOR } ui_drop_target_info; static GtkTargetEntry ui_drop_target_entries [] = { @@ -88,6 +89,7 @@ static GtkTargetEntry ui_drop_target_entries [] = { #if ENABLE_MAGIC_COLORS {(gchar *)"application/x-inkscape-color", 0, APP_X_INKY_COLOR}, #endif // ENABLE_MAGIC_COLORS + {(gchar *)"application/x-inkscape-nocolor", 0, APP_X_NOCOLOR }, {(gchar *)"application/x-color", 0, APP_X_COLOR } }; @@ -1233,6 +1235,68 @@ sp_ui_drag_data_received(GtkWidget *widget, } break; + case APP_X_NOCOLOR: + { + gchar* c = g_strdup("none"); // temp + int destX = 0; + int destY = 0; + gtk_widget_translate_coordinates( widget, &(desktop->canvas->widget), x, y, &destX, &destY ); + Geom::Point where( sp_canvas_window_to_world( desktop->canvas, Geom::Point( destX, destY ) ) ); + Geom::Point const button_dt(desktop->w2d(where)); + Geom::Point const button_doc(desktop->dt2doc(button_dt)); + + SPItem *item = desktop->item_at_point( where, true ); + + bool consumed = false; + if (desktop->event_context && desktop->event_context->get_drag()) { + consumed = desktop->event_context->get_drag()->dropColor(item, c, button_dt); + if (consumed) { + sp_document_done( doc , SP_VERB_NONE, _("Drop color on gradient")); + desktop->event_context->get_drag()->updateDraggers(); + } + } + + if (!consumed && item) { + bool fillnotstroke = (drag_context->action != GDK_ACTION_MOVE); + if (fillnotstroke && + (SP_IS_SHAPE(item) || SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item))) { + Path *livarot_path = Path_for_item(item, true, true); + livarot_path->ConvertWithBackData(0.04); + + boost::optional<Path::cut_position> position = get_nearest_position_on_Path(livarot_path, button_doc); + if (position) { + Geom::Point nearest = get_point_on_Path(livarot_path, position->piece, position->t); + Geom::Point delta = nearest - button_doc; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + delta = desktop->d2w(delta); + double stroke_tolerance = + ( !SP_OBJECT_STYLE(item)->stroke.isNone() ? + desktop->current_zoom() * + SP_OBJECT_STYLE (item)->stroke_width.computed * + to_2geom(sp_item_i2d_affine(item)).descrim() * 0.5 + : 0.0) + + prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); + + if (Geom::L2 (delta) < stroke_tolerance) { + fillnotstroke = false; + } + } + delete livarot_path; + } + + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_set_property( css, fillnotstroke ? "fill":"stroke", c ); + + sp_desktop_apply_css_recursive( item, css, true ); + item->updateRepr(); + + sp_document_done( doc , SP_VERB_NONE, + _("Drop color")); + } + g_free(c); + } + break; + case SVG_DATA: case SVG_XML_DATA: { gchar *svgdata = (gchar *)data->data; |
