index c205bf930ddf7ad91cc22d5d8b022be29eeb5faa..a233a0ed408f7760dfaffc8ed85f1c9db30959ec 100644 (file)
void FilterEffectsDialog::FilterModifier::duplicate_filter()
{
- SPFilter *filter = get_selected_filter();
+ SPFilter* filter = get_selected_filter();
if(filter) {
- //SPFilter *dupfilter = filter_duplicate(sp_desktop_document(SP_ACTIVE_DESKTOP), filter);
+ Inkscape::XML::Node* repr = SP_OBJECT_REPR(filter), *parent = repr->parent();
+ repr = repr->duplicate(repr->document());
+ parent->appendChild(repr);
sp_document_done(filter->document, SP_VERB_DIALOG_FILTER_EFFECTS, _("Duplicate filter"));
@@ -191,8 +193,7 @@ void FilterEffectsDialog::FilterModifier::filter_name_edited(const Glib::ustring
FilterEffectsDialog::CellRendererConnection::CellRendererConnection()
: Glib::ObjectBase(typeid(CellRendererConnection)),
_primitive(*this, "primitive", 0)
-{
-}
+{}
Glib::PropertyProxy<void*> FilterEffectsDialog::CellRendererConnection::property_primitive()
{
@@ -215,6 +216,16 @@ int FilterEffectsDialog::CellRendererConnection::input_count(const SPFilterPrimi
return 1;
}
+void FilterEffectsDialog::CellRendererConnection::set_text_width(const int w)
+{
+ _text_width = w;
+}
+
+int FilterEffectsDialog::CellRendererConnection::get_text_width() const
+{
+ return _text_width;
+}
+
void FilterEffectsDialog::CellRendererConnection::get_size_vfunc(
Gtk::Widget& widget, const Gdk::Rectangle* cell_area,
int* x_offset, int* y_offset, int* width, int* height) const
if(y_offset)
(*y_offset) = 0;
if(width)
- (*width) = size * primlist.primitive_count();
+ (*width) = size * primlist.primitive_count() + _text_width * 7;
if(height) {
// Scale the height depending on the number of inputs, unless it's
- // the first primitive, in which case their are no connections
+ // the first primitive, in which case there are no connections
SPFilterPrimitive* prim = (SPFilterPrimitive*)_primitive.get_value();
- (*height) = primlist.is_first(prim) ? size : size * input_count(prim);
+ (*height) = size * input_count(prim);
}
}
/*** PrimitiveList ***/
FilterEffectsDialog::PrimitiveList::PrimitiveList(FilterEffectsDialog& d)
- : _dialog(d), _in_drag(0)
+ : _dialog(d),
+ _in_drag(0)
{
add_events(Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
+ signal_expose_event().connect(sigc::mem_fun(*this, &PrimitiveList::on_expose_signal));
_model = Gtk::ListStore::create(_columns);
- // TODO: reenable this once it is possible to modify the order in the backend
- //set_reorderable(true);
+ set_reorderable(true);
set_model(_model);
append_column(_("_Type"), _columns.type);
signal_selection_changed().connect(sigc::mem_fun(*this, &PrimitiveList::queue_draw));
- CellRendererConnection* cell = new CellRendererConnection;
- int cols_count = append_column("Connections", *cell);
+ _connection_cell.set_text_width(init_text());
+
+ int cols_count = append_column(_("Connections"), _connection_cell);
Gtk::TreeViewColumn* col = get_column(cols_count - 1);
if(col)
- col->add_attribute(cell->property_primitive(), _columns.primitive);
+ col->add_attribute(_connection_cell.property_primitive(), _columns.primitive);
+}
+
+// Sets up a vertical Pango context/layout, and returns the largest
+// width needed to render the FilterPrimitiveInput labels.
+int FilterEffectsDialog::PrimitiveList::init_text()
+{
+ // Set up a vertical context+layout
+ Glib::RefPtr<Pango::Context> context = create_pango_context();
+ const Pango::Matrix matrix = {0, -1, 1, 0, 0, 0};
+ context->set_matrix(matrix);
+ _vertical_layout = Pango::Layout::create(context);
+
+ int maxfont = 0;
+ for(int i = 0; i < FPInputConverter.end; ++i) {
+ _vertical_layout->set_text(FPInputConverter.get_label((FilterPrimitiveInput)i));
+ int fontw, fonth;
+ _vertical_layout->get_pixel_size(fontw, fonth);
+ if(fonth > maxfont)
+ maxfont = fonth;
+ }
+
+ return maxfont;
}
Glib::SignalProxy0<void> FilterEffectsDialog::PrimitiveList::signal_selection_changed()
if(prim) {
Gtk::TreeModel::Row row = *_model->append();
row[_columns.primitive] = prim;
- row[_columns.type_id] = FPConverter.get_id_from_name(prim->repr->name());
+ row[_columns.type_id] = FPConverter.get_id_from_key(prim->repr->name());
row[_columns.type] = FPConverter.get_label(row[_columns.type_id]);
row[_columns.id] = SP_OBJECT_ID(prim);
}
}
-bool FilterEffectsDialog::PrimitiveList::on_expose_event(GdkEventExpose* e)
+
+
+bool FilterEffectsDialog::PrimitiveList::on_expose_signal(GdkEventExpose* e)
{
- Gtk::TreeView::on_expose_event(e);
+ Gdk::Rectangle clip(e->area.x, e->area.y, e->area.width, e->area.height);
+ Glib::RefPtr<Gdk::Window> win = get_bin_window();
+ Glib::RefPtr<Gdk::GC> darkgc = get_style()->get_dark_gc(Gtk::STATE_NORMAL);
SPFilterPrimitive* prim = get_selected();
+ int row_count = get_model()->children().size();
+
+ int fheight = CellRendererConnection::size;
+ Gdk::Rectangle rct, vis;
+ Gtk::TreeIter row = get_model()->children().begin();
+ int text_start_x = 0;
+ if(row) {
+ get_cell_area(get_model()->get_path(row), *get_column(1), rct);
+ get_visible_rect(vis);
+ int vis_x, vis_y;
+ tree_to_widget_coords(vis.get_x(), vis.get_y(), vis_x, vis_y);
+
+ text_start_x = rct.get_x() + row_count * fheight;
+ for(int i = 0; i < FPInputConverter.end; ++i) {
+ _vertical_layout->set_text(FPInputConverter.get_label((FilterPrimitiveInput)i));
+ const int x = text_start_x + _connection_cell.get_text_width() * (i + 1);
+ get_bin_window()->draw_layout(get_style()->get_text_gc(Gtk::STATE_NORMAL), x, vis_y, _vertical_layout);
+ get_bin_window()->draw_line(darkgc, x, vis_y, x, vis_y + vis.get_height());
+ }
+ }
int row_index = 0;
- int row_count = get_model()->children().size();
- int fheight = 0;
- for(Gtk::TreeIter row = get_model()->children().begin();
- row != get_model()->children().end(); ++row, ++row_index) {
- Gdk::Rectangle rct, clip(&e->area);
+ for(; row != get_model()->children().end(); ++row, ++row_index) {
get_cell_area(get_model()->get_path(row), *get_column(1), rct);
const int x = rct.get_x(), y = rct.get_y(), h = rct.get_height();
- // For calculating the width of cells, the height of the first row is used
- if(row_index == 0)
- fheight = h;
-
// Check mouse state
int mx, my;
Gdk::ModifierType mask;
// Outline the bottom of the connection area
const int outline_x = x + fheight * (row_count - row_index);
- get_bin_window()->draw_line(get_style()->get_dark_gc(Gtk::STATE_NORMAL),
- x, y + h, outline_x, y + h);
-
- // The first row can't have any inputs
- if(row_index == 0)
- continue;
+ get_bin_window()->draw_line(darkgc, x, y + h, outline_x, y + h);
// Side outline
- get_bin_window()->draw_line(get_style()->get_dark_gc(Gtk::STATE_NORMAL),
- outline_x, y, outline_x, y + h);
+ get_bin_window()->draw_line(darkgc, outline_x, y, outline_x, y + h);
std::vector<Gdk::Point> con_poly;
int con_drag_y;
for(int i = 0; i < inputs; ++i) {
inside = do_connection_node(row, i, con_poly, mx, my);
get_bin_window()->draw_polygon(inside && mask & GDK_BUTTON1_MASK ?
- get_style()->get_dark_gc(Gtk::STATE_NORMAL) :
- get_style()->get_dark_gc(Gtk::STATE_ACTIVE),
+ darkgc : get_style()->get_dark_gc(Gtk::STATE_ACTIVE),
inside, con_poly);
// TODO: draw connections for each of the feMergeNodes
inside = do_connection_node(row, 0, con_poly, mx, my);
con_drag_y = con_poly[2].get_y();
get_bin_window()->draw_polygon(inside && mask & GDK_BUTTON1_MASK ?
- get_style()->get_dark_gc(Gtk::STATE_NORMAL) :
- get_style()->get_dark_gc(Gtk::STATE_ACTIVE),
+ darkgc : get_style()->get_dark_gc(Gtk::STATE_ACTIVE),
inside, con_poly);
// Draw "in" connection
- draw_connection(find_result(row, SP_ATTR_IN), outline_x, con_poly[2].get_y(), row_count);
+ if(_in_drag != 1 || row_prim != prim)
+ draw_connection(row, SP_ATTR_IN, text_start_x, outline_x, con_poly[2].get_y(), row_count);
if(inputs == 2) {
// Draw "in2" shape
if(_in_drag == 2)
con_drag_y = con_poly[2].get_y();
get_bin_window()->draw_polygon(inside && mask & GDK_BUTTON1_MASK ?
- get_style()->get_dark_gc(Gtk::STATE_NORMAL) :
- get_style()->get_dark_gc(Gtk::STATE_ACTIVE),
+ darkgc : get_style()->get_dark_gc(Gtk::STATE_ACTIVE),
inside, con_poly);
// Draw "in2" connection
- draw_connection(find_result(row, SP_ATTR_IN2), outline_x, con_poly[2].get_y(), row_count);
+ if(_in_drag != 2 || row_prim != prim)
+ draw_connection(row, SP_ATTR_IN2, text_start_x, outline_x, con_poly[2].get_y(), row_count);
}
// Draw drag connection
return true;
}
-void FilterEffectsDialog::PrimitiveList::draw_connection(const Gtk::TreeIter& input, const int x1, const int y1,
+void FilterEffectsDialog::PrimitiveList::draw_connection(const Gtk::TreeIter& input, const SPAttributeEnum attr,
+ const int text_start_x, const int x1, const int y1,
const int row_count)
{
- if(input != _model->children().end()) {
+ const Gtk::TreeIter res = find_result(input, attr);
+ Glib::RefPtr<Gdk::GC> gc = get_style()->get_black_gc();
+
+ if(res == input) {
+ // Draw straight connection to a standard input
+ const int tw = _connection_cell.get_text_width();
+ const int src = 1 + (int)FPInputConverter.get_id_from_key(
+ SP_OBJECT_REPR((*res)[_columns.primitive])->attribute((const gchar*)sp_attribute_name(attr)));
+ get_bin_window()->draw_line(gc, x1, y1, text_start_x + tw * src + (int)(tw * 0.5f), y1);
+ }
+ else if(res != _model->children().end()) {
Gdk::Rectangle rct;
get_cell_area(get_model()->get_path(_model->children().begin()), *get_column(1), rct);
- const int fheight = rct.get_height();
+ const int fheight = CellRendererConnection::size;
- get_cell_area(get_model()->get_path(input), *get_column(1), rct);
- const int row_index = find_index(input);
+ get_cell_area(get_model()->get_path(res), *get_column(1), rct);
+ const int row_index = find_index(res);
const int x2 = rct.get_x() + fheight * (row_count - row_index) - fheight / 2;
const int y2 = rct.get_y() + rct.get_height();
- // Draw an 'L'-shaped connection
- get_bin_window()->draw_line(get_style()->get_black_gc(), x1, y1, x2, y1);
- get_bin_window()->draw_line(get_style()->get_black_gc(), x2, y1, x2, y2);
+ // Draw an 'L'-shaped connection to another filter primitive
+ get_bin_window()->draw_line(gc, x1, y1, x2, y1);
+ get_bin_window()->draw_line(gc, x2, y1, x2, y2);
}
}
@@ -446,7 +501,7 @@ bool FilterEffectsDialog::PrimitiveList::do_connection_node(const Gtk::TreeIter&
const int input_count = CellRendererConnection::input_count((*row)[_columns.primitive]);
get_cell_area(get_model()->get_path(_model->children().begin()), *get_column(1), rct);
- const int fheight = rct.get_height();
+ const int fheight = CellRendererConnection::size;
get_cell_area(_model->get_path(row), *get_column(1), rct);
const float h = rct.get_height() / input_count;
@@ -490,7 +545,10 @@ const Gtk::TreeIter FilterEffectsDialog::PrimitiveList::find_result(const Gtk::T
if(((SPFilterPrimitive*)(*i)[_columns.primitive])->image_out == image)
target = i;
}
+ return target;
}
+ else if(image < -1)
+ return start;
return target;
}
@@ -509,18 +567,27 @@ bool FilterEffectsDialog::PrimitiveList::on_button_press_event(GdkEventButton* e
Gtk::TreeViewColumn* col;
const int x = (int)e->x, y = (int)e->y;
int cx, cy;
+
+ _drag_prim = 0;
if(get_path_at_pos(x, y, path, col, cx, cy)) {
+ Gtk::TreeIter iter = _model->get_iter(path);
std::vector<Gdk::Point> points;
if(do_connection_node(_model->get_iter(path), 0, points, x, y))
_in_drag = 1;
else if(do_connection_node(_model->get_iter(path), 1, points, x, y))
_in_drag = 2;
-
+
queue_draw();
+ _drag_prim = (*iter)[_columns.primitive];
}
- return Gtk::TreeView::on_button_press_event(e);
+ if(_in_drag) {
+ get_selection()->select(path);
+ return true;
+ }
+ else
+ return Gtk::TreeView::on_button_press_event(e);
}
bool FilterEffectsDialog::PrimitiveList::on_motion_notify_event(GdkEventMotion* e)
@@ -540,20 +607,47 @@ bool FilterEffectsDialog::PrimitiveList::on_button_release_event(GdkEventButton*
int cx, cy;
if(get_path_at_pos((int)e->x, (int)e->y, path, col, cx, cy)) {
- target = (*_model->get_iter(path))[_columns.primitive];
- Inkscape::XML::Node *repr = SP_OBJECT_REPR(target);
- // Make sure the target has a result
- const gchar *gres = repr->attribute("result");
- Glib::ustring result = gres ? gres : "";
- if(!gres) {
- result = "result" + Glib::Ascii::dtostr(SP_FILTER(prim->parent)->_image_number_next);
- repr->setAttribute("result", result.c_str());
+ const gchar *in_val = 0;
+ Glib::ustring result;
+ Gtk::TreeIter target_iter = _model->get_iter(path);
+ target = (*target_iter)[_columns.primitive];
+
+ const int sources_x = CellRendererConnection::size * _model->children().size() +
+ _connection_cell.get_text_width();
+
+ if(cx > sources_x) {
+ int src = (cx - sources_x) / _connection_cell.get_text_width();
+ if(src < 0)
+ src = 1;
+ else if(src >= FPInputConverter.end)
+ src = FPInputConverter.end - 1;
+ result = FPInputConverter.get_key((FilterPrimitiveInput)src);
+ in_val = result.c_str();
+ }
+ else {
+ // Ensure that the target comes before the selected primitive
+ for(Gtk::TreeIter iter = _model->children().begin();
+ iter != get_selection()->get_selected(); ++iter) {
+ if(iter == target_iter) {
+ Inkscape::XML::Node *repr = SP_OBJECT_REPR(target);
+ // Make sure the target has a result
+ const gchar *gres = repr->attribute("result");
+ if(!gres) {
+ result = "result" + Glib::Ascii::dtostr(SP_FILTER(prim->parent)->_image_number_next);
+ repr->setAttribute("result", result.c_str());
+ in_val = result.c_str();
+ }
+ else
+ in_val = gres;
+ break;
+ }
+ }
}
if(_in_drag == 1)
- SP_OBJECT_REPR(prim)->setAttribute("in", result.c_str());
+ _dialog.set_attr(SP_ATTR_IN, in_val);
else if(_in_drag == 2)
- SP_OBJECT_REPR(prim)->setAttribute("in2", result.c_str());
+ _dialog.set_attr(SP_ATTR_IN2, in_val);
}
_in_drag = 0;
@@ -574,18 +668,65 @@ bool FilterEffectsDialog::PrimitiveList::on_button_release_event(GdkEventButton*
return Gtk::TreeView::on_button_release_event(e);
}
+// Checks all of prim's inputs, removes any that use result
+void check_single_connection(SPFilterPrimitive* prim, const int result)
+{
+ if(prim && result >= 0) {
+
+ if(prim->image_in == result)
+ SP_OBJECT_REPR(prim)->setAttribute("in", 0);
+
+ if(SP_IS_FEBLEND(prim)) {
+ if(SP_FEBLEND(prim)->in2 == result)
+ SP_OBJECT_REPR(prim)->setAttribute("in2", 0);
+ }
+ else if(SP_IS_FECOMPOSITE(prim)) {
+ if(SP_FECOMPOSITE(prim)->in2 == result)
+ SP_OBJECT_REPR(prim)->setAttribute("in2", 0);
+ }
+ }
+}
+
+// Remove any connections going to/from prim_iter that forward-reference other primitives
+void FilterEffectsDialog::PrimitiveList::sanitize_connections(const Gtk::TreeIter& prim_iter)
+{
+ SPFilterPrimitive *prim = (*prim_iter)[_columns.primitive];
+ bool before = true;
+
+ for(Gtk::TreeIter iter = _model->children().begin();
+ iter != _model->children().end(); ++iter) {
+ if(iter == prim_iter)
+ before = false;
+ else {
+ SPFilterPrimitive* cur_prim = (*iter)[_columns.primitive];
+ if(before)
+ check_single_connection(cur_prim, prim->image_out);
+ else
+ check_single_connection(prim, cur_prim->image_out);
+ }
+ }
+}
+
// Reorder the filter primitives to match the list order
void FilterEffectsDialog::PrimitiveList::on_drag_end(const Glib::RefPtr<Gdk::DragContext>&)
{
SPFilter* filter = _dialog._filter_modifier.get_selected_filter();
+ int ndx = 0;
for(Gtk::TreeModel::iterator iter = _model->children().begin();
- iter != _model->children().end(); ++iter) {
+ iter != _model->children().end(); ++iter, ++ndx) {
SPFilterPrimitive* prim = (*iter)[_columns.primitive];
- if(prim)
- ;//reorder_primitive(filter, prim->repr->position(), ndx); /* FIXME */
+ if(prim) {
+ SP_OBJECT_REPR(prim)->setPosition(ndx);
+ if(_drag_prim == prim) {
+ sanitize_connections(iter);
+ get_selection()->select(iter);
+ }
+ }
}
+ filter->requestModified(SP_OBJECT_MODIFIED_FLAG);
+
sp_document_done(filter->document, SP_VERB_DIALOG_FILTER_EFFECTS, _("Reorder filter primitive"));
}
return _model->children().size();
}
-bool FilterEffectsDialog::PrimitiveList::is_first(const SPFilterPrimitive* prim) const
-{
- return (*_model->children().begin())[_columns.primitive] == prim;
-}
-
/*** SettingsGroup ***/
FilterEffectsDialog::SettingsGroup::SettingsGroup()
{
@@ -650,6 +786,82 @@ void FilterEffectsDialog::SettingsGroup::add_setting(std::vector<Gtk::Widget*>&
add_setting_generic(*hb, label);
}
+/*** ConvolveMatrix ***/
+FilterEffectsDialog::ConvolveMatrixColumns::ConvolveMatrixColumns()
+{
+ cols.resize(5);
+ for(unsigned i = 0; i < cols.size(); ++i)
+ add(cols[i]);
+}
+
+FilterEffectsDialog::ConvolveMatrix::ConvolveMatrix()
+{
+ _model = Gtk::ListStore::create(_columns);
+ set_model(_model);
+ set_headers_visible(false);
+}
+
+sigc::signal<void>& FilterEffectsDialog::ConvolveMatrix::signal_changed()
+{
+ return _signal_changed;
+}
+
+Glib::ustring FilterEffectsDialog::ConvolveMatrix::get_value() const
+{
+ std::ostringstream os;
+
+ for(Gtk::TreeIter iter = _model->children().begin();
+ iter != _model->children().end(); ++iter) {
+ for(unsigned c = 0; c < get_columns().size(); ++c) {
+ os << (*iter)[_columns.cols[c]] << " ";
+ }
+ }
+
+ return os.str();
+}
+
+void FilterEffectsDialog::ConvolveMatrix::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);
+ }
+}
+
+void FilterEffectsDialog::ConvolveMatrix::update(SPFeConvolveMatrix* conv, const int rows, const int cols)
+{
+ _model->clear();
+
+ remove_all_columns();
+
+ if(conv) {
+ 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));
+ }
+
+ 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;
+ }
+ }
+}
+
+void FilterEffectsDialog::ConvolveMatrix::rebind(const Glib::ustring&, const Glib::ustring&)
+{
+ _signal_changed();
+}
+
/*** FilterEffectsDialog ***/
FilterEffectsDialog::FilterEffectsDialog()
_add_primitive_type(FPConverter),
_add_primitive(Gtk::Stock::ADD),
_settings_labels(Gtk::SizeGroup::create(Gtk::SIZE_GROUP_HORIZONTAL)),
- _empty_settings("No primitive selected", Gtk::ALIGN_LEFT),
+ _empty_settings(_("No primitive selected"), Gtk::ALIGN_LEFT),
// TODO: Find better range/climb-rate/digits values for the SpinSliders,
// many of the current values are just guesses
_blend_mode(BlendModeConverter),
_composite_k2(0, -10, 10, 1, 0.01, 1),
_composite_k3(0, -10, 10, 1, 0.01, 1),
_composite_k4(0, -10, 10, 1, 0.01, 1),
+ _convolve_orderx(1, 0),
+ _convolve_ordery(1, 0),
+ _convolve_divisor(1, 0.01, 10, 1, 0.01, 1),
+ _convolve_bias(0, -10, 10, 1, 0.01, 1),
_gaussianblur_stddeviation(1, 0, 100, 1, 0.01, 1),
_morphology_radius(1, 0, 100, 1, 0.01, 1),
_offset_dx(0, -100, 100, 1, 0.01, 1),
Gtk::HPaned* hpaned = Gtk::manage(new Gtk::HPaned);
Gtk::ScrolledWindow* sw_prims = Gtk::manage(new Gtk::ScrolledWindow);
Gtk::HBox* hb_prims = Gtk::manage(new Gtk::HBox);
- Gtk::Frame* fr_settings = Gtk::manage(new Gtk::Frame("<b>Settings</b>"));
+ Gtk::Frame* fr_settings = Gtk::manage(new Gtk::Frame(_("<b>Settings</b>")));
Gtk::Alignment* al_settings = Gtk::manage(new Gtk::Alignment);
get_vbox()->add(*hpaned);
hpaned->pack1(_filter_modifier);
_empty_settings.set_sensitive(false);
_settings.pack_start(_empty_settings);
- _generic_settings.init(this, _settings_labels);
- _generic_settings.add_setting_generic(_primitive_input1, "Input");
- _primitive_input1.signal_changed().connect(
- sigc::bind(sigc::mem_fun(*this, &FilterEffectsDialog::set_attr_special), SP_ATTR_IN));
- _primitive_input1.append_text("Default");
- _primitive_input1.append_text("Source Graphic");
- _primitive_input1.append_text("Source Alpha");
- _primitive_input1.append_text("Background Image");
- _primitive_input1.append_text("Background Alpha");
- _primitive_input1.append_text("Fill Paint");
- _primitive_input1.append_text("Stroke Paint");
- _primitive_input1.append_text("Connection");
-
_blend.init(this, _settings_labels);
- _blend.add_setting(_blend_mode, SP_ATTR_MODE, "Mode");
+ _blend.add_setting(_blend_mode, SP_ATTR_MODE, _("Mode"));
_colormatrix.init(this, _settings_labels);
- //_colormatrix.add_setting(_colormatrix_type, "Type");
+ //_colormatrix.add_setting(_colormatrix_type, _("Type"));
_componenttransfer.init(this, _settings_labels);
_composite.init(this, _settings_labels);
- _composite.add_setting(_composite_operator, SP_ATTR_OPERATOR, "Operator");
- _composite.add_setting(_composite_k1, SP_ATTR_K1, "K1");
- _composite.add_setting(_composite_k2, SP_ATTR_K2, "K2");
- _composite.add_setting(_composite_k3, SP_ATTR_K3, "K3");
- _composite.add_setting(_composite_k4, SP_ATTR_K4, "K4");
+ _composite.add_setting(_composite_operator, SP_ATTR_OPERATOR, _("Operator"));
+ _composite.add_setting(_composite_k1, SP_ATTR_K1, _("K1"));
+ _composite.add_setting(_composite_k2, SP_ATTR_K2, _("K2"));
+ _composite.add_setting(_composite_k3, SP_ATTR_K3, _("K3"));
+ _composite.add_setting(_composite_k4, SP_ATTR_K4, _("K4"));
_convolvematrix.init(this, _settings_labels);
+ _convolvematrix.add_setting_generic(_convolve_orderx, _("Rows"));
+ _convolve_orderx.set_range(1, 5);
+ _convolve_orderx.get_adjustment()->set_step_increment(1);
+ _convolve_orderx.signal_value_changed().connect(
+ sigc::bind(sigc::mem_fun(*this, &FilterEffectsDialog::set_attr_special), SP_ATTR_ORDER));
+ _convolvematrix.add_setting_generic(_convolve_ordery, _("Columns"));
+ _convolve_ordery.set_range(1, 5);
+ _convolve_ordery.get_adjustment()->set_step_increment(1);
+ _convolve_ordery.signal_value_changed().connect(
+ sigc::bind(sigc::mem_fun(*this, &FilterEffectsDialog::set_attr_special), SP_ATTR_ORDER));
+ Gtk::ScrolledWindow* sw = Gtk::manage(new Gtk::ScrolledWindow);
+ sw->add(_convolve_kernelmatrix);
+ sw->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+ sw->set_shadow_type(Gtk::SHADOW_IN);
+ _convolvematrix.add_setting_generic(*sw, _("Kernel"));
+ _convolve_kernelmatrix.signal_changed().connect(
+ sigc::bind(sigc::mem_fun(*this, &FilterEffectsDialog::set_attr_special), SP_ATTR_KERNELMATRIX));
+ //_convolvematrix.add_setting(_convolve_divisor, SP_ATTR_DIVISOR, _("Divisor"));
+ //_convolvematrix.add_setting(_convolve_bias, SP_ATTR_BIAS, _("Bias"));
_diffuselighting.init(this, _settings_labels);
_flood.init(this, _settings_labels);
_gaussianblur.init(this, _settings_labels);
- _gaussianblur.add_setting(_gaussianblur_stddeviation, SP_ATTR_STDDEVIATION, "Standard Deviation");
+ _gaussianblur.add_setting(_gaussianblur_stddeviation, SP_ATTR_STDDEVIATION, _("Standard Deviation"));
_image.init(this, _settings_labels);
_merge.init(this, _settings_labels);
_morphology.init(this, _settings_labels);
- //_morphology.add_setting(_morphology_operator, "Operator");
- //_morphology.add_setting(_morphology_radius, "Radius");
+ //_morphology.add_setting(_morphology_operator, _("Operator"));
+ //_morphology.add_setting(_morphology_radius, _("Radius"));
_offset.init(this, _settings_labels);
- _offset.add_setting(_offset_dx, SP_ATTR_DX, "Delta X");
- _offset.add_setting(_offset_dy, SP_ATTR_DY, "Delta Y");
+ _offset.add_setting(_offset_dx, SP_ATTR_DX, _("Delta X"));
+ _offset.add_setting(_offset_dy, SP_ATTR_DY, _("Delta Y"));
_specularlighting.init(this, _settings_labels);
trb_grp.push_back(&_turbulence_fractalnoise);
trb_grp.push_back(&_turbulence_turbulence);
_turbulence.add_setting(trb_grp);
- /*_turbulence.add_setting(_turbulence_numoctaves, "Octaves");
- _turbulence.add_setting(_turbulence_basefrequency, "Base Frequency");
- _turbulence.add_setting(_turbulence_seed, "Seed");
+ /*_turbulence.add_setting(_turbulence_numoctaves, _("Octaves"));
+ _turbulence.add_setting(_turbulence_basefrequency, _("Base Frequency"));
+ _turbulence.add_setting(_turbulence_seed, _("Seed"));
_turbulence.add_setting(_turbulence_stitchtiles);*/
}
void FilterEffectsDialog::add_primitive()
{
SPFilter* filter = _filter_modifier.get_selected_filter();
- const EnumData<NR::FilterPrimitiveType>* data = _add_primitive_type.get_active_data();
- if(filter && data) {
- SPFilterPrimitive* prim = filter_add_primitive(filter, data->name.c_str());
-
- // Set default values
- switch(data->id) {
- case NR::NR_FILTER_BLEND:
- sp_object_set(prim, SP_ATTR_MODE, BlendModeConverter.get_name(NR::BLEND_NORMAL).c_str());
- break;
- case NR::NR_FILTER_COLORMATRIX:
- break;
- case NR::NR_FILTER_COMPONENTTRANSFER:
- break;
- case NR::NR_FILTER_COMPOSITE:
- break;
- case NR::NR_FILTER_CONVOLVEMATRIX:
- break;
- case NR::NR_FILTER_DIFFUSELIGHTING:
- break;
- case NR::NR_FILTER_DISPLACEMENTMAP:
- break;
- case NR::NR_FILTER_FLOOD:
- break;
- case NR::NR_FILTER_GAUSSIANBLUR:
- sp_object_set(prim, SP_ATTR_STDDEVIATION, "1");
- break;
- case NR::NR_FILTER_IMAGE:
- break;
- case NR::NR_FILTER_MERGE:
- break;
- case NR::NR_FILTER_MORPHOLOGY:
- break;
- case NR::NR_FILTER_OFFSET:
- sp_object_set(prim, SP_ATTR_DX, "0");
- sp_object_set(prim, SP_ATTR_DY, "0");
- break;
- case NR::NR_FILTER_SPECULARLIGHTING:
- break;
- case NR::NR_FILTER_TILE:
- break;
- case NR::NR_FILTER_TURBULENCE:
- break;
- default:
- break;
- }
+ if(filter) {
+ SPFilterPrimitive* prim = filter_add_primitive(filter, _add_primitive_type.get_active_data()->id);
_primitive_list.update();
_primitive_list.select(prim);
@@ -884,41 +1063,36 @@ void FilterEffectsDialog::set_attr_spinslider(const SPAttributeEnum attr, const
if(input->is_sensitive()) {
std::ostringstream os;
os << input->get_value();
- set_attr(attr, os.str());
+ set_attr(attr, os.str().c_str());
}
}
void FilterEffectsDialog::set_attr_special(const SPAttributeEnum attr)
{
Glib::ustring val;
+ std::ostringstream os;
switch(attr) {
- case SP_ATTR_IN:
- val = _primitive_input1.get_active_text();
- if(val == "Default") {
- val = "";
- }
- else if(val == "Connection") {
- return;
- }
- else {
- val.erase(val.find(" "), 1);
- for(Glib::ustring::size_type i = 0; i < val.size(); ++i) {
- if(val[i] == ' ') {
- val.erase(i, i + 1);
- break;
- }
- }
- }
+ case SP_ATTR_ORDER:
+ {
+ int x = (int)(_convolve_orderx.get_value() + 0.5f);
+ int y = (int)(_convolve_ordery.get_value() + 0.5f);
+ os << x << " " << y;
+ val = os.str();
+ _convolve_kernelmatrix.update(SP_FECONVOLVEMATRIX(_primitive_list.get_selected()), x, y);
+ break;
+ }
+ case SP_ATTR_KERNELMATRIX:
+ val = _convolve_kernelmatrix.get_value();
break;
default:
return;
}
- set_attr(attr, val);
+ set_attr(attr, val.c_str());
}
-void FilterEffectsDialog::set_attr(const SPAttributeEnum attr, const Glib::ustring& val)
+void FilterEffectsDialog::set_attr(const SPAttributeEnum attr, const gchar* val)
{
SPFilter *filter = _filter_modifier.get_selected_filter();
SPFilterPrimitive* prim = _primitive_list.get_selected();
@@ -926,8 +1100,7 @@ void FilterEffectsDialog::set_attr(const SPAttributeEnum attr, const Glib::ustri
if(filter && prim) {
update_settings_sensitivity();
- SP_OBJECT_REPR(prim)->setAttribute((gchar*)sp_attribute_name(attr), val.c_str());
- sp_object_set(prim, attr, val.c_str());
+ SP_OBJECT_REPR(prim)->setAttribute((gchar*)sp_attribute_name(attr), val);
filter->requestModified(SP_OBJECT_MODIFIED_FLAG);
sp_document_done(filter->document, SP_VERB_DIALOG_FILTER_EFFECTS, _("Set filter primitive attribute"));
_empty_settings.show();
if(prim) {
- const NR::FilterPrimitiveType tid = FPConverter.get_id_from_name(prim->repr->name());
-
- _generic_settings.show_all();
- const gchar *attr_in_g = SP_OBJECT_REPR(prim)->attribute("in");
- const Glib::ustring attr_in = attr_in_g ? attr_in_g : "";
- if(attr_in == "")
- _primitive_input1.set_active(0);
- else if(attr_in == "SourceGraphic")
- _primitive_input1.set_active(1);
- else if(attr_in == "SourceAlpha")
- _primitive_input1.set_active(2);
- else if(attr_in == "BackgroundImage")
- _primitive_input1.set_active(3);
- else if(attr_in == "BackgroundAlpha")
- _primitive_input1.set_active(4);
- else if(attr_in == "Fill Paint")
- _primitive_input1.set_active(5);
- else if(attr_in == "Stroke Paint")
- _primitive_input1.set_active(6);
- else
- _primitive_input1.set_active(7);
+ const NR::FilterPrimitiveType tid = FPConverter.get_id_from_key(prim->repr->name());
if(tid == NR::NR_FILTER_BLEND) {
_blend.show_all();
const gchar* val = prim->repr->attribute("mode");
if(val)
- _blend_mode.set_active(BlendModeConverter.get_id_from_name(val));
+ _blend_mode.set_active(BlendModeConverter.get_id_from_key(val));
}
else if(tid == NR::NR_FILTER_COLORMATRIX)
_colormatrix.show_all();
_composite_k3.set_value(comp->k3);
_composite_k4.set_value(comp->k4);
}
- else if(tid == NR::NR_FILTER_CONVOLVEMATRIX)
+ else if(tid == NR::NR_FILTER_CONVOLVEMATRIX) {
_convolvematrix.show_all();
+ SPFeConvolveMatrix* conv = SP_FECONVOLVEMATRIX(prim);
+ _convolve_orderx.set_value(conv->order.getNumber());
+ _convolve_ordery.set_value(conv->order.optNumber_set ? conv->order.getOptNumber() : conv->order.getNumber());
+ _convolve_kernelmatrix.update(conv);
+ }
else if(tid == NR::NR_FILTER_DIFFUSELIGHTING)
_diffuselighting.show_all();
- else if(tid == NR::NR_FILTER_DISPLACEMENTMAP)
+ else if(tid == NR::NR_FILTER_DISPLACEMENTMAP) {
_displacementmap.show_all();
+ }
else if(tid == NR::NR_FILTER_FLOOD)
_flood.show_all();
else if(tid == NR::NR_FILTER_GAUSSIANBLUR) {