From: Jon A. Cruz Date: Wed, 7 Jul 2010 05:03:34 +0000 (-0700) Subject: Tuning fill-n-stroke to support non-solid swatches. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4a1822d1f7f3d9a9b165ed8091a94ac3da830403;p=inkscape.git Tuning fill-n-stroke to support non-solid swatches. --- diff --git a/src/widgets/gradient-selector.cpp b/src/widgets/gradient-selector.cpp index 77defa5c9..5b663c493 100644 --- a/src/widgets/gradient-selector.cpp +++ b/src/widgets/gradient-selector.cpp @@ -117,10 +117,10 @@ sp_gradient_selector_class_init (SPGradientSelectorClass *klass) object_class->destroy = sp_gradient_selector_destroy; } -static void -sp_gradient_selector_init (SPGradientSelector *sel) +static void sp_gradient_selector_init(SPGradientSelector *sel) { - GtkWidget *hb, *m, *mi; + sel->safelyInit = true; + new (&sel->nonsolid) std::vector(); sel->mode = SPGradientSelector::MODE_LINEAR; @@ -134,39 +134,44 @@ sp_gradient_selector_init (SPGradientSelector *sel) g_signal_connect (G_OBJECT (sel->vectors), "vector_set", G_CALLBACK (sp_gradient_selector_vector_set), sel); /* Create box for buttons */ - hb = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (sel), hb, FALSE, FALSE, 0); + GtkWidget *hb = gtk_hbox_new( FALSE, 0 ); + sel->nonsolid.push_back(hb); + gtk_box_pack_start( GTK_BOX(sel), hb, FALSE, FALSE, 0 ); GtkTooltips *ttips = gtk_tooltips_new (); sel->add = gtk_button_new_with_label (_("Duplicate")); + sel->nonsolid.push_back(sel->add); gtk_box_pack_start (GTK_BOX (hb), sel->add, TRUE, TRUE, 0); g_signal_connect (G_OBJECT (sel->add), "clicked", G_CALLBACK (sp_gradient_selector_add_vector_clicked), sel); gtk_widget_set_sensitive (sel->add, FALSE); sel->edit = gtk_button_new_with_label (_("Edit...")); + sel->nonsolid.push_back(sel->edit); gtk_box_pack_start (GTK_BOX (hb), sel->edit, TRUE, TRUE, 0); g_signal_connect (G_OBJECT (sel->edit), "clicked", G_CALLBACK (sp_gradient_selector_edit_vector_clicked), sel); gtk_widget_set_sensitive (sel->edit, FALSE); - gtk_widget_show_all (hb); + gtk_widget_show_all(hb); /* Spread selector */ - hb = gtk_hbox_new (FALSE, 0); - gtk_widget_show (hb); - gtk_box_pack_start (GTK_BOX (sel), hb, FALSE, FALSE, 0); - - sel->spread = gtk_option_menu_new (); - gtk_widget_show (sel->spread); - gtk_box_pack_end (GTK_BOX (hb), sel->spread, FALSE, FALSE, 0); - gtk_tooltips_set_tip (ttips, sel->spread, + hb = gtk_hbox_new( FALSE, 0 ); + sel->nonsolid.push_back(hb); + gtk_widget_show(hb); + gtk_box_pack_start( GTK_BOX(sel), hb, FALSE, FALSE, 0 ); + + sel->spread = gtk_option_menu_new(); + sel->nonsolid.push_back(sel->spread); + gtk_widget_show(sel->spread); + gtk_box_pack_end( GTK_BOX(hb), sel->spread, FALSE, FALSE, 0 ); + gtk_tooltips_set_tip( ttips, sel->spread, // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/pservers.html#LinearGradientSpreadMethodAttribute _("Whether to fill with flat color beyond the ends of the gradient vector " "(spreadMethod=\"pad\"), or repeat the gradient in the same direction " "(spreadMethod=\"repeat\"), or repeat the gradient in alternating opposite " "directions (spreadMethod=\"reflect\")"), NULL); - m = gtk_menu_new (); - mi = gtk_menu_item_new_with_label (_("none")); + GtkWidget *m = gtk_menu_new(); + GtkWidget *mi = gtk_menu_item_new_with_label(_("none")); gtk_menu_append (GTK_MENU (m), mi); g_object_set_data (G_OBJECT (mi), "gradientSpread", GUINT_TO_POINTER (SP_GRADIENT_SPREAD_PAD)); g_signal_connect (G_OBJECT (mi), "activate", G_CALLBACK (sp_gradient_selector_spread_activate), sel); @@ -180,22 +185,27 @@ sp_gradient_selector_init (SPGradientSelector *sel) gtk_menu_append (GTK_MENU (m), mi); gtk_widget_show_all (m); - gtk_option_menu_set_menu (GTK_OPTION_MENU (sel->spread), m); + gtk_option_menu_set_menu( GTK_OPTION_MENU(sel->spread), m ); - sel->spreadLbl = gtk_label_new (_("Repeat:")); - gtk_widget_show(sel->spreadLbl); - gtk_box_pack_end(GTK_BOX(hb), sel->spreadLbl, FALSE, FALSE, 4); + sel->spreadLbl = gtk_label_new( _("Repeat:") ); + sel->nonsolid.push_back(sel->spreadLbl); + gtk_widget_show( sel->spreadLbl ); + gtk_box_pack_end( GTK_BOX(hb), sel->spreadLbl, FALSE, FALSE, 4 ); } -static void -sp_gradient_selector_destroy (GtkObject *object) +static void sp_gradient_selector_destroy(GtkObject *object) { - SPGradientSelector *sel; + SPGradientSelector *sel = SP_GRADIENT_SELECTOR( object ); - sel = SP_GRADIENT_SELECTOR (object); + if ( sel->safelyInit ) { + sel->safelyInit = false; + using std::vector; + sel->nonsolid.~vector(); + } - if (((GtkObjectClass *) (parent_class))->destroy) + if (((GtkObjectClass *) (parent_class))->destroy) { (* ((GtkObjectClass *) (parent_class))->destroy) (object); + } } GtkWidget * @@ -208,26 +218,15 @@ sp_gradient_selector_new (void) return (GtkWidget *) sel; } -static void removeWidget( GtkWidget *& widget ) -{ - if (widget) { - GtkWidget *parent = gtk_widget_get_parent(widget); - if (parent) { - gtk_container_remove(GTK_CONTAINER(parent), widget); - widget = 0; - } - } -} - void SPGradientSelector::setMode(SelectorMode mode) { if (mode != this->mode) { this->mode = mode; if (mode == MODE_SWATCH) { - removeWidget(add); - removeWidget(edit); - removeWidget(spread); - removeWidget(spreadLbl); + for (std::vector::iterator it = nonsolid.begin(); it != nonsolid.end(); ++it) + { + gtk_widget_hide(*it); + } SPGradientVectorSelector* vs = SP_GRADIENT_VECTOR_SELECTOR(vectors); vs->setSwatched(); @@ -269,6 +268,20 @@ void SPGradientSelector::setVector(SPDocument *doc, SPGradient *vector) sp_gradient_vector_selector_set_gradient(SP_GRADIENT_VECTOR_SELECTOR(vectors), doc, vector); if (vector) { + if ( (mode == MODE_SWATCH) && vector->isSwatch() ) { + if ( vector->isSolid() ) { + for (std::vector::iterator it = nonsolid.begin(); it != nonsolid.end(); ++it) + { + gtk_widget_hide(*it); + } + } else { + for (std::vector::iterator it = nonsolid.begin(); it != nonsolid.end(); ++it) + { + gtk_widget_show_all(*it); + } + } + } + if (edit) { gtk_widget_set_sensitive(edit, TRUE); } diff --git a/src/widgets/gradient-selector.h b/src/widgets/gradient-selector.h index 25f561a6e..860804ec6 100644 --- a/src/widgets/gradient-selector.h +++ b/src/widgets/gradient-selector.h @@ -17,6 +17,7 @@ #include #include +#include #include "sp-gradient.h" #include "sp-gradient-spread.h" #include "sp-gradient-units.h" @@ -59,6 +60,9 @@ struct SPGradientSelector { GtkWidget *spread; GtkWidget *spreadLbl; + bool safelyInit; + std::vector nonsolid; + void setMode(SelectorMode mode); void setUnits(SPGradientUnits units); void setSpread(SPGradientSpread spread); diff --git a/src/widgets/gradient-vector.cpp b/src/widgets/gradient-vector.cpp index 454c12001..c49d9e06f 100644 --- a/src/widgets/gradient-vector.cpp +++ b/src/widgets/gradient-vector.cpp @@ -174,6 +174,10 @@ GtkWidget *sp_gradient_vector_selector_new(SPDocument *doc, SPGradient *gr) void sp_gradient_vector_selector_set_gradient(SPGradientVectorSelector *gvs, SPDocument *doc, SPGradient *gr) { +// g_message("sp_gradient_vector_selector_set_gradient(%p, %p, %p) [%s] %d %d", gvs, doc, gr, +// (gr ? gr->getId():"N/A"), +// (gr ? gr->isSwatch() : -1), +// (gr ? gr->isSolid() : -1)); static gboolean suppress = FALSE; g_return_if_fail(gvs != NULL); @@ -337,6 +341,7 @@ static void sp_gvs_gradient_activate(GtkMenuItem *mi, SPGradientVectorSelector * /* Hmmm - probably we can just re-set it as menuitem data (Lauris) */ //g_print("SPGradientVectorSelector: gradient %s activated\n", SP_OBJECT_ID(gr)); + //g_message("Setting to gradient %p swatch:%d solid:%d", gr, gr->isSwatch(), gr->isSolid()); norm = sp_gradient_ensure_vector_normalized(gr); if (norm != gr) { diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp index a569d00bb..cf6a04a3c 100644 --- a/src/widgets/paint-selector.cpp +++ b/src/widgets/paint-selector.cpp @@ -1082,11 +1082,10 @@ static void sp_paint_selector_set_mode_swatch(SPPaintSelector *psel, SPPaintSele SwatchSelector *swatchsel = 0; if (psel->mode == SPPaintSelector::MODE_SWATCH){ - /* Already have pattern menu */ swatchsel = static_cast(g_object_get_data(G_OBJECT(psel->selector), "swatch-selector")); } else { sp_paint_selector_clear_frame(psel); - /* Create new gradient selector */ + // Create new gradient selector SwatchSelector *swatchsel = new SwatchSelector(); swatchsel->show(); diff --git a/src/widgets/swatch-selector.cpp b/src/widgets/swatch-selector.cpp index ce0f8a810..88abca358 100644 --- a/src/widgets/swatch-selector.cpp +++ b/src/widgets/swatch-selector.cpp @@ -169,10 +169,9 @@ void SwatchSelector::connectchangedHandler( GCallback handler, void *data ) void SwatchSelector::setVector(SPDocument */*doc*/, SPGradient *vector) { //GtkVBox * box = gobj(); - _gsel->setVector((vector) ? SP_OBJECT_DOCUMENT(vector) : 0, vector); - if (vector) { + if ( vector && vector->isSolid() ) { SPStop* stop = vector->getFirstStop(); guint32 const colorVal = sp_stop_get_rgba32(stop); @@ -180,6 +179,9 @@ void SwatchSelector::setVector(SPDocument */*doc*/, SPGradient *vector) SPColor color( SP_RGBA32_R_F(colorVal), SP_RGBA32_G_F(colorVal), SP_RGBA32_B_F(colorVal) ); // set its color, from the stored array _csel->base->setColor( color ); + gtk_widget_show_all( GTK_WIDGET(_csel) ); + } else { + gtk_widget_hide( GTK_WIDGET(_csel) ); } /*