119dda377f0f022ed07c203343c36ed5d6033a06
1 /**
2 * \brief Filter Effects dialog
3 *
4 * Authors:
5 * Nicholas Bishop <nicholasbishop@gmail.org>
6 *
7 * Copyright (C) 2007 Authors
8 *
9 * Released under GNU GPL. Read the file 'COPYING' for more information.
10 */
12 #ifdef HAVE_CONFIG_H
13 # include <config.h>
14 #endif
16 #include <gtk/gtktreeview.h>
17 #include <gtkmm/cellrenderertext.h>
18 #include <gtkmm/colorbutton.h>
19 #include <gtkmm/paned.h>
20 #include <gtkmm/scale.h>
21 #include <gtkmm/scrolledwindow.h>
22 #include <gtkmm/spinbutton.h>
23 #include <gtkmm/stock.h>
24 #include <glibmm/i18n.h>
26 #include "application/application.h"
27 #include "application/editor.h"
28 #include "desktop.h"
29 #include "desktop-handles.h"
30 #include "dialog-manager.h"
31 #include "document.h"
32 #include "filter-chemistry.h"
33 #include "filter-effects-dialog.h"
34 #include "inkscape.h"
35 #include "selection.h"
36 #include "sp-feblend.h"
37 #include "sp-fecomposite.h"
38 #include "sp-fedisplacementmap.h"
39 #include "sp-femerge.h"
40 #include "sp-filter-primitive.h"
41 #include "sp-gaussian-blur.h"
42 #include "sp-feoffset.h"
43 #include "style.h"
44 #include "svg/svg-color.h"
45 #include "verbs.h"
46 #include "xml/node.h"
47 #include "xml/repr.h"
48 #include <sstream>
50 #include <iostream>
52 using namespace NR;
54 namespace Inkscape {
55 namespace UI {
56 namespace Dialog {
58 class ColorButton : public Gtk::ColorButton, public AttrWidget
59 {
60 public:
61 ColorButton(const SPAttributeEnum a)
62 : AttrWidget(a)
63 {
64 Gdk::Color col;
65 col.set_rgb(65535, 65535, 65535);
66 set_color(col);
67 }
69 // Returns the color in 'rgb(r,g,b)' form.
70 Glib::ustring get_as_attribute() const
71 {
72 std::ostringstream os;
73 const Gdk::Color c = get_color();
74 const int r = (c.get_red() + 1) / 256 - 1, g = (c.get_green() + 1) / 256 - 1, b = (c.get_blue() + 1) / 256 - 1;
75 os << "rgb(" << r << "," << g << "," << b << ")";
76 return os.str();
77 }
80 void set_from_attribute(SPObject* o)
81 {
82 const gchar* val = attribute_value(o);
83 if(val) {
84 const guint32 i = sp_svg_read_color(val, 0xFFFFFFFF);
85 const int r = SP_RGBA32_R_U(i) + 1, g = SP_RGBA32_G_U(i) + 1, b = SP_RGBA32_B_U(i) + 1;
86 Gdk::Color col;
87 col.set_rgb(r * 256 - 1, g * 256 - 1, b * 256 - 1);
88 set_color(col);
89 }
90 }
91 };
93 /* Displays/Edits the kernel matrix for feConvolveMatrix */
94 class FilterEffectsDialog::ConvolveMatrix : public Gtk::TreeView, public AttrWidget
95 {
96 public:
97 ConvolveMatrix(const SPAttributeEnum a)
98 : AttrWidget(a)
99 {
100 _model = Gtk::ListStore::create(_columns);
101 set_model(_model);
102 set_headers_visible(false);
103 }
105 Glib::ustring get_as_attribute() const
106 {
107 std::ostringstream os;
109 for(Gtk::TreeIter iter = _model->children().begin();
110 iter != _model->children().end(); ++iter) {
111 for(unsigned c = 0; c < get_columns().size(); ++c) {
112 os << (*iter)[_columns.cols[c]] << " ";
113 }
114 }
116 return os.str();
117 }
119 void set_from_attribute(SPObject* o)
120 {
121 update(SP_FECONVOLVEMATRIX(o));
122 }
124 sigc::signal<void>& signal_changed()
125 {
126 return _signal_changed;
127 }
129 void update(SPFeConvolveMatrix* conv)
130 {
131 if(conv) {
132 int cols, rows;
134 cols = (int)conv->order.getNumber();
135 if(cols > 5)
136 cols = 5;
137 rows = conv->order.optNumber_set ? (int)conv->order.getOptNumber() : cols;
139 update(conv, cols, rows);
140 }
141 }
142 private:
143 class ConvolveMatrixColumns : public Gtk::TreeModel::ColumnRecord
144 {
145 public:
146 ConvolveMatrixColumns()
147 {
148 cols.resize(5);
149 for(unsigned i = 0; i < cols.size(); ++i)
150 add(cols[i]);
151 }
152 std::vector<Gtk::TreeModelColumn<double> > cols;
153 };
155 void update(SPFeConvolveMatrix* conv, const int rows, const int cols)
156 {
157 _model->clear();
159 remove_all_columns();
161 if(conv) {
162 int ndx = 0;
164 for(int i = 0; i < cols; ++i) {
165 append_column_numeric_editable("", _columns.cols[i], "%.2f");
166 dynamic_cast<Gtk::CellRendererText*>(get_column(i)->get_first_cell_renderer())->signal_edited().connect(
167 sigc::mem_fun(*this, &ConvolveMatrix::rebind));
168 }
170 for(int r = 0; r < rows; ++r) {
171 Gtk::TreeRow row = *(_model->append());
172 for(int c = 0; c < cols; ++c, ++ndx)
173 row[_columns.cols[c]] = ndx < (int)conv->kernelMatrix.size() ? conv->kernelMatrix[ndx] : 0;
174 }
175 }
176 }
178 void rebind(const Glib::ustring&, const Glib::ustring&)
179 {
180 _signal_changed();
181 }
183 Glib::RefPtr<Gtk::ListStore> _model;
184 ConvolveMatrixColumns _columns;
185 sigc::signal<void> _signal_changed;
186 };
188 class FilterEffectsDialog::Settings
189 {
190 public:
191 Settings(FilterEffectsDialog& d)
192 : _dialog(d)
193 {
194 _sizegroup = Gtk::SizeGroup::create(Gtk::SIZE_GROUP_HORIZONTAL);
195 _sizegroup->set_ignore_hidden();
197 for(int i = 0; i < NR_FILTER_ENDPRIMITIVETYPE; ++i) {
198 _dialog._settings_box.add(_groups[i]);
199 }
200 }
202 ~Settings()
203 {
204 for(int i = 0; i < NR_FILTER_ENDPRIMITIVETYPE; ++i) {
205 for(unsigned j = 0; j < _attrwidgets[i].size(); ++j)
206 delete _attrwidgets[i][j];
207 }
208 }
210 // Show the active settings group and update all the AttrWidgets with new values
211 void show_and_update(const NR::FilterPrimitiveType t)
212 {
213 type(t);
214 _groups[t].show_all();
216 SPObject* ob = _dialog._primitive_list.get_selected();
218 _dialog.set_attrs_locked(true);
219 for(unsigned i = 0; i < _attrwidgets[_current_type].size(); ++i)
220 _attrwidgets[_current_type][i]->set_from_attribute(ob);
221 _dialog.set_attrs_locked(false);
222 }
224 void type(const NR::FilterPrimitiveType t)
225 {
226 _current_type = t;
227 }
229 ColorButton* add_color(const SPAttributeEnum attr, const Glib::ustring& label)
230 {
231 ColorButton* col = new ColorButton(attr);
232 add_widget(*col, label);
233 _attrwidgets[_current_type].push_back(col);
234 col->signal_color_set().connect(
235 sigc::bind(sigc::mem_fun(_dialog, &FilterEffectsDialog::set_attr_direct), attr, col));
236 return col;
237 }
239 // ConvolveMatrix
240 ConvolveMatrix* add(const SPAttributeEnum attr, const Glib::ustring& label)
241 {
242 ConvolveMatrix* conv = new ConvolveMatrix(attr);
243 add_widget(*conv, label);
244 _attrwidgets[_current_type].push_back(conv);
245 conv->signal_changed().connect(
246 sigc::bind(sigc::mem_fun(_dialog, &FilterEffectsDialog::set_attr_direct), attr, conv));
247 return conv;
248 }
250 // SpinSlider
251 SpinSlider* add(const SPAttributeEnum attr, const Glib::ustring& label,
252 const double lo, const double hi, const double step_inc, const double climb, const int digits)
253 {
254 SpinSlider* spinslider = new SpinSlider(lo, lo, hi, step_inc, climb, digits, attr);
255 add_widget(*spinslider, label);
256 _attrwidgets[_current_type].push_back(spinslider);
257 spinslider->signal_value_changed().connect(
258 sigc::bind(sigc::mem_fun(_dialog, &FilterEffectsDialog::set_attr_direct), attr, spinslider));
259 return spinslider;
260 }
262 // DualSpinSlider
263 DualSpinSlider* add(const SPAttributeEnum attr, const Glib::ustring& label1, const Glib::ustring& label2,
264 const double lo, const double hi, const double step_inc, const double climb, const int digits)
265 {
266 DualSpinSlider* dss = new DualSpinSlider(lo, lo, hi, step_inc, climb, digits, attr);
267 add_widget(dss->get_spinslider1(), label1);
268 add_widget(dss->get_spinslider2(), label2);
269 _attrwidgets[_current_type].push_back(dss);
270 dss->signal_value_changed().connect(
271 sigc::bind(sigc::mem_fun(_dialog, &FilterEffectsDialog::set_attr_direct), attr, dss));
272 return dss;
273 }
275 // ComboBoxEnum
276 template<typename T> ComboBoxEnum<T>* add(const SPAttributeEnum attr,
277 const Glib::ustring& label,
278 const Util::EnumDataConverter<T>& conv)
279 {
280 ComboBoxEnum<T>* combo = new ComboBoxEnum<T>(conv, attr);
281 add_widget(*combo, label);
282 _attrwidgets[_current_type].push_back(combo);
283 combo->signal_changed().connect(
284 sigc::bind(sigc::mem_fun(_dialog, &FilterEffectsDialog::set_attr_direct), attr, combo));
285 return combo;
286 }
288 // Combine the two most recent settings widgets in to the same row
289 void combine()
290 {
291 Gtk::VBox& vb = _groups[_current_type];
292 const int size = vb.children().size();
293 if(size >= 2) {
294 Gtk::HBox* h1 = dynamic_cast<Gtk::HBox*>(vb.children()[size - 2].get_widget());
295 Gtk::HBox* h2 = dynamic_cast<Gtk::HBox*>(vb.children()[size - 1].get_widget());
296 Gtk::Widget* c1 = h1->children()[1].get_widget();
297 Gtk::Widget* c2 = h2->children()[1].get_widget();
298 h1->remove(*c1);
299 h2->remove(*c2);
300 h1->pack_start(*c1, false, false);
301 h1->pack_start(*c2, false, false);
302 vb.remove(*h2);
303 }
304 }
305 private:
306 /* Adds a new settings widget using the specified label. The label will be formatted with a colon
307 and all widgets within the setting group are aligned automatically. */
308 void add_widget(Gtk::Widget& w, const Glib::ustring& label)
309 {
310 Gtk::Label *lbl = Gtk::manage(new Gtk::Label(label + (label == "" ? "" : ":"), Gtk::ALIGN_LEFT));
311 Gtk::HBox *hb = Gtk::manage(new Gtk::HBox);
312 hb->set_spacing(12);
313 hb->pack_start(*lbl, false, false);
314 hb->pack_start(w);
315 _groups[_current_type].pack_start(*hb);
317 _sizegroup->add_widget(*lbl);
319 hb->show();
320 lbl->show();
322 w.show();
323 }
325 Gtk::VBox _groups[NR::NR_FILTER_ENDPRIMITIVETYPE];
326 Glib::RefPtr<Gtk::SizeGroup> _sizegroup;
328 FilterEffectsDialog& _dialog;
329 std::vector<AttrWidget*> _attrwidgets[NR::NR_FILTER_ENDPRIMITIVETYPE];
330 NR::FilterPrimitiveType _current_type;
331 };
333 Glib::RefPtr<Gtk::Menu> create_popup_menu(Gtk::Widget& parent, sigc::slot<void> dup,
334 sigc::slot<void> rem)
335 {
336 Glib::RefPtr<Gtk::Menu> menu(new Gtk::Menu);
338 menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("_Duplicate"), dup));
339 Gtk::MenuItem* mi = Gtk::manage(new Gtk::ImageMenuItem(Gtk::Stock::REMOVE));
340 menu->append(*mi);
341 mi->signal_activate().connect(rem);
342 mi->show();
343 menu->accelerate(parent);
345 return menu;
346 }
348 static void try_id_change(SPObject* ob, const Glib::ustring& text)
349 {
350 // FIXME: this needs more serious error checking...
351 if(ob && !SP_ACTIVE_DOCUMENT->getObjectById(text.c_str())) {
352 SPException ex;
353 SP_EXCEPTION_INIT(&ex);
354 sp_object_setAttribute(ob, "id", text.c_str(), &ex);
355 sp_document_done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_FILTER_EFFECTS, _("Set object ID"));
356 }
357 }
359 /*** FilterModifier ***/
360 FilterEffectsDialog::FilterModifier::FilterModifier()
361 : _add(Gtk::Stock::ADD)
362 {
363 Gtk::ScrolledWindow* sw = Gtk::manage(new Gtk::ScrolledWindow);
364 pack_start(*sw);
365 pack_start(_add, false, false);
366 sw->add(_list);
368 _list.set_model(_model);
369 const int selcol = _list.append_column("", _cell_sel);
370 Gtk::TreeViewColumn* col = _list.get_column(selcol - 1);
371 if(col)
372 col->add_attribute(_cell_sel.property_sel(), _columns.sel);
373 _list.append_column(_("_Filter"), _columns.id);
375 sw->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
376 sw->set_shadow_type(Gtk::SHADOW_IN);
377 show_all_children();
378 _add.signal_clicked().connect(sigc::mem_fun(*this, &FilterModifier::add_filter));
379 _list.signal_button_press_event().connect_notify(
380 sigc::mem_fun(*this, &FilterModifier::filter_list_button_press));
381 _list.signal_button_release_event().connect_notify(
382 sigc::mem_fun(*this, &FilterModifier::filter_list_button_release));
383 _menu = create_popup_menu(*this, sigc::mem_fun(*this, &FilterModifier::duplicate_filter),
384 sigc::mem_fun(*this, &FilterModifier::remove_filter));
386 g_signal_connect(G_OBJECT(INKSCAPE), "change_selection",
387 G_CALLBACK(&FilterModifier::on_inkscape_change_selection), this);
389 update_filters();
390 }
392 FilterEffectsDialog::FilterModifier::CellRendererSel::CellRendererSel()
393 : Glib::ObjectBase(typeid(CellRendererSel)),
394 _size(10),
395 _sel(*this, "sel", 0)
396 {}
398 Glib::PropertyProxy<int> FilterEffectsDialog::FilterModifier::CellRendererSel::property_sel()
399 {
400 return _sel.get_proxy();
401 }
403 void FilterEffectsDialog::FilterModifier::CellRendererSel::get_size_vfunc(
404 Gtk::Widget&, const Gdk::Rectangle*, int* x, int* y, int* w, int* h) const
405 {
406 if(x)
407 (*x) = 0;
408 if(y)
409 (*y) = 0;
410 if(w)
411 (*w) = _size;
412 if(h)
413 (*h) = _size;
414 }
416 void FilterEffectsDialog::FilterModifier::CellRendererSel::render_vfunc(
417 const Glib::RefPtr<Gdk::Drawable>& win, Gtk::Widget& widget, const Gdk::Rectangle& bg_area,
418 const Gdk::Rectangle& cell_area, const Gdk::Rectangle& expose_area, Gtk::CellRendererState flags)
419 {
420 const int sel = _sel.get_value();
422 if(sel > 0) {
423 const int s = _size - 2;
424 const int w = cell_area.get_width();
425 const int h = cell_area.get_height();
426 const int x = cell_area.get_x() + w / 2 - s / 2;
427 const int y = cell_area.get_y() + h / 2 - s / 2;
429 win->draw_rectangle(widget.get_style()->get_text_gc(Gtk::STATE_NORMAL), (sel == 1), x, y, s, s);
430 }
431 }
433 // When the selection changes, show the active filter(s) in the dialog
434 void FilterEffectsDialog::FilterModifier::on_inkscape_change_selection(Application *inkscape,
435 Selection *sel,
436 FilterModifier* fm)
437 {
438 if(fm && sel)
439 fm->update_selection(sel);
440 }
442 void FilterEffectsDialog::FilterModifier::update_selection(Selection *sel)
443 {
444 std::set<SPObject*> used;
446 for(GSList const *i = sel->itemList(); i != NULL; i = i->next) {
447 SPObject *obj = SP_OBJECT (i->data);
448 SPStyle *style = SP_OBJECT_STYLE (obj);
449 if(!style || !SP_IS_ITEM(obj)) continue;
451 if(style->filter.set && style->getFilter())
452 used.insert(style->getFilter());
453 else
454 used.insert(0);
455 }
457 const int size = used.size();
459 for(Gtk::TreeIter iter = _model->children().begin();
460 iter != _model->children().end(); ++iter) {
461 if(used.find((*iter)[_columns.filter]) != used.end()) {
462 // If only one filter is in use by the selection, select it
463 if(size == 1)
464 _list.get_selection()->select(iter);
465 (*iter)[_columns.sel] = size;
466 }
467 else
468 (*iter)[_columns.sel] = 0;
469 }
470 }
472 Glib::SignalProxy0<void> FilterEffectsDialog::FilterModifier::signal_selection_changed()
473 {
474 return _list.get_selection()->signal_changed();
475 }
477 SPFilter* FilterEffectsDialog::FilterModifier::get_selected_filter()
478 {
479 if(_list.get_selection()) {
480 Gtk::TreeModel::iterator i = _list.get_selection()->get_selected();
482 if(i)
483 return (*i)[_columns.filter];
484 }
486 return 0;
487 }
489 void FilterEffectsDialog::FilterModifier::select_filter(const SPFilter* filter)
490 {
491 if(filter) {
492 for(Gtk::TreeModel::iterator i = _model->children().begin();
493 i != _model->children().end(); ++i) {
494 if((*i)[_columns.filter] == filter) {
495 _list.get_selection()->select(i);
496 break;
497 }
498 }
499 }
500 }
502 void FilterEffectsDialog::FilterModifier::filter_list_button_press(GdkEventButton* e)
503 {
504 // Double-click
505 if(e->type == GDK_2BUTTON_PRESS) {
506 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
507 SPDocument *doc = sp_desktop_document(desktop);
508 SPFilter* filter = get_selected_filter();
509 Inkscape::Selection *sel = sp_desktop_selection(desktop);
511 GSList const *items = sel->itemList();
513 for (GSList const *i = items; i != NULL; i = i->next) {
514 SPItem * item = SP_ITEM(i->data);
515 SPStyle *style = SP_OBJECT_STYLE(item);
516 g_assert(style != NULL);
518 sp_style_set_property_url(SP_OBJECT(item), "filter", SP_OBJECT(filter), false);
519 SP_OBJECT(item)->requestDisplayUpdate((SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG ));
520 }
522 update_selection(sel);
523 sp_document_done(doc, SP_VERB_DIALOG_FILTER_EFFECTS, _("Apply filter"));
524 }
525 }
527 void FilterEffectsDialog::FilterModifier::filter_list_button_release(GdkEventButton* event)
528 {
529 if((event->type == GDK_BUTTON_RELEASE) && (event->button == 3)) {
530 const bool sensitive = get_selected_filter() != NULL;
531 _menu->items()[0].set_sensitive(sensitive);
532 _menu->items()[1].set_sensitive(sensitive);
533 _menu->popup(event->button, event->time);
534 }
535 }
537 void FilterEffectsDialog::FilterModifier::add_filter()
538 {
539 SPDocument* doc = sp_desktop_document(SP_ACTIVE_DESKTOP);
540 SPFilter* filter = new_filter(doc);
542 update_filters();
544 select_filter(filter);
546 sp_document_done(doc, SP_VERB_DIALOG_FILTER_EFFECTS, _("Add filter"));
547 }
549 void FilterEffectsDialog::FilterModifier::remove_filter()
550 {
551 SPFilter *filter = get_selected_filter();
553 if(filter) {
554 SPDocument* doc = filter->document;
555 sp_repr_unparent(filter->repr);
557 sp_document_done(doc, SP_VERB_DIALOG_FILTER_EFFECTS, _("Remove filter"));
559 update_filters();
560 }
561 }
563 void FilterEffectsDialog::FilterModifier::duplicate_filter()
564 {
565 SPFilter* filter = get_selected_filter();
567 if(filter) {
568 Inkscape::XML::Node* repr = SP_OBJECT_REPR(filter), *parent = repr->parent();
569 repr = repr->duplicate(repr->document());
570 parent->appendChild(repr);
572 sp_document_done(filter->document, SP_VERB_DIALOG_FILTER_EFFECTS, _("Duplicate filter"));
574 update_filters();
575 }
576 }
578 void FilterEffectsDialog::FilterModifier::filter_name_edited(const Glib::ustring& path, const Glib::ustring& text)
579 {
580 Gtk::TreeModel::iterator i = _model->get_iter(path);
582 if(i)
583 try_id_change((SPObject*)(*i)[_columns.filter], text);
584 }
586 FilterEffectsDialog::CellRendererConnection::CellRendererConnection()
587 : Glib::ObjectBase(typeid(CellRendererConnection)),
588 _primitive(*this, "primitive", 0)
589 {}
591 Glib::PropertyProxy<void*> FilterEffectsDialog::CellRendererConnection::property_primitive()
592 {
593 return _primitive.get_proxy();
594 }
596 int FilterEffectsDialog::CellRendererConnection::input_count(const SPFilterPrimitive* prim)
597 {
598 if(!prim)
599 return 0;
600 else if(SP_IS_FEBLEND(prim) || SP_IS_FECOMPOSITE(prim) || SP_IS_FEDISPLACEMENTMAP(prim))
601 return 2;
602 else if(SP_IS_FEMERGE(prim)) {
603 // Return the number of feMergeNode connections plus an extra one for adding a new input
604 int count = 1;
605 for(const SPObject* o = prim->firstChild(); o; o = o->next, ++count);
606 return count;
607 }
608 else
609 return 1;
610 }
612 void FilterEffectsDialog::CellRendererConnection::set_text_width(const int w)
613 {
614 _text_width = w;
615 }
617 int FilterEffectsDialog::CellRendererConnection::get_text_width() const
618 {
619 return _text_width;
620 }
622 void FilterEffectsDialog::CellRendererConnection::get_size_vfunc(
623 Gtk::Widget& widget, const Gdk::Rectangle* cell_area,
624 int* x_offset, int* y_offset, int* width, int* height) const
625 {
626 PrimitiveList& primlist = dynamic_cast<PrimitiveList&>(widget);
628 if(x_offset)
629 (*x_offset) = 0;
630 if(y_offset)
631 (*y_offset) = 0;
632 if(width)
633 (*width) = size * primlist.primitive_count() + _text_width * 7;
634 if(height) {
635 // Scale the height depending on the number of inputs, unless it's
636 // the first primitive, in which case there are no connections
637 SPFilterPrimitive* prim = (SPFilterPrimitive*)_primitive.get_value();
638 (*height) = size * input_count(prim);
639 }
640 }
642 /*** PrimitiveList ***/
643 FilterEffectsDialog::PrimitiveList::PrimitiveList(FilterEffectsDialog& d)
644 : _dialog(d),
645 _in_drag(0)
646 {
647 add_events(Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
648 signal_expose_event().connect(sigc::mem_fun(*this, &PrimitiveList::on_expose_signal));
650 _model = Gtk::ListStore::create(_columns);
652 set_reorderable(true);
654 set_model(_model);
655 append_column(_("_Type"), _columns.type);
657 signal_selection_changed().connect(sigc::mem_fun(*this, &PrimitiveList::queue_draw));
659 _connection_cell.set_text_width(init_text());
661 int cols_count = append_column(_("Connections"), _connection_cell);
662 Gtk::TreeViewColumn* col = get_column(cols_count - 1);
663 if(col)
664 col->add_attribute(_connection_cell.property_primitive(), _columns.primitive);
665 }
667 // Sets up a vertical Pango context/layout, and returns the largest
668 // width needed to render the FilterPrimitiveInput labels.
669 int FilterEffectsDialog::PrimitiveList::init_text()
670 {
671 // Set up a vertical context+layout
672 Glib::RefPtr<Pango::Context> context = create_pango_context();
673 const Pango::Matrix matrix = {0, -1, 1, 0, 0, 0};
674 context->set_matrix(matrix);
675 _vertical_layout = Pango::Layout::create(context);
677 int maxfont = 0;
678 for(int i = 0; i < FPInputConverter.end; ++i) {
679 _vertical_layout->set_text(FPInputConverter.get_label((FilterPrimitiveInput)i));
680 int fontw, fonth;
681 _vertical_layout->get_pixel_size(fontw, fonth);
682 if(fonth > maxfont)
683 maxfont = fonth;
684 }
686 return maxfont;
687 }
689 Glib::SignalProxy0<void> FilterEffectsDialog::PrimitiveList::signal_selection_changed()
690 {
691 return get_selection()->signal_changed();
692 }
694 /* Add all filter primitives in the current to the list.
695 Keeps the same selection if possible, otherwise selects the first element */
696 void FilterEffectsDialog::PrimitiveList::update()
697 {
698 SPFilter* f = _dialog._filter_modifier.get_selected_filter();
699 const SPFilterPrimitive* active_prim = get_selected();
700 bool active_found = false;
702 _model->clear();
704 if(f) {
705 _dialog._primitive_box.set_sensitive(true);
707 for(SPObject *prim_obj = f->children;
708 prim_obj && SP_IS_FILTER_PRIMITIVE(prim_obj);
709 prim_obj = prim_obj->next) {
710 SPFilterPrimitive *prim = SP_FILTER_PRIMITIVE(prim_obj);
711 if(prim) {
712 Gtk::TreeModel::Row row = *_model->append();
713 row[_columns.primitive] = prim;
714 row[_columns.type_id] = FPConverter.get_id_from_key(prim->repr->name());
715 row[_columns.type] = FPConverter.get_label(row[_columns.type_id]);
716 row[_columns.id] = SP_OBJECT_ID(prim);
718 if(prim == active_prim) {
719 get_selection()->select(row);
720 active_found = true;
721 }
722 }
723 }
725 if(!active_found && _model->children().begin())
726 get_selection()->select(_model->children().begin());
727 }
728 else {
729 _dialog._primitive_box.set_sensitive(false);
730 }
731 }
733 void FilterEffectsDialog::PrimitiveList::set_menu(Glib::RefPtr<Gtk::Menu> menu)
734 {
735 _primitive_menu = menu;
736 }
738 SPFilterPrimitive* FilterEffectsDialog::PrimitiveList::get_selected()
739 {
740 if(_dialog._filter_modifier.get_selected_filter()) {
741 Gtk::TreeModel::iterator i = get_selection()->get_selected();
742 if(i)
743 return (*i)[_columns.primitive];
744 }
746 return 0;
747 }
749 void FilterEffectsDialog::PrimitiveList::select(SPFilterPrimitive* prim)
750 {
751 for(Gtk::TreeIter i = _model->children().begin();
752 i != _model->children().end(); ++i) {
753 if((*i)[_columns.primitive] == prim)
754 get_selection()->select(i);
755 }
756 }
760 bool FilterEffectsDialog::PrimitiveList::on_expose_signal(GdkEventExpose* e)
761 {
762 Gdk::Rectangle clip(e->area.x, e->area.y, e->area.width, e->area.height);
763 Glib::RefPtr<Gdk::Window> win = get_bin_window();
764 Glib::RefPtr<Gdk::GC> darkgc = get_style()->get_dark_gc(Gtk::STATE_NORMAL);
766 SPFilterPrimitive* prim = get_selected();
767 int row_count = get_model()->children().size();
769 int fheight = CellRendererConnection::size;
770 Gdk::Rectangle rct, vis;
771 Gtk::TreeIter row = get_model()->children().begin();
772 int text_start_x = 0;
773 if(row) {
774 get_cell_area(get_model()->get_path(row), *get_column(1), rct);
775 get_visible_rect(vis);
776 int vis_x, vis_y;
777 tree_to_widget_coords(vis.get_x(), vis.get_y(), vis_x, vis_y);
779 text_start_x = rct.get_x() + rct.get_width() - _connection_cell.get_text_width() * (FPInputConverter.end + 1) + 1;
780 for(int i = 0; i < FPInputConverter.end; ++i) {
781 _vertical_layout->set_text(FPInputConverter.get_label((FilterPrimitiveInput)i));
782 const int x = text_start_x + _connection_cell.get_text_width() * (i + 1);
783 get_bin_window()->draw_rectangle(get_style()->get_bg_gc(Gtk::STATE_NORMAL), true, x, vis_y, _connection_cell.get_text_width(), vis.get_height());
784 get_bin_window()->draw_layout(get_style()->get_text_gc(Gtk::STATE_NORMAL), x + 1, vis_y, _vertical_layout);
785 get_bin_window()->draw_line(darkgc, x, vis_y, x, vis_y + vis.get_height());
786 }
787 }
789 int row_index = 0;
790 for(; row != get_model()->children().end(); ++row, ++row_index) {
791 get_cell_area(get_model()->get_path(row), *get_column(1), rct);
792 const int x = rct.get_x(), y = rct.get_y(), h = rct.get_height();
794 // Check mouse state
795 int mx, my;
796 Gdk::ModifierType mask;
797 get_bin_window()->get_pointer(mx, my, mask);
799 // Outline the bottom of the connection area
800 const int outline_x = x + fheight * (row_count - row_index);
801 get_bin_window()->draw_line(darkgc, x, y + h, outline_x, y + h);
803 // Side outline
804 get_bin_window()->draw_line(darkgc, outline_x, y - 1, outline_x, y + h);
806 std::vector<Gdk::Point> con_poly;
807 int con_drag_y;
808 bool inside;
809 const SPFilterPrimitive* row_prim = (*row)[_columns.primitive];
810 const int inputs = CellRendererConnection::input_count(row_prim);
812 if(SP_IS_FEMERGE(row_prim)) {
813 for(int i = 0; i < inputs; ++i) {
814 inside = do_connection_node(row, i, con_poly, mx, my);
815 get_bin_window()->draw_polygon(inside && mask & GDK_BUTTON1_MASK ?
816 darkgc : get_style()->get_dark_gc(Gtk::STATE_ACTIVE),
817 inside, con_poly);
819 // TODO: draw connections for each of the feMergeNodes
820 }
821 }
822 else {
823 // Draw "in" shape
824 inside = do_connection_node(row, 0, con_poly, mx, my);
825 con_drag_y = con_poly[2].get_y();
826 get_bin_window()->draw_polygon(inside && mask & GDK_BUTTON1_MASK ?
827 darkgc : get_style()->get_dark_gc(Gtk::STATE_ACTIVE),
828 inside, con_poly);
829 // Draw "in" connection
830 if(_in_drag != 1 || row_prim != prim)
831 draw_connection(row, SP_ATTR_IN, text_start_x, outline_x, con_poly[2].get_y(), row_count);
833 if(inputs == 2) {
834 // Draw "in2" shape
835 inside = do_connection_node(row, 1, con_poly, mx, my);
836 if(_in_drag == 2)
837 con_drag_y = con_poly[2].get_y();
838 get_bin_window()->draw_polygon(inside && mask & GDK_BUTTON1_MASK ?
839 darkgc : get_style()->get_dark_gc(Gtk::STATE_ACTIVE),
840 inside, con_poly);
841 // Draw "in2" connection
842 if(_in_drag != 2 || row_prim != prim)
843 draw_connection(row, SP_ATTR_IN2, text_start_x, outline_x, con_poly[2].get_y(), row_count);
844 }
846 // Draw drag connection
847 if(row_prim == prim && _in_drag) {
848 get_bin_window()->draw_line(get_style()->get_black_gc(), outline_x, con_drag_y,
849 mx, con_drag_y);
850 get_bin_window()->draw_line(get_style()->get_black_gc(), mx, con_drag_y, mx, my);
851 }
852 }
853 }
855 return true;
856 }
858 void FilterEffectsDialog::PrimitiveList::draw_connection(const Gtk::TreeIter& input, const SPAttributeEnum attr,
859 const int text_start_x, const int x1, const int y1,
860 const int row_count)
861 {
862 const Gtk::TreeIter res = find_result(input, attr);
863 Glib::RefPtr<Gdk::GC> gc = get_style()->get_black_gc();
865 if(res == input) {
866 // Draw straight connection to a standard input
867 const int tw = _connection_cell.get_text_width();
868 const int src = 1 + (int)FPInputConverter.get_id_from_key(
869 SP_OBJECT_REPR((*res)[_columns.primitive])->attribute((const gchar*)sp_attribute_name(attr)));
870 gint end_x = text_start_x + tw * src + (int)(tw * 0.5f) + 1;
871 get_bin_window()->draw_rectangle(gc, true, end_x-2, y1-2, 5, 5);
872 get_bin_window()->draw_line(gc, x1, y1, end_x, y1);
873 }
874 else if(res != _model->children().end()) {
875 Gdk::Rectangle rct;
877 get_cell_area(get_model()->get_path(_model->children().begin()), *get_column(1), rct);
878 const int fheight = CellRendererConnection::size;
880 get_cell_area(get_model()->get_path(res), *get_column(1), rct);
881 const int row_index = find_index(res);
882 const int x2 = rct.get_x() + fheight * (row_count - row_index) - fheight / 2;
883 const int y2 = rct.get_y() + rct.get_height();
885 // Draw an 'L'-shaped connection to another filter primitive
886 get_bin_window()->draw_line(gc, x1, y1, x2, y1);
887 get_bin_window()->draw_line(gc, x2, y1, x2, y2);
888 }
889 }
891 // Creates a triangle outline of the connection node and returns true if (x,y) is inside the node
892 bool FilterEffectsDialog::PrimitiveList::do_connection_node(const Gtk::TreeIter& row, const int input,
893 std::vector<Gdk::Point>& points,
894 const int ix, const int iy)
895 {
896 Gdk::Rectangle rct;
897 const int input_count = CellRendererConnection::input_count((*row)[_columns.primitive]);
899 get_cell_area(get_model()->get_path(_model->children().begin()), *get_column(1), rct);
900 const int fheight = CellRendererConnection::size;
902 get_cell_area(_model->get_path(row), *get_column(1), rct);
903 const float h = rct.get_height() / input_count;
905 const int x = rct.get_x() + fheight * (_model->children().size() - find_index(row));
906 const int con_w = (int)(fheight * 0.35f);
907 const int con_y = (int)(rct.get_y() + (h / 2) - con_w + (input * h));
908 points.clear();
909 points.push_back(Gdk::Point(x, con_y));
910 points.push_back(Gdk::Point(x, con_y + con_w * 2));
911 points.push_back(Gdk::Point(x - con_w, con_y + con_w));
913 return ix >= x - h && iy >= con_y && ix <= x && iy <= points[1].get_y();
914 }
916 const Gtk::TreeIter FilterEffectsDialog::PrimitiveList::find_result(const Gtk::TreeIter& start,
917 const SPAttributeEnum attr)
918 {
919 SPFilterPrimitive* prim = (*start)[_columns.primitive];
920 Gtk::TreeIter target = _model->children().end();
921 int image;
923 if(attr == SP_ATTR_IN)
924 image = prim->image_in;
925 else if(attr == SP_ATTR_IN2) {
926 if(SP_IS_FEBLEND(prim))
927 image = SP_FEBLEND(prim)->in2;
928 else if(SP_IS_FECOMPOSITE(prim))
929 image = SP_FECOMPOSITE(prim)->in2;
930 /*else if(SP_IS_FEDISPLACEMENTMAP(prim))
931 image = SP_FEDISPLACEMENTMAP(prim)->in2;*/
932 else
933 return target;
934 }
935 else
936 return target;
938 if(image >= 0) {
939 for(Gtk::TreeIter i = _model->children().begin();
940 i != start; ++i) {
941 if(((SPFilterPrimitive*)(*i)[_columns.primitive])->image_out == image)
942 target = i;
943 }
944 return target;
945 }
946 else if(image < -1)
947 return start;
949 return target;
950 }
952 int FilterEffectsDialog::PrimitiveList::find_index(const Gtk::TreeIter& target)
953 {
954 int i = 0;
955 for(Gtk::TreeIter iter = _model->children().begin();
956 iter != target; ++iter, ++i);
957 return i;
958 }
960 bool FilterEffectsDialog::PrimitiveList::on_button_press_event(GdkEventButton* e)
961 {
962 Gtk::TreePath path;
963 Gtk::TreeViewColumn* col;
964 const int x = (int)e->x, y = (int)e->y;
965 int cx, cy;
967 _drag_prim = 0;
969 if(get_path_at_pos(x, y, path, col, cx, cy)) {
970 Gtk::TreeIter iter = _model->get_iter(path);
971 std::vector<Gdk::Point> points;
972 if(do_connection_node(_model->get_iter(path), 0, points, x, y))
973 _in_drag = 1;
974 else if(do_connection_node(_model->get_iter(path), 1, points, x, y))
975 _in_drag = 2;
977 queue_draw();
978 _drag_prim = (*iter)[_columns.primitive];
979 }
981 if(_in_drag) {
982 get_selection()->select(path);
983 return true;
984 }
985 else
986 return Gtk::TreeView::on_button_press_event(e);
987 }
989 bool FilterEffectsDialog::PrimitiveList::on_motion_notify_event(GdkEventMotion* e)
990 {
991 queue_draw();
993 return Gtk::TreeView::on_motion_notify_event(e);
994 }
996 bool FilterEffectsDialog::PrimitiveList::on_button_release_event(GdkEventButton* e)
997 {
998 SPFilterPrimitive *prim = get_selected(), *target;
1000 if(_in_drag && prim) {
1001 Gtk::TreePath path;
1002 Gtk::TreeViewColumn* col;
1003 int cx, cy;
1005 if(get_path_at_pos((int)e->x, (int)e->y, path, col, cx, cy)) {
1006 const gchar *in_val = 0;
1007 Glib::ustring result;
1008 Gtk::TreeIter target_iter = _model->get_iter(path);
1009 target = (*target_iter)[_columns.primitive];
1011 Gdk::Rectangle rct;
1012 get_cell_area(path, *col, rct);
1013 const int twidth = _connection_cell.get_text_width();
1014 const int sources_x = rct.get_width() - twidth * FPInputConverter.end;
1015 if(cx > sources_x) {
1016 int src = (cx - sources_x) / twidth;
1017 if(src < 0)
1018 src = 0;
1019 else if(src >= FPInputConverter.end)
1020 src = FPInputConverter.end - 1;
1021 result = FPInputConverter.get_key((FilterPrimitiveInput)src);
1022 in_val = result.c_str();
1023 }
1024 else {
1025 // Ensure that the target comes before the selected primitive
1026 for(Gtk::TreeIter iter = _model->children().begin();
1027 iter != get_selection()->get_selected(); ++iter) {
1028 if(iter == target_iter) {
1029 Inkscape::XML::Node *repr = SP_OBJECT_REPR(target);
1030 // Make sure the target has a result
1031 const gchar *gres = repr->attribute("result");
1032 if(!gres) {
1033 result = "result" + Glib::Ascii::dtostr(SP_FILTER(prim->parent)->_image_number_next);
1034 repr->setAttribute("result", result.c_str());
1035 in_val = result.c_str();
1036 }
1037 else
1038 in_val = gres;
1039 break;
1040 }
1041 }
1042 }
1044 if(_in_drag == 1)
1045 _dialog.set_attr(SP_ATTR_IN, in_val);
1046 else if(_in_drag == 2)
1047 _dialog.set_attr(SP_ATTR_IN2, in_val);
1048 }
1050 _in_drag = 0;
1051 queue_draw();
1053 _dialog.update_settings_view();
1054 }
1056 if((e->type == GDK_BUTTON_RELEASE) && (e->button == 3)) {
1057 const bool sensitive = get_selected() != NULL;
1058 _primitive_menu->items()[0].set_sensitive(sensitive);
1059 _primitive_menu->items()[1].set_sensitive(sensitive);
1060 _primitive_menu->popup(e->button, e->time);
1062 return true;
1063 }
1064 else
1065 return Gtk::TreeView::on_button_release_event(e);
1066 }
1068 // Checks all of prim's inputs, removes any that use result
1069 void check_single_connection(SPFilterPrimitive* prim, const int result)
1070 {
1071 if(prim && result >= 0) {
1073 if(prim->image_in == result)
1074 SP_OBJECT_REPR(prim)->setAttribute("in", 0);
1076 if(SP_IS_FEBLEND(prim)) {
1077 if(SP_FEBLEND(prim)->in2 == result)
1078 SP_OBJECT_REPR(prim)->setAttribute("in2", 0);
1079 }
1080 else if(SP_IS_FECOMPOSITE(prim)) {
1081 if(SP_FECOMPOSITE(prim)->in2 == result)
1082 SP_OBJECT_REPR(prim)->setAttribute("in2", 0);
1083 }
1084 }
1085 }
1087 // Remove any connections going to/from prim_iter that forward-reference other primitives
1088 void FilterEffectsDialog::PrimitiveList::sanitize_connections(const Gtk::TreeIter& prim_iter)
1089 {
1090 SPFilterPrimitive *prim = (*prim_iter)[_columns.primitive];
1091 bool before = true;
1093 for(Gtk::TreeIter iter = _model->children().begin();
1094 iter != _model->children().end(); ++iter) {
1095 if(iter == prim_iter)
1096 before = false;
1097 else {
1098 SPFilterPrimitive* cur_prim = (*iter)[_columns.primitive];
1099 if(before)
1100 check_single_connection(cur_prim, prim->image_out);
1101 else
1102 check_single_connection(prim, cur_prim->image_out);
1103 }
1104 }
1105 }
1107 // Reorder the filter primitives to match the list order
1108 void FilterEffectsDialog::PrimitiveList::on_drag_end(const Glib::RefPtr<Gdk::DragContext>&)
1109 {
1110 SPFilter* filter = _dialog._filter_modifier.get_selected_filter();
1111 int ndx = 0;
1113 for(Gtk::TreeModel::iterator iter = _model->children().begin();
1114 iter != _model->children().end(); ++iter, ++ndx) {
1115 SPFilterPrimitive* prim = (*iter)[_columns.primitive];
1116 if(prim) {
1117 SP_OBJECT_REPR(prim)->setPosition(ndx);
1118 if(_drag_prim == prim) {
1119 sanitize_connections(iter);
1120 get_selection()->select(iter);
1121 }
1122 }
1123 }
1125 filter->requestModified(SP_OBJECT_MODIFIED_FLAG);
1127 sp_document_done(filter->document, SP_VERB_DIALOG_FILTER_EFFECTS, _("Reorder filter primitive"));
1128 }
1130 int FilterEffectsDialog::PrimitiveList::primitive_count() const
1131 {
1132 return _model->children().size();
1133 }
1135 /*** FilterEffectsDialog ***/
1137 FilterEffectsDialog::FilterEffectsDialog()
1138 : Dialog ("dialogs.filtereffects", SP_VERB_DIALOG_FILTER_EFFECTS),
1139 _primitive_list(*this),
1140 _add_primitive_type(FPConverter),
1141 _add_primitive(Gtk::Stock::ADD),
1142 _empty_settings(_("No primitive selected"), Gtk::ALIGN_LEFT),
1143 _locked(false)
1144 {
1145 _settings = new Settings(*this);
1147 // Initialize widget hierarchy
1148 Gtk::HPaned* hpaned = Gtk::manage(new Gtk::HPaned);
1149 Gtk::ScrolledWindow* sw_prims = Gtk::manage(new Gtk::ScrolledWindow);
1150 Gtk::HBox* hb_prims = Gtk::manage(new Gtk::HBox);
1151 Gtk::Frame* fr_settings = Gtk::manage(new Gtk::Frame(_("<b>Settings</b>")));
1152 Gtk::Alignment* al_settings = Gtk::manage(new Gtk::Alignment);
1153 get_vbox()->add(*hpaned);
1154 hpaned->pack1(_filter_modifier);
1155 hpaned->pack2(_primitive_box);
1156 _primitive_box.pack_start(*sw_prims);
1157 _primitive_box.pack_start(*hb_prims, false, false);
1158 sw_prims->add(_primitive_list);
1159 hb_prims->pack_end(_add_primitive, false, false);
1160 hb_prims->pack_end(_add_primitive_type, false, false);
1161 get_vbox()->pack_start(*fr_settings, false, false);
1162 fr_settings->add(*al_settings);
1163 al_settings->add(_settings_box);
1165 _primitive_list.signal_selection_changed().connect(
1166 sigc::mem_fun(*this, &FilterEffectsDialog::update_settings_view));
1167 _filter_modifier.signal_selection_changed().connect(
1168 sigc::mem_fun(_primitive_list, &PrimitiveList::update));
1170 sw_prims->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
1171 sw_prims->set_shadow_type(Gtk::SHADOW_IN);
1172 al_settings->set_padding(0, 0, 12, 0);
1173 fr_settings->set_shadow_type(Gtk::SHADOW_NONE);
1174 ((Gtk::Label*)fr_settings->get_label_widget())->set_use_markup();
1175 _add_primitive.signal_clicked().connect(sigc::mem_fun(*this, &FilterEffectsDialog::add_primitive));
1176 _primitive_list.set_menu(create_popup_menu(*this, sigc::mem_fun(*this, &FilterEffectsDialog::duplicate_primitive),
1177 sigc::mem_fun(*this, &FilterEffectsDialog::remove_primitive)));
1179 show_all_children();
1180 init_settings_widgets();
1181 _primitive_list.update();
1182 update_settings_view();
1183 }
1185 FilterEffectsDialog::~FilterEffectsDialog()
1186 {
1187 delete _settings;
1188 }
1190 void FilterEffectsDialog::set_attrs_locked(const bool l)
1191 {
1192 _locked = l;
1193 }
1195 void FilterEffectsDialog::init_settings_widgets()
1196 {
1197 // TODO: Find better range/climb-rate/digits values for the SpinSliders,
1198 // most of the current values are complete guesses!
1200 _empty_settings.set_sensitive(false);
1201 _settings_box.pack_start(_empty_settings);
1203 _settings->type(NR_FILTER_BLEND);
1204 _settings->add(SP_ATTR_MODE, _("Mode"), BlendModeConverter);
1206 _settings->type(NR_FILTER_COMPOSITE);
1207 _settings->add(SP_ATTR_OPERATOR, _("Operator"), CompositeOperatorConverter);
1208 _k1 = _settings->add(SP_ATTR_K1, _("K1"), -10, 10, 1, 0.01, 1);
1209 _k2 = _settings->add(SP_ATTR_K2, _("K2"), -10, 10, 1, 0.01, 1);
1210 _k3 = _settings->add(SP_ATTR_K3, _("K3"), -10, 10, 1, 0.01, 1);
1211 _k4 = _settings->add(SP_ATTR_K4, _("K4"), -10, 10, 1, 0.01, 1);
1213 _settings->type(NR_FILTER_CONVOLVEMATRIX);
1214 _convolve_order = _settings->add(SP_ATTR_ORDER, _("Size"), "", 1, 5, 1, 1, 0);
1215 _convolve_order->remove_scale();
1216 _settings->combine();
1217 _convolve_tx = _settings->add(SP_ATTR_TARGETX, _("Target"), 0, 4, 1, 1, 0);
1218 _convolve_tx->remove_scale();
1219 _convolve_ty = _settings->add(SP_ATTR_TARGETY, "", 0, 4, 1, 1, 0);
1220 _convolve_ty->remove_scale();
1221 _settings->combine();
1222 _convolve_matrix = _settings->add(SP_ATTR_KERNELMATRIX, _("Kernel"));
1223 _convolve_order->signal_value_changed().connect(sigc::mem_fun(*this, &FilterEffectsDialog::convolve_order_changed));
1224 _settings->add(SP_ATTR_DIVISOR, _("Divisor"), 0.01, 10, 1, 0.01, 1);
1225 _settings->add(SP_ATTR_BIAS, _("Bias"), -10, 10, 1, 0.01, 1);
1227 _settings->type(NR_FILTER_DIFFUSELIGHTING);
1228 _settings->add_color(SP_PROP_LIGHTING_COLOR, _("Diffuse Color"));
1229 _settings->add(SP_ATTR_SURFACESCALE, _("Surface Scale"), -10, 10, 1, 0.01, 1);
1230 _settings->add(SP_ATTR_DIFFUSECONSTANT, _("Constant"), 0, 100, 1, 0.01, 1);
1231 _settings->add(SP_ATTR_KERNELUNITLENGTH, _("Kernel Unit Length X"), _("Kernel Unit Length Y"), 0.01, 10, 1, 0.01, 1);
1233 _settings->type(NR_FILTER_GAUSSIANBLUR);
1234 _settings->add(SP_ATTR_STDDEVIATION, _("Standard Deviation X"), _("Standard Deviation Y"), 0.01, 100, 1, 0.01, 1);
1236 _settings->type(NR_FILTER_OFFSET);
1237 _settings->add(SP_ATTR_DX, _("Delta X"), -100, 100, 1, 0.01, 1);
1238 _settings->add(SP_ATTR_DY, _("Delta Y"), -100, 100, 1, 0.01, 1);
1240 _settings->type(NR_FILTER_SPECULARLIGHTING);
1241 _settings->add_color(SP_PROP_LIGHTING_COLOR, _("Specular Color"));
1242 _settings->add(SP_ATTR_SURFACESCALE, _("Surface Scale"), -10, 10, 1, 0.01, 1);
1243 _settings->add(SP_ATTR_SPECULARCONSTANT, _("Constant"), 0, 100, 1, 0.01, 1);
1244 _settings->add(SP_ATTR_SPECULAREXPONENT, _("Exponent"), 1, 128, 1, 0.01, 1);
1245 _settings->add(SP_ATTR_KERNELUNITLENGTH, _("Kernel Unit Length X"), _("Kernel Unit Length Y"), 0.01, 10, 1, 0.01, 1);
1247 _settings->type(NR_FILTER_TURBULENCE);
1248 /*std::vector<Gtk::Widget*> trb_grp;
1249 trb_grp.push_back(&_turbulence_fractalnoise);
1250 trb_grp.push_back(&_turbulence_turbulence);
1251 _settings->add(trb_grp);
1252 _turbulence.add_setting(_turbulence_numoctaves, _("Octaves"));
1253 _turbulence.add_setting(_turbulence_basefrequency, _("Base Frequency"));
1254 _turbulence.add_setting(_turbulence_seed, _("Seed"));
1255 _turbulence.add_setting(_turbulence_stitchtiles);*/
1256 }
1258 void FilterEffectsDialog::add_primitive()
1259 {
1260 SPFilter* filter = _filter_modifier.get_selected_filter();
1262 if(filter) {
1263 SPFilterPrimitive* prim = filter_add_primitive(filter, _add_primitive_type.get_active_data()->id);
1265 _primitive_list.update();
1266 _primitive_list.select(prim);
1268 sp_document_done(filter->document, SP_VERB_DIALOG_FILTER_EFFECTS, _("Add filter primitive"));
1269 }
1270 }
1272 void FilterEffectsDialog::remove_primitive()
1273 {
1274 SPFilterPrimitive* prim = _primitive_list.get_selected();
1276 if(prim) {
1277 sp_repr_unparent(prim->repr);
1279 sp_document_done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_DIALOG_FILTER_EFFECTS,
1280 _("Remove filter primitive"));
1282 _primitive_list.update();
1283 }
1284 }
1286 void FilterEffectsDialog::duplicate_primitive()
1287 {
1288 SPFilter* filter = _filter_modifier.get_selected_filter();
1289 SPFilterPrimitive* origprim = _primitive_list.get_selected();
1291 if(filter && origprim) {
1292 Inkscape::XML::Node *repr;
1293 repr = SP_OBJECT_REPR(origprim)->duplicate(SP_OBJECT_REPR(origprim)->document());
1294 SP_OBJECT_REPR(filter)->appendChild(repr);
1296 sp_document_done(filter->document, SP_VERB_DIALOG_FILTER_EFFECTS, _("Duplicate filter primitive"));
1298 _primitive_list.update();
1299 }
1300 }
1302 void FilterEffectsDialog::convolve_order_changed()
1303 {
1304 _convolve_matrix->update(SP_FECONVOLVEMATRIX(_primitive_list.get_selected()));
1305 _convolve_tx->get_adjustment().set_upper(_convolve_order->get_spinslider1().get_value());
1306 _convolve_ty->get_adjustment().set_upper(_convolve_order->get_spinslider2().get_value());
1307 }
1309 void FilterEffectsDialog::set_attr_direct(const SPAttributeEnum attr, const AttrWidget* input)
1310 {
1311 set_attr(attr, input->get_as_attribute().c_str());
1312 }
1314 void FilterEffectsDialog::set_attr(const SPAttributeEnum attr, const gchar* val)
1315 {
1316 if(!_locked) {
1317 SPFilter *filter = _filter_modifier.get_selected_filter();
1318 SPFilterPrimitive* prim = _primitive_list.get_selected();
1320 if(filter && prim) {
1321 update_settings_sensitivity();
1323 const gchar* name = (const gchar*)sp_attribute_name(attr);
1324 SP_OBJECT_REPR(prim)->setAttribute(name, val);
1325 filter->requestModified(SP_OBJECT_MODIFIED_FLAG);
1327 Glib::ustring undokey = "filtereffects:";
1328 undokey += name;
1329 sp_document_maybe_done(filter->document, undokey.c_str(), SP_VERB_DIALOG_FILTER_EFFECTS,
1330 _("Set filter primitive attribute"));
1331 }
1332 }
1333 }
1335 void FilterEffectsDialog::update_settings_view()
1336 {
1337 SPFilterPrimitive* prim = _primitive_list.get_selected();
1339 // Hide all the settings
1340 _settings_box.hide_all();
1341 _settings_box.show();
1343 _settings_box.set_sensitive(false);
1344 _empty_settings.show();
1346 if(prim) {
1347 const FilterPrimitiveType tid = FPConverter.get_id_from_key(prim->repr->name());
1349 _settings->show_and_update(tid);
1351 _settings_box.set_sensitive(true);
1352 _empty_settings.hide();
1353 }
1355 update_settings_sensitivity();
1356 }
1358 void FilterEffectsDialog::update_settings_sensitivity()
1359 {
1360 SPFilterPrimitive* prim = _primitive_list.get_selected();
1361 const bool use_k = SP_IS_FECOMPOSITE(prim) && SP_FECOMPOSITE(prim)->composite_operator == COMPOSITE_ARITHMETIC;
1362 _k1->set_sensitive(use_k);
1363 _k2->set_sensitive(use_k);
1364 _k3->set_sensitive(use_k);
1365 _k4->set_sensitive(use_k);
1366 }
1368 } // namespace Dialog
1369 } // namespace UI
1370 } // namespace Inkscape
1372 /*
1373 Local Variables:
1374 mode:c++
1375 c-file-style:"stroustrup"
1376 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1377 indent-tabs-mode:nil
1378 fill-column:99
1379 End:
1380 */
1381 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :