From 7672b906efcaa8acaa10a63787f62ef3bb9cc441 Mon Sep 17 00:00:00 2001 From: joncruz Date: Fri, 10 Mar 2006 07:07:04 +0000 Subject: [PATCH] Initial cut of color drag-n-drop to items on canvas. --- ChangeLog | 5 +++++ src/interface.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index c03a7cd8d..95ed6e187 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-03-09 Jon A. Cruz + * src/interface.cpp: + + Initial cut of color drag-n-drop to items on canvas. + 2006-03-09 Peter Moulder * src/path-chemistry.cpp (sp_selected_path_reverse): diff --git a/src/interface.cpp b/src/interface.cpp index 4a7c12f76..dd725477c 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -53,6 +53,13 @@ #include "message-context.h" +// Added for color drag-n-drop +#include "display/sp-canvas.h" +#include "color.h" +#include "svg/svg.h" +#include "desktop-style.h" +#include "style.h" + using Inkscape::IO::StringOutputStream; using Inkscape::IO::Base64OutputStream; @@ -67,7 +74,8 @@ typedef enum { SVG_DATA, PNG_DATA, JPEG_DATA, - IMAGE_DATA + IMAGE_DATA, + APP_X_COLOR } ui_drop_target_info; static GtkTargetEntry ui_drop_target_entries [] = { @@ -76,6 +84,7 @@ static GtkTargetEntry ui_drop_target_entries [] = { {"image/svg", 0, SVG_DATA}, {"image/png", 0, PNG_DATA}, {"image/jpeg", 0, JPEG_DATA}, + {"application/x-color", 0, APP_X_COLOR} }; static GtkTargetEntry *completeDropTargets = 0; @@ -965,6 +974,42 @@ sp_ui_drag_data_received(GtkWidget *widget, gpointer user_data) { switch (info) { + case APP_X_COLOR: + { + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + int destX = 0; + int destY = 0; + gtk_widget_translate_coordinates( widget, &(desktop->canvas->widget), x, y, &destX, &destY ); + NR::Point where( sp_canvas_window_to_world( desktop->canvas, NR::Point( destX, destY ) ) ); + + SPItem *item = desktop->item_at_point( where, true ); + if ( item ) + { + if ( data->length == 8 ) { + gchar c[64] = {0}; + // Careful about endian issues. + guint16* dataVals = (guint16*)data->data; + sp_svg_write_color( c, 64, + SP_RGBA32_U_COMPOSE( + 0x0ff & (dataVals[0] >> 8), + 0x0ff & (dataVals[1] >> 8), + 0x0ff & (dataVals[2] >> 8), + 0xff // can't have transparency in the color itself + //0x0ff & (data->data[3] >> 8), + )); + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_set_property( css, (true) ? "fill":"stroke", c ); + + sp_desktop_apply_css_recursive( item, css, true ); + item->updateRepr(); + + SPDocument *doc = SP_ACTIVE_DOCUMENT; + sp_document_done( doc ); + } + } + } + break; + case SVG_DATA: case SVG_XML_DATA: { gchar *svgdata = (gchar *)data->data; -- 2.30.2