From 94d7884e56192ef3d558038ccced5c74a24a8174 Mon Sep 17 00:00:00 2001 From: buliabyak Date: Wed, 4 Oct 2006 21:36:10 +0000 Subject: [PATCH] simplify style-querying for blur radius; move Blur slider above Opacity, cleanup --- src/desktop-style.cpp | 32 +++++------- src/dialogs/object-properties.cpp | 82 ++++++++++++++----------------- 2 files changed, 49 insertions(+), 65 deletions(-) diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index 66953aae7..7dbbfd5e8 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -1026,12 +1026,15 @@ objects_query_blur (GSList *objects, SPStyle *style_res) float blur_prev = -1; bool same_blur = true; guint blur_items = 0; + guint items = 0; for (GSList const *i = objects; i != NULL; i = i->next) { SPObject *obj = SP_OBJECT (i->data); SPStyle *style = SP_OBJECT_STYLE (obj); if (!style) continue; + items ++; + //if object has a filter if (style->filter.set && style->filter.filter) { //cycle through filter primitives @@ -1039,8 +1042,7 @@ objects_query_blur (GSList *objects, SPStyle *style_res) { SPFilterPrimitive *primitive = style->filter.filter->_primitives[i]; //if primitive is gaussianblur - // if(SP_IS_GAUSSIANBLUR(primitive)) - { + if(SP_IS_GAUSSIANBLUR(primitive)) { SPGaussianBlur * spblur = SP_GAUSSIANBLUR(primitive); float num = spblur->stdDeviation.getNumber(); blur_sum += num; @@ -1054,28 +1056,16 @@ objects_query_blur (GSList *objects, SPStyle *style_res) } } - if (blur_items > 0) - { - blur_sum /= blur_items; - style_res->filter.set = true; - style_res->filter.filter = new SPFilter(); - //TODO: this SPFilter attributes should be set on sp-filter.cpp - // when a new SPFilter is created, not here - style_res->filter.filter->_primitive_count=0; - style_res->filter.filter->_primitive_table_size = 1; - style_res->filter.filter->_primitives = new SPFilterPrimitive*[1]; - style_res->filter.filter->_primitives[0] = NULL; - - SPGaussianBlur * b = new SPGaussianBlur(); - add_primitive(style_res->filter.filter, b); - sp_gaussianBlur_setDeviation(b, blur_sum); - } - + if (items > 0) { + if (blur_items > 0) + blur_sum /= blur_items; + style_res->filter_gaussianBlur_deviation.value = blur_sum; + } - if (blur_items == 0) { + if (items == 0) { return QUERY_STYLE_NOTHING; - } else if (blur_items == 1) { + } else if (items == 1) { return QUERY_STYLE_SINGLE; } else { if (same_blur) diff --git a/src/dialogs/object-properties.cpp b/src/dialogs/object-properties.cpp index 20efc8408..f1f8ed602 100644 --- a/src/dialogs/object-properties.cpp +++ b/src/dialogs/object-properties.cpp @@ -13,9 +13,7 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -//uncomment to display blur slider -#define WITH_BLUR - + #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -183,6 +181,39 @@ sp_object_properties_dialog (void) INKSCAPE_STOCK_PROPERTIES_STROKE_PAGE); } + + /* Blur */ + GtkWidget *b_vb = gtk_vbox_new (FALSE, 0); + gtk_box_pack_start (GTK_BOX (vb), b_vb, FALSE, FALSE, 2); + gtk_object_set_data (GTK_OBJECT (dlg), "blur", b_vb); + + GtkWidget *blur_l_hb = gtk_hbox_new (FALSE, 4); + GtkWidget *blur_l = gtk_label_new_with_mnemonic (_("_Blur")); + gtk_misc_set_alignment (GTK_MISC (blur_l), 0.0, 1.0); + gtk_box_pack_start (GTK_BOX (blur_l_hb), blur_l, FALSE, FALSE, 4); + gtk_box_pack_start (GTK_BOX (b_vb), blur_l_hb, FALSE, FALSE, 0); + + GtkWidget *blur_hb = gtk_hbox_new (FALSE, 4); + gtk_box_pack_start (GTK_BOX (b_vb), blur_hb, FALSE, FALSE, 0); + + GtkObject *blur_a = gtk_adjustment_new (0.0, 0.0, 100.0, 1.0, 1.0, 0.0); + gtk_object_set_data(GTK_OBJECT(dlg), "blur_adjustment", blur_a); + + GtkWidget *blur_s = gtk_hscale_new (GTK_ADJUSTMENT (blur_a)); + gtk_scale_set_draw_value (GTK_SCALE (blur_s), FALSE); + gtk_box_pack_start (GTK_BOX (blur_hb), blur_s, TRUE, TRUE, 4); + gtk_label_set_mnemonic_widget (GTK_LABEL(blur_l), blur_s); + + GtkWidget *blur_sb = gtk_spin_button_new (GTK_ADJUSTMENT (blur_a), 0.01, 3); + gtk_box_pack_start (GTK_BOX (blur_hb), blur_sb, FALSE, FALSE, 0); + + gtk_signal_connect ( blur_a, "value_changed", + GTK_SIGNAL_FUNC (sp_fillstroke_blur_changed), + dlg ); + + gtk_widget_show_all (b_vb); + + /* Opacity */ GtkWidget *o_vb = gtk_vbox_new (FALSE, 0); @@ -220,39 +251,6 @@ sp_object_properties_dialog (void) g_signal_connect ( G_OBJECT (INKSCAPE), "modify_selection", G_CALLBACK (sp_fillstroke_selection_modified), dlg ); g_signal_connect ( G_OBJECT (INKSCAPE), "activate_desktop", G_CALLBACK (sp_fillstroke_selection_changed), dlg ); - -#ifdef WITH_BLUR - /* Blur */ - GtkWidget *b_vb = gtk_vbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vb), b_vb, FALSE, FALSE, 2); - gtk_object_set_data (GTK_OBJECT (dlg), "blur", b_vb); - - GtkWidget *blur_l_hb = gtk_hbox_new (FALSE, 4); - GtkWidget *blur_l = gtk_label_new_with_mnemonic (_("_Blur")); - gtk_misc_set_alignment (GTK_MISC (blur_l), 0.0, 1.0); - gtk_box_pack_start (GTK_BOX (blur_l_hb), blur_l, FALSE, FALSE, 4); - gtk_box_pack_start (GTK_BOX (b_vb), blur_l_hb, FALSE, FALSE, 0); - - GtkWidget *blur_hb = gtk_hbox_new (FALSE, 4); - gtk_box_pack_start (GTK_BOX (b_vb), blur_hb, FALSE, FALSE, 0); - - GtkObject *blur_a = gtk_adjustment_new (0.0, 0.0, 100.0, 1.0, 1.0, 0.0); - gtk_object_set_data(GTK_OBJECT(dlg), "blur_adjustment", blur_a); - - GtkWidget *blur_s = gtk_hscale_new (GTK_ADJUSTMENT (blur_a)); - gtk_scale_set_draw_value (GTK_SCALE (blur_s), FALSE); - gtk_box_pack_start (GTK_BOX (blur_hb), blur_s, TRUE, TRUE, 4); - gtk_label_set_mnemonic_widget (GTK_LABEL(blur_l), blur_s); - - GtkWidget *blur_sb = gtk_spin_button_new (GTK_ADJUSTMENT (blur_a), 1.0, 3); - gtk_box_pack_start (GTK_BOX (blur_hb), blur_sb, FALSE, FALSE, 0); - - gtk_signal_connect ( blur_a, "value_changed", - GTK_SIGNAL_FUNC (sp_fillstroke_blur_changed), - dlg ); - - gtk_widget_show_all (b_vb); -#endif sp_fillstroke_selection_changed(NULL, NULL, NULL); gtk_widget_show (dlg); @@ -329,26 +327,22 @@ sp_fillstroke_selection_changed ( Inkscape::Application *inkscape, GtkWidget *b = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (dlg), "blur")); GtkAdjustment *bluradjustment = GTK_ADJUSTMENT(gtk_object_get_data(GTK_OBJECT(dlg), "blur_adjustment")); -#ifdef WITH_BLUR //query now for current average blurring of selection int blur_result = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_BLUR); - switch (blur_result) { case QUERY_STYLE_NOTHING: //no blurring -// gtk_widget_set_sensitive (b, FALSE); + gtk_widget_set_sensitive (b, FALSE); break; case QUERY_STYLE_SINGLE: case QUERY_STYLE_MULTIPLE_AVERAGED: case QUERY_STYLE_MULTIPLE_SAME: gtk_widget_set_sensitive (b, TRUE); //update blur widget value - SPGaussianBlur * spblur = SP_GAUSSIANBLUR(query->filter.filter->_primitives[0]); - gtk_adjustment_set_value(bluradjustment, spblur->stdDeviation.getNumber()); + float radius = query->filter_gaussianBlur_deviation.value; + // TODO: divide by bbox diagonal + gtk_adjustment_set_value(bluradjustment, radius); break; } -#endif - - g_free (query); -- 2.30.2