From 348f08f93801f357b80cb5d3ad7c5b38dc8c4e53 Mon Sep 17 00:00:00 2001 From: nicholasbishop Date: Sat, 28 Jul 2007 08:51:54 +0000 Subject: [PATCH] Filter effects dialog: * Added settings for feDiffuseLighting. * Added color buttons for feDiffuseLighting and feSpecularLighting. --- src/ui/dialog/filter-effects-dialog.cpp | 68 +++++++++++++++++++------ src/ui/dialog/filter-effects-dialog.h | 2 - 2 files changed, 52 insertions(+), 18 deletions(-) diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index bd834608e..119dda377 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -40,6 +41,7 @@ #include "sp-gaussian-blur.h" #include "sp-feoffset.h" #include "style.h" +#include "svg/svg-color.h" #include "verbs.h" #include "xml/node.h" #include "xml/repr.h" @@ -53,6 +55,41 @@ namespace Inkscape { namespace UI { namespace Dialog { +class ColorButton : public Gtk::ColorButton, public AttrWidget +{ +public: + ColorButton(const SPAttributeEnum a) + : AttrWidget(a) + { + Gdk::Color col; + col.set_rgb(65535, 65535, 65535); + set_color(col); + } + + // Returns the color in 'rgb(r,g,b)' form. + Glib::ustring get_as_attribute() const + { + std::ostringstream os; + const Gdk::Color c = get_color(); + const int r = (c.get_red() + 1) / 256 - 1, g = (c.get_green() + 1) / 256 - 1, b = (c.get_blue() + 1) / 256 - 1; + os << "rgb(" << r << "," << g << "," << b << ")"; + return os.str(); + } + + + void set_from_attribute(SPObject* o) + { + const gchar* val = attribute_value(o); + if(val) { + const guint32 i = sp_svg_read_color(val, 0xFFFFFFFF); + const int r = SP_RGBA32_R_U(i) + 1, g = SP_RGBA32_G_U(i) + 1, b = SP_RGBA32_B_U(i) + 1; + Gdk::Color col; + col.set_rgb(r * 256 - 1, g * 256 - 1, b * 256 - 1); + set_color(col); + } + } +}; + /* Displays/Edits the kernel matrix for feConvolveMatrix */ class FilterEffectsDialog::ConvolveMatrix : public Gtk::TreeView, public AttrWidget { @@ -189,11 +226,14 @@ public: _current_type = t; } - void add(Gtk::ColorButton& cb, const SPAttributeEnum attr, const Glib::ustring& label) + ColorButton* add_color(const SPAttributeEnum attr, const Glib::ustring& label) { - //generic_add(cb, label); - //cb.signal_color_set().connect( - // sigc::bind(sigc::mem_fun(_dialog, &FilterEffectsDialog::set_attr_color), attr, &cb)); + ColorButton* col = new ColorButton(attr); + add_widget(*col, label); + _attrwidgets[_current_type].push_back(col); + col->signal_color_set().connect( + sigc::bind(sigc::mem_fun(_dialog, &FilterEffectsDialog::set_attr_direct), attr, col)); + return col; } // ConvolveMatrix @@ -1183,6 +1223,12 @@ void FilterEffectsDialog::init_settings_widgets() _convolve_order->signal_value_changed().connect(sigc::mem_fun(*this, &FilterEffectsDialog::convolve_order_changed)); _settings->add(SP_ATTR_DIVISOR, _("Divisor"), 0.01, 10, 1, 0.01, 1); _settings->add(SP_ATTR_BIAS, _("Bias"), -10, 10, 1, 0.01, 1); + + _settings->type(NR_FILTER_DIFFUSELIGHTING); + _settings->add_color(SP_PROP_LIGHTING_COLOR, _("Diffuse Color")); + _settings->add(SP_ATTR_SURFACESCALE, _("Surface Scale"), -10, 10, 1, 0.01, 1); + _settings->add(SP_ATTR_DIFFUSECONSTANT, _("Constant"), 0, 100, 1, 0.01, 1); + _settings->add(SP_ATTR_KERNELUNITLENGTH, _("Kernel Unit Length X"), _("Kernel Unit Length Y"), 0.01, 10, 1, 0.01, 1); _settings->type(NR_FILTER_GAUSSIANBLUR); _settings->add(SP_ATTR_STDDEVIATION, _("Standard Deviation X"), _("Standard Deviation Y"), 0.01, 100, 1, 0.01, 1); @@ -1192,10 +1238,11 @@ void FilterEffectsDialog::init_settings_widgets() _settings->add(SP_ATTR_DY, _("Delta Y"), -100, 100, 1, 0.01, 1); _settings->type(NR_FILTER_SPECULARLIGHTING); - //_settings->add(_specular_color, SP_PROP_LIGHTING_COLOR, _("Specular Color")); + _settings->add_color(SP_PROP_LIGHTING_COLOR, _("Specular Color")); _settings->add(SP_ATTR_SURFACESCALE, _("Surface Scale"), -10, 10, 1, 0.01, 1); _settings->add(SP_ATTR_SPECULARCONSTANT, _("Constant"), 0, 100, 1, 0.01, 1); _settings->add(SP_ATTR_SPECULAREXPONENT, _("Exponent"), 1, 128, 1, 0.01, 1); + _settings->add(SP_ATTR_KERNELUNITLENGTH, _("Kernel Unit Length X"), _("Kernel Unit Length Y"), 0.01, 10, 1, 0.01, 1); _settings->type(NR_FILTER_TURBULENCE); /*std::vector trb_grp; @@ -1259,17 +1306,6 @@ void FilterEffectsDialog::convolve_order_changed() _convolve_ty->get_adjustment().set_upper(_convolve_order->get_spinslider2().get_value()); } -void FilterEffectsDialog::set_attr_color(const SPAttributeEnum attr, const Gtk::ColorButton* input) -{ - if(input->is_sensitive()) { - std::ostringstream os; - const Gdk::Color c = input->get_color(); - const int r = 255 * c.get_red() / 65535, g = 255 * c.get_green() / 65535, b = 255 * c.get_blue() / 65535; - os << "rgb(" << r << "," << g << "," << b << ")"; - set_attr(attr, os.str().c_str()); - } -} - void FilterEffectsDialog::set_attr_direct(const SPAttributeEnum attr, const AttrWidget* input) { set_attr(attr, input->get_as_attribute().c_str()); diff --git a/src/ui/dialog/filter-effects-dialog.h b/src/ui/dialog/filter-effects-dialog.h index 9e9a02f47..b80ab7686 100644 --- a/src/ui/dialog/filter-effects-dialog.h +++ b/src/ui/dialog/filter-effects-dialog.h @@ -17,7 +17,6 @@ #include #include #include -#include "gtkmm/colorbutton.h" #include #include #include @@ -175,7 +174,6 @@ private: void duplicate_primitive(); void convolve_order_changed(); - void set_attr_color(const SPAttributeEnum attr, const Gtk::ColorButton*); void set_attr_direct(const SPAttributeEnum attr, const AttrWidget*); void set_attr_special(const SPAttributeEnum); void set_attr(const SPAttributeEnum, const gchar* val); -- 2.30.2