From: joncruz Date: Tue, 3 Mar 2009 10:01:27 +0000 (+0000) Subject: Adding some no-color to drag-n-drop X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=359d8ad2cb77e7d73b38ff9f534604ece31c7493;p=inkscape.git Adding some no-color to drag-n-drop --- 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 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; diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index dfb60c04e..ff4934912 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -96,6 +96,7 @@ typedef enum { APP_X_INKY_COLOR_ID = 0, APP_X_INKY_COLOR = 0, APP_X_COLOR, + APP_X_NOCOLOR, TEXT_DATA } colorFlavorType; @@ -114,6 +115,12 @@ static const GtkTargetEntry sourceColorEntries[] = { {"text/plain", 0, TEXT_DATA}, }; +static const GtkTargetEntry sourceNoColorEntries[] = { + {"application/x-inkscape-nocolor", 0, APP_X_NOCOLOR}, + {"application/x-color", 0, APP_X_COLOR}, + {"text/plain", 0, TEXT_DATA}, +}; + void ColorItem::_dragGetColorData( GtkWidget *widget, GdkDragContext *drag_context, GtkSelectionData *data, @@ -158,6 +165,51 @@ void ColorItem::_dragGetColorData( GtkWidget *widget, } } +// if ( found ) { +// g_message("Found the color at entry %d in palette '%s'", index, paletteName.c_str() ); +// } else { +// g_message("Unable to find the color"); +// } + int itemCount = 4 + 2 + 1 + paletteName.length(); + + guint16* tmp = new guint16[itemCount]; + tmp[0] = (item->def.getR() << 8) | item->def.getR(); + tmp[1] = (item->def.getG() << 8) | item->def.getG(); + tmp[2] = (item->def.getB() << 8) | item->def.getB(); + tmp[3] = 0xffff; + tmp[4] = (item->_isLive || !item->_listeners.empty() || (item->_linkSrc != 0) ) ? 1 : 0; + + tmp[5] = index; + tmp[6] = paletteName.length(); + for ( unsigned int i = 0; i < paletteName.length(); i++ ) { + tmp[7 + i] = paletteName[i]; + } + gtk_selection_data_set( data, + typeXColor, + 16, // format + reinterpret_cast(tmp), + itemCount * 2); + delete[] tmp; + } else if ( info == APP_X_NOCOLOR ) { + Glib::ustring paletteName; + + // Find where this thing came from + bool found = false; + int index = 0; + for ( std::vector::iterator it = possible.begin(); it != possible.end() && !found; ++it ) { + JustForNow* curr = *it; + index = 0; + for ( std::vector::iterator zz = curr->_colors.begin(); zz != curr->_colors.end(); ++zz ) { + if ( item == *zz ) { + found = true; + paletteName = curr->_name; + break; + } else { + index++; + } + } + } + // if ( found ) { // g_message("Found the color at entry %d in palette '%s'", index, paletteName.c_str() ); // } else { @@ -398,6 +450,10 @@ void ColorItem::_dropDataIn( GtkWidget *widget, } break; } + case APP_X_NOCOLOR: + { +// g_message("APP_X_NOCOLOR dropping through to x-color"); + } case APP_X_COLOR: { if ( data->length == 8 ) { @@ -643,11 +699,19 @@ Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, ::PreviewS G_CALLBACK(handleButtonPress), this); - gtk_drag_source_set( GTK_WIDGET(newBlot->gobj()), - GDK_BUTTON1_MASK, - sourceColorEntries, - G_N_ELEMENTS(sourceColorEntries), - GdkDragAction(GDK_ACTION_MOVE | GDK_ACTION_COPY) ); + if ( isRemove() ) { + gtk_drag_source_set( GTK_WIDGET(newBlot->gobj()), + GDK_BUTTON1_MASK, + sourceNoColorEntries, + G_N_ELEMENTS(sourceNoColorEntries), + GdkDragAction(GDK_ACTION_MOVE | GDK_ACTION_COPY) ); + } else { + gtk_drag_source_set( GTK_WIDGET(newBlot->gobj()), + GDK_BUTTON1_MASK, + sourceColorEntries, + G_N_ELEMENTS(sourceColorEntries), + GdkDragAction(GDK_ACTION_MOVE | GDK_ACTION_COPY) ); + } g_signal_connect( G_OBJECT(newBlot->gobj()), "drag-data-get",