Code

Added my name to the list of authors
[inkscape.git] / src / ui / dialog / filter-effects-dialog.cpp
index f3fa074d54e21fb4ce587768db6a0dc398b9d136..edcb1e9ca653ad501c4c0dc4f76ad75a9a921e9a 100644 (file)
@@ -35,7 +35,9 @@
 #include "inkscape.h"
 #include "selection.h"
 #include "sp-feblend.h"
+#include "sp-fecolormatrix.h"
 #include "sp-fecomposite.h"
+#include "sp-feconvolvematrix.h"
 #include "sp-fedisplacementmap.h"
 #include "sp-fedistantlight.h"
 #include "sp-femerge.h"
@@ -264,18 +266,19 @@ public:
     }
 };
 
-/* Displays/Edits the kernel matrix for feConvolveMatrix */
-class FilterEffectsDialog::ConvolveMatrix : public Gtk::TreeView, public AttrWidget
+/* Displays/Edits the matrix for feConvolveMatrix or feColorMatrix */
+class FilterEffectsDialog::MatrixAttr : public Gtk::Frame, public AttrWidget
 {
 public:
-    ConvolveMatrix(const SPAttributeEnum a)
+    MatrixAttr(const SPAttributeEnum a)
         : AttrWidget(a)
     {
-        signal_changed().connect(signal_attr_changed().make_slot());
-
         _model = Gtk::ListStore::create(_columns);
-        set_model(_model);
-        set_headers_visible(false);
+        _tree.set_model(_model);
+        _tree.set_headers_visible(false);
+        _tree.show();
+        add(_tree);
+        set_shadow_type(Gtk::SHADOW_IN);
     }
 
     Glib::ustring get_as_attribute() const
@@ -284,7 +287,7 @@ public:
         
         for(Gtk::TreeIter iter = _model->children().begin();
             iter != _model->children().end(); ++iter) {
-            for(unsigned c = 0; c < get_columns().size(); ++c) {
+            for(unsigned c = 0; c < _tree.get_columns().size(); ++c) {
                 os << (*iter)[_columns.cols[c]] << " ";
             }
         }
@@ -294,32 +297,25 @@ public:
     
     void set_from_attribute(SPObject* o)
     {
-        update(SP_FECONVOLVEMATRIX(o));
-    }
-
-    sigc::signal<void>& signal_changed()
-    {
-        return _signal_changed;
-    }
-
-    void update(SPFeConvolveMatrix* conv)
-    {
-        if(conv) {
-            int cols, rows;
-
-            cols = (int)conv->order.getNumber();
-            if(cols > 5)
-                cols = 5;
-            rows = conv->order.optNumber_set ? (int)conv->order.getOptNumber() : cols;
-
-            update(conv, cols, rows);
+        if(o) {
+            if(SP_IS_FECONVOLVEMATRIX(o)) {
+                SPFeConvolveMatrix* conv = SP_FECONVOLVEMATRIX(o);
+                int cols, rows;
+                cols = (int)conv->order.getNumber();
+                if(cols > 5)
+                    cols = 5;
+                rows = conv->order.optNumber_set ? (int)conv->order.getOptNumber() : cols;
+                update(o, rows, cols);
+            }
+            else if(SP_IS_FECOLORMATRIX(o))
+                update(o, 4, 5);
         }
     }
 private:
-    class ConvolveMatrixColumns : public Gtk::TreeModel::ColumnRecord
+    class MatrixColumns : public Gtk::TreeModel::ColumnRecord
     {
     public:
-        ConvolveMatrixColumns()
+        MatrixColumns()
         {
             cols.resize(5);
             for(unsigned i = 0; i < cols.size(); ++i)
@@ -328,37 +324,112 @@ private:
         std::vector<Gtk::TreeModelColumn<double> > cols;
     };
 
-    void update(SPFeConvolveMatrix* conv, const int rows, const int cols)
+    void update(SPObject* o, const int rows, const int cols)
     {
         _model->clear();
 
-        remove_all_columns();
+        _tree.remove_all_columns();
 
-        if(conv) {
+        SPFeColorMatrix* col = 0;
+        SPFeConvolveMatrix* conv = 0;
+        if(SP_IS_FECOLORMATRIX(o))
+            col = SP_FECOLORMATRIX(o);
+        else if(SP_IS_FECONVOLVEMATRIX(o))
+            conv = SP_FECONVOLVEMATRIX(o);
+        else
+            return;
+
+        if(o) {
             int ndx = 0;
 
             for(int i = 0; i < cols; ++i) {
-                append_column_numeric_editable("", _columns.cols[i], "%.2f");
-                dynamic_cast<Gtk::CellRendererText*>(get_column(i)->get_first_cell_renderer())->signal_edited().connect(
-                    sigc::mem_fun(*this, &ConvolveMatrix::rebind));
+                _tree.append_column_numeric_editable("", _columns.cols[i], "%.2f");
+                dynamic_cast<Gtk::CellRendererText*>(_tree.get_column(i)->get_first_cell_renderer())->signal_edited().connect(
+                    sigc::mem_fun(*this, &MatrixAttr::rebind));
             }
 
             for(int r = 0; r < rows; ++r) {
                 Gtk::TreeRow row = *(_model->append());
-                for(int c = 0; c < cols; ++c, ++ndx)
-                    row[_columns.cols[c]] = ndx < (int)conv->kernelMatrix.size() ? conv->kernelMatrix[ndx] : 0;
+                for(int c = 0; c < cols; ++c, ++ndx) {
+                    if(col)
+                        row[_columns.cols[c]] = ndx < (int)col->values.size() ? col->values[ndx] : 0;
+                    else
+                        row[_columns.cols[c]] = ndx < (int)conv->kernelMatrix.size() ? conv->kernelMatrix[ndx] : 0;
+                }
             }
         }
     }
 
     void rebind(const Glib::ustring&, const Glib::ustring&)
     {
-        _signal_changed();
+        signal_attr_changed()();
     }
 
+    Gtk::TreeView _tree;
     Glib::RefPtr<Gtk::ListStore> _model;
-    ConvolveMatrixColumns _columns;
-    sigc::signal<void> _signal_changed;
+    MatrixColumns _columns;
+};
+
+// Displays a matrix or a slider for feColorMatrix
+class FilterEffectsDialog::ColorMatrixValues : public Gtk::Frame, public AttrWidget
+{
+public:
+    ColorMatrixValues()
+        : AttrWidget(SP_ATTR_VALUES),
+          _matrix(SP_ATTR_VALUES),
+          _saturation(0, 0, 1, 0.1, 0.01, 2, SP_ATTR_VALUES),
+          _angle(0, 0, 360, 0.1, 0.01, 1, SP_ATTR_VALUES),
+          _label(_("None"), Gtk::ALIGN_LEFT)
+    {
+        _matrix.show();
+        _saturation.show();
+        _angle.show();
+
+        _label.set_sensitive(false);
+        _label.show();
+
+        set_shadow_type(Gtk::SHADOW_NONE);
+    }
+
+    virtual void set_from_attribute(SPObject* o)
+    {
+        if(SP_IS_FECOLORMATRIX(o)) {
+            SPFeColorMatrix* col = SP_FECOLORMATRIX(o);
+            remove();
+            switch(col->type) {
+                case COLORMATRIX_SATURATE:
+                    add(_saturation);
+                    _saturation.set_from_attribute(o);
+                    break;
+                case COLORMATRIX_HUEROTATE:
+                    add(_angle);
+                    _angle.set_from_attribute(o);
+                    break;
+                case COLORMATRIX_LUMINANCETOALPHA:
+                    add(_label);
+                    break;
+                case COLORMATRIX_MATRIX:
+                default:
+                    add(_matrix);
+                    _matrix.set_from_attribute(o);
+                    break;
+            }
+        }
+    }
+
+    virtual Glib::ustring get_as_attribute() const
+    {
+        const Widget* w = get_child();
+        if(w == &_label)
+            return "";
+        else
+            return dynamic_cast<const AttrWidget*>(w)->get_as_attribute();
+    }
+private:
+    MatrixAttr _matrix;
+    SpinSlider _saturation;
+    SpinSlider _angle;
+    Gtk::Label _label;
 };
 
 class FilterEffectsDialog::Settings
@@ -428,15 +499,24 @@ public:
         return col;
     }
 
-    // ConvolveMatrix
-    ConvolveMatrix* add_matrix(const SPAttributeEnum attr, const Glib::ustring& label)
+    // Matrix
+    MatrixAttr* add_matrix(const SPAttributeEnum attr, const Glib::ustring& label)
     {
-        ConvolveMatrix* conv = new ConvolveMatrix(attr);
+        MatrixAttr* conv = new MatrixAttr(attr);
         add_widget(conv, label);
         add_attr_widget(conv);
         return conv;
     }
 
+    // ColorMatrixValues
+    ColorMatrixValues* add_colormatrixvalues(const Glib::ustring& label)
+    {
+        ColorMatrixValues* cmv = new ColorMatrixValues;
+        add_widget(cmv, label);
+        add_attr_widget(cmv);
+        return cmv;
+    }
+
     // SpinSlider
     SpinSlider* add_spinslider(const SPAttributeEnum attr, const Glib::ustring& label,
                          const double lo, const double hi, const double step_inc, const double climb, const int digits)
@@ -1572,6 +1652,10 @@ void FilterEffectsDialog::init_settings_widgets()
     _settings->type(NR_FILTER_BLEND);
     _settings->add_combo(SP_ATTR_MODE, _("Mode"), BlendModeConverter);
 
+    _settings->type(NR_FILTER_COLORMATRIX);
+    _settings->add_combo(SP_ATTR_TYPE, _("Type"), ColorMatrixTypeConverter);
+    _settings->add_colormatrixvalues(_("Value(s)"));
+
     _settings->type(NR_FILTER_COMPOSITE);
     _settings->add_combo(SP_ATTR_OPERATOR, _("Operator"), CompositeOperatorConverter);
     _k1 = _settings->add_spinslider(SP_ATTR_K1, _("K1"), -10, 10, 1, 0.01, 1);
@@ -1586,6 +1670,7 @@ void FilterEffectsDialog::init_settings_widgets()
     _convolve_order->signal_attr_changed().connect(sigc::mem_fun(*this, &FilterEffectsDialog::convolve_order_changed));
     _settings->add_spinslider(SP_ATTR_DIVISOR, _("Divisor"), 0.01, 10, 1, 0.01, 1);
     _settings->add_spinslider(SP_ATTR_BIAS, _("Bias"), -10, 10, 1, 0.01, 1);
+    _settings->add_combo(SP_ATTR_EDGEMODE, _("Edge Mode"), ConvolveMatrixEdgeModeConverter);
 
     _settings->type(NR_FILTER_DIFFUSELIGHTING);
     _settings->add_color(SP_PROP_LIGHTING_COLOR, _("Diffuse Color"));
@@ -1593,6 +1678,11 @@ void FilterEffectsDialog::init_settings_widgets()
     _settings->add_spinslider(SP_ATTR_DIFFUSECONSTANT, _("Constant"), 0, 100, 1, 0.01, 1);
     _settings->add_dualspinslider(SP_ATTR_KERNELUNITLENGTH, _("Kernel Unit Length"), 0.01, 10, 1, 0.01, 1);
     _settings->add_lightsource(_("Light Source"));
+
+    _settings->type(NR_FILTER_DISPLACEMENTMAP);
+    _settings->add_spinslider(SP_ATTR_SCALE, _("Scale"), 0, 100, 1, 0.01, 1);
+    _settings->add_combo(SP_ATTR_XCHANNELSELECTOR, _("X Channel"), DisplacementMapChannelConverter);
+    _settings->add_combo(SP_ATTR_YCHANNELSELECTOR, _("Y Channel"), DisplacementMapChannelConverter);
     
     _settings->type(NR_FILTER_GAUSSIANBLUR);
     _settings->add_dualspinslider(SP_ATTR_STDDEVIATION, _("Standard Deviation"), 0.01, 100, 1, 0.01, 1);
@@ -1662,7 +1752,7 @@ void FilterEffectsDialog::duplicate_primitive()
 
 void FilterEffectsDialog::convolve_order_changed()
 {
-    _convolve_matrix->update(SP_FECONVOLVEMATRIX(_primitive_list.get_selected()));
+    _convolve_matrix->set_from_attribute(SP_OBJECT(_primitive_list.get_selected()));
     _convolve_target->get_spinbuttons()[0]->get_adjustment()->set_upper(_convolve_order->get_spinbutton1().get_value() - 1);
     _convolve_target->get_spinbuttons()[1]->get_adjustment()->set_upper(_convolve_order->get_spinbutton2().get_value() - 1);
 }