From 040d951511fa76daf078fc39b02ccff2f7bf888c Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Fri, 2 Jul 2010 01:18:10 -0700 Subject: [PATCH] Rough pass of Fill-n-Stroke swatch conversion. --- src/sp-gradient.cpp | 12 ++++++ src/sp-gradient.h | 2 + src/ui/dialog/swatches.cpp | 71 ++++++++++++++++++---------------- src/widgets/fill-style.cpp | 6 ++- src/widgets/paint-selector.cpp | 1 + 5 files changed, 57 insertions(+), 35 deletions(-) diff --git a/src/sp-gradient.cpp b/src/sp-gradient.cpp index 0c0c94784..9c1ea0da7 100644 --- a/src/sp-gradient.cpp +++ b/src/sp-gradient.cpp @@ -288,6 +288,18 @@ SPGradientSpread SPGradient::getSpread() const return spread; } +void SPGradient::setSwatch() +{ + if ( !isSwatch() ) { + if ( hasStops() && (getStopCount() == 0) ) { + repr->setAttribute("osb:paint", "solid"); + } else { + repr->setAttribute("osb:paint", "gradient"); + } + requestModified(SP_OBJECT_MODIFIED_FLAG); + } +} + /** * Return stop's color as 32bit value. */ diff --git a/src/sp-gradient.h b/src/sp-gradient.h index 7e6afe052..f1705f1c1 100644 --- a/src/sp-gradient.h +++ b/src/sp-gradient.h @@ -142,6 +142,8 @@ public: SPGradientSpread fetchSpread(); SPGradientUnits fetchUnits(); + void setSwatch(); + private: bool invalidateVector(); void rebuildVector(); diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index 90e9e5f7b..755a10519 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -72,7 +72,8 @@ static std::map docPerPanel; class SwatchesPanelHook : public SwatchesPanel { public: - static void convertGradient( GtkMenuItem * menuitem, gpointer userData ); + static void convertGradient( GtkMenuItem *menuitem, gpointer userData ); + static void addNewGradient( GtkMenuItem *menuitem, gpointer user_data ); }; static void handleClick( GtkWidget* /*widget*/, gpointer callback_data ) { @@ -139,7 +140,7 @@ static void editGradient( GtkMenuItem */*menuitem*/, gpointer /*user_data*/ ) } } -static void addNewGradient( GtkMenuItem */*menuitem*/, gpointer /*user_data*/ ) +void SwatchesPanelHook::addNewGradient( GtkMenuItem */*menuitem*/, gpointer /*user_data*/ ) { if ( bounceTarget ) { SwatchesPanel* swp = bouncePanel; @@ -147,21 +148,22 @@ static void addNewGradient( GtkMenuItem */*menuitem*/, gpointer /*user_data*/ ) SPDocument *doc = desktop ? desktop->doc() : 0; if (doc) { Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); + SPGradient * gr = 0; + { + Inkscape::XML::Node *repr = xml_doc->createElement("svg:linearGradient"); + Inkscape::XML::Node *stop = xml_doc->createElement("svg:stop"); + stop->setAttribute("offset", "0"); + stop->setAttribute("style", "stop-color:#000;stop-opacity:1;"); + repr->appendChild(stop); + Inkscape::GC::release(stop); - Inkscape::XML::Node *repr = xml_doc->createElement("svg:linearGradient"); - repr->setAttribute("osb:paint", "solid"); - Inkscape::XML::Node *stop = xml_doc->createElement("svg:stop"); - stop->setAttribute("offset", "0"); - stop->setAttribute("style", "stop-color:#000;stop-opacity:1;"); - repr->appendChild(stop); - Inkscape::GC::release(stop); - - SP_OBJECT_REPR( SP_DOCUMENT_DEFS(doc) )->addChild(repr, NULL); - - SPGradient * gr = static_cast(doc->getObjectByRepr(repr)); + SP_OBJECT_REPR( SP_DOCUMENT_DEFS(doc) )->addChild(repr, NULL); - Inkscape::GC::release(repr); + gr = static_cast(doc->getObjectByRepr(repr)); + Inkscape::GC::release(repr); + } + gr->setSwatch(); editGradientImpl( gr ); } @@ -182,12 +184,9 @@ void SwatchesPanelHook::convertGradient( GtkMenuItem * /*menuitem*/, gpointer us for (const GSList *item = gradients; item; item = item->next) { SPGradient* grad = SP_GRADIENT(item->data); if ( targetName == grad->getId() ) { - grad->repr->setAttribute("osb:paint", "solid"); // TODO make conditional - + grad->setSwatch(); sp_document_done(doc, SP_VERB_CONTEXT_GRADIENT, _("Add gradient stop")); - - handleGradientsChange(doc); // work-around for signal not being emitted break; } } @@ -253,7 +252,7 @@ gboolean colorItemHandleButtonPress( GtkWidget* widget, GdkEventButton* event, g child = gtk_menu_item_new_with_label(_("Add")); g_signal_connect( G_OBJECT(child), "activate", - G_CALLBACK(addNewGradient), + G_CALLBACK(SwatchesPanelHook::addNewGradient), user_data ); gtk_menu_shell_append(GTK_MENU_SHELL(popupMenu), child); popupExtras.push_back(child); @@ -887,21 +886,25 @@ void SwatchesPanel::handleDefsModified(SPDocument *document) std::map tmpGrads; recalcSwatchContents(document, tmpColors, tmpPrevs, tmpGrads); - int cap = std::min(docPalette->_colors.size(), tmpColors.size()); - for (int i = 0; i < cap; i++) { - ColorItem* newColor = tmpColors[i]; - ColorItem* oldColor = docPalette->_colors[i]; - if ( (newColor->def.getType() != oldColor->def.getType()) || - (newColor->def.getR() != oldColor->def.getR()) || - (newColor->def.getG() != oldColor->def.getG()) || - (newColor->def.getB() != oldColor->def.getB()) ) { - oldColor->def.setRGB(newColor->def.getR(), newColor->def.getG(), newColor->def.getB()); - } - if (tmpGrads.find(newColor) != tmpGrads.end()) { - oldColor->setGradient(tmpGrads[newColor]); - } - if ( tmpPrevs.find(newColor) != tmpPrevs.end() ) { - oldColor->setPixData(tmpPrevs[newColor], PREVIEW_PIXBUF_WIDTH, VBLOCK); + if ( tmpColors.size() != docPalette->_colors.size() ) { + handleGradientsChange(document); + } else { + int cap = std::min(docPalette->_colors.size(), tmpColors.size()); + for (int i = 0; i < cap; i++) { + ColorItem* newColor = tmpColors[i]; + ColorItem* oldColor = docPalette->_colors[i]; + if ( (newColor->def.getType() != oldColor->def.getType()) || + (newColor->def.getR() != oldColor->def.getR()) || + (newColor->def.getG() != oldColor->def.getG()) || + (newColor->def.getB() != oldColor->def.getB()) ) { + oldColor->def.setRGB(newColor->def.getR(), newColor->def.getG(), newColor->def.getB()); + } + if (tmpGrads.find(newColor) != tmpGrads.end()) { + oldColor->setGradient(tmpGrads[newColor]); + } + if ( tmpPrevs.find(newColor) != tmpPrevs.end() ) { + oldColor->setPixData(tmpPrevs[newColor], PREVIEW_PIXBUF_WIDTH, VBLOCK); + } } } } diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index 5a7256d83..f1342f3de 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -556,8 +556,12 @@ void FillNStroke::updateFromPaint() } if (!vector) { + SPGradient *gr = sp_gradient_vector_for_object(document, desktop, SP_OBJECT(i->data), kind == FILL); + if ( gr && (psel->mode == SPPaintSelector::MODE_SWATCH) ) { + gr->setSwatch(); + } sp_item_set_gradient(SP_ITEM(i->data), - sp_gradient_vector_for_object(document, desktop, SP_OBJECT(i->data), kind == FILL), + gr, gradient_type, kind == FILL); } else { sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, kind == FILL); diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp index 8759854a0..a569d00bb 100644 --- a/src/widgets/paint-selector.cpp +++ b/src/widgets/paint-selector.cpp @@ -1102,6 +1102,7 @@ static void sp_paint_selector_set_mode_swatch(SPPaintSelector *psel, SPPaintSele gtk_frame_set_label(GTK_FRAME(psel->frame), _("Swatch fill")); } + #ifdef SP_PS_VERBOSE g_print("Swatch req\n"); #endif -- 2.30.2