From: nicholasbishop Date: Sat, 14 Jul 2007 20:55:43 +0000 (+0000) Subject: Filter effects: X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c9f29ccf73d68064b0e869847ce640bd27b94b82;p=inkscape.git Filter effects: * As coded by Johan Engelen, made the filter-effect-enums code more generic; the data and conversion classes are now in src/util, filter-specific data is in filter-enums.h * Improved filter_add_primitive so that default values are filled in appropriately to prevent errors or possible crashes --- diff --git a/src/Makefile_insert b/src/Makefile_insert index 989b0cb1d..1371039c1 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -75,6 +75,7 @@ libinkpre_a_SOURCES = \ extract-uri.cpp extract-uri.h \ file.cpp file.h \ filter-chemistry.cpp filter-chemistry.h \ + filter-enums.cpp filter-enums.h \ flood-context.cpp flood-context.h \ fontsize-expansion.cpp fontsize-expansion.h \ forward.h \ @@ -288,6 +289,7 @@ libinkpost_a_SOURCES = \ ege-select-one-action.h \ fill-or-stroke.h \ filter-chemistry.cpp filter-chemistry.h \ + filter-enums.cpp filter-enums.h \ fixes.cpp \ gc-alloc.h \ gc-anchored.h gc-anchored.cpp \ diff --git a/src/filter-chemistry.cpp b/src/filter-chemistry.cpp index e59036362..d9bf33d60 100644 --- a/src/filter-chemistry.cpp +++ b/src/filter-chemistry.cpp @@ -18,6 +18,9 @@ #include "document-private.h" #include "desktop-style.h" +#include "filter-chemistry.h" +#include "filter-enums.h" + #include "sp-feblend.h" #include "sp-filter.h" #include "sp-filter-reference.h" @@ -111,15 +114,57 @@ SPFilter *new_filter(SPDocument *document) } SPFilterPrimitive * -filter_add_primitive(SPFilter *filter, const gchar *type) +filter_add_primitive(SPFilter *filter, const NR::FilterPrimitiveType type) { Inkscape::XML::Document *xml_doc = sp_document_repr_doc(filter->document); //create filter primitive node Inkscape::XML::Node *repr; - repr = xml_doc->createElement(type); + repr = xml_doc->createElement(FPConverter.get_key(type).c_str()); repr->setAttribute("inkscape:collect", "always"); + // set default values + switch(type) { + case NR::NR_FILTER_BLEND: + repr->setAttribute("blend", "normal"); + 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: + repr->setAttribute("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: + repr->setAttribute("dx", "0"); + repr->setAttribute("dy", "0"); + break; + case NR::NR_FILTER_SPECULARLIGHTING: + break; + case NR::NR_FILTER_TILE: + break; + case NR::NR_FILTER_TURBULENCE: + break; + default: + break; + } + //set primitive as child of filter node filter->repr->appendChild(repr); Inkscape::GC::release(repr); diff --git a/src/filter-chemistry.h b/src/filter-chemistry.h index 125c527b2..25ba0c997 100644 --- a/src/filter-chemistry.h +++ b/src/filter-chemistry.h @@ -17,7 +17,7 @@ #include "forward.h" #include "sp-filter.h" -SPFilterPrimitive *filter_add_primitive(SPFilter *filter, const gchar *type); +SPFilterPrimitive *filter_add_primitive(SPFilter *filter, NR::FilterPrimitiveType); SPFilter *new_filter (SPDocument *document); SPFilter *new_filter_gaussian_blur (SPDocument *document, gdouble stdDeviation, double expansion, double expansionX, double expansionY, double width, double height); SPFilter *new_filter_simple_from_item (SPDocument *document, SPItem *item, const char *mode, gdouble stdDeviation); diff --git a/src/filter-enums.cpp b/src/filter-enums.cpp new file mode 100644 index 000000000..b5e1cfbe5 --- /dev/null +++ b/src/filter-enums.cpp @@ -0,0 +1,68 @@ +/* + * Conversion data for filter and filter primitive enumerations + * + * Authors: + * Nicholas Bishop + * + * Copyright (C) 2007 authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include + +#include "filter-enums.h" + +using Inkscape::Util::EnumData; +using Inkscape::Util::EnumDataConverter; + +const EnumData FPData[NR::NR_FILTER_ENDPRIMITIVETYPE] = { + {NR::NR_FILTER_BLEND, _("Blend"), "svg:feBlend"}, + {NR::NR_FILTER_COLORMATRIX, _("Color Matrix"), "svg:feColorMatrix"}, + {NR::NR_FILTER_COMPONENTTRANSFER, _("Component Transfer"), "svg:feComponentTransfer"}, + {NR::NR_FILTER_COMPOSITE, _("Composite"), "svg:feComposite"}, + {NR::NR_FILTER_CONVOLVEMATRIX, _("Convolve Matrix"), "svg:feConvolveMatrix"}, + {NR::NR_FILTER_DIFFUSELIGHTING, _("Diffuse Lighting"), "svg:feDiffuseLighting"}, + {NR::NR_FILTER_DISPLACEMENTMAP, _("Displacement Map"), "svg:feDisplacementMap"}, + {NR::NR_FILTER_FLOOD, _("Flood"), "svg:feFlood"}, + {NR::NR_FILTER_GAUSSIANBLUR, _("Gaussian Blur"), "svg:feGaussianBlur"}, + {NR::NR_FILTER_IMAGE, _("Image"), "svg:feImage"}, + {NR::NR_FILTER_MERGE, _("Merge"), "svg:feMerge"}, + {NR::NR_FILTER_MORPHOLOGY, _("Morphology"), "svg:feMorphology"}, + {NR::NR_FILTER_OFFSET, _("Offset"), "svg:feOffset"}, + {NR::NR_FILTER_SPECULARLIGHTING, _("Specular Lighting"), "svg:feSpecularLighting"}, + {NR::NR_FILTER_TILE, _("Tile"), "svg:feTile"}, + {NR::NR_FILTER_TURBULENCE, _("Turbulence"), "svg:feTurbulence"} +}; +const EnumDataConverter FPConverter(FPData, NR::NR_FILTER_ENDPRIMITIVETYPE); + +const EnumData BlendModeData[NR::BLEND_ENDMODE] = { + {NR::BLEND_NORMAL, _("Normal"), "normal"}, + {NR::BLEND_MULTIPLY, _("Multiply"), "multiply"}, + {NR::BLEND_SCREEN, _("Screen"), "screen"}, + {NR::BLEND_DARKEN, _("Darken"), "darken"}, + {NR::BLEND_LIGHTEN, _("Lighten"), "lighten"} +}; +const EnumDataConverter BlendModeConverter(BlendModeData, NR::BLEND_ENDMODE); + +const EnumData CompositeOperatorData[COMPOSITE_ENDOPERATOR] = { + {COMPOSITE_DEFAULT, _("Default"), ""}, + {COMPOSITE_OVER, _("Over"), "over"}, + {COMPOSITE_IN, _("In"), "in"}, + {COMPOSITE_OUT, _("Out"), "out"}, + {COMPOSITE_ATOP, _("Atop"), "atop"}, + {COMPOSITE_XOR, _("XOR"), "xor"}, + {COMPOSITE_ARITHMETIC, _("Arithmetic"), "arithmetic"} +}; +const EnumDataConverter CompositeOperatorConverter(CompositeOperatorData, COMPOSITE_ENDOPERATOR); + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/filter-enums.h b/src/filter-enums.h new file mode 100644 index 000000000..98b8b0e7d --- /dev/null +++ b/src/filter-enums.h @@ -0,0 +1,41 @@ +#ifndef __SP_FILTER_ENUMS_H__ +#define __SP_FILTER_ENUMS_H__ + +/* + * Conversion data for filter and filter primitive enumerations + * + * Authors: + * Nicholas Bishop + * + * Copyright (C) 2007 authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "display/nr-filter-blend.h" +#include "display/nr-filter-composite.h" +#include "display/nr-filter-types.h" +#include "util/enums.h" + +// Filter primitives +extern const Inkscape::Util::EnumData FPData[NR::NR_FILTER_ENDPRIMITIVETYPE]; +extern const Inkscape::Util::EnumDataConverter FPConverter; +// Blend mode +extern const Inkscape::Util::EnumData BlendModeData[NR::BLEND_ENDMODE]; +extern const Inkscape::Util::EnumDataConverter BlendModeConverter; +// Composite operator +extern const Inkscape::Util::EnumData CompositeOperatorData[COMPOSITE_ENDOPERATOR]; +extern const Inkscape::Util::EnumDataConverter CompositeOperatorConverter; + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index cd6aa986a..a2ae18f6f 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -283,7 +283,7 @@ void FilterEffectsDialog::PrimitiveList::update() 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); @@ -824,52 +824,9 @@ void FilterEffectsDialog::init_settings_widgets() void FilterEffectsDialog::add_primitive() { SPFilter* filter = _filter_modifier.get_selected_filter(); - const EnumData* 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); @@ -979,7 +936,7 @@ void FilterEffectsDialog::update_settings_view() _empty_settings.show(); if(prim) { - const NR::FilterPrimitiveType tid = FPConverter.get_id_from_name(prim->repr->name()); + const NR::FilterPrimitiveType tid = FPConverter.get_id_from_key(prim->repr->name()); _generic_settings.show_all(); _primitive_input1.set_active_input(SP_OBJECT_REPR(prim)->attribute("in")); @@ -989,7 +946,7 @@ void FilterEffectsDialog::update_settings_view() _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(); diff --git a/src/ui/dialog/filter-effects-dialog.h b/src/ui/dialog/filter-effects-dialog.h index 78b2eeb38..ab30268dd 100644 --- a/src/ui/dialog/filter-effects-dialog.h +++ b/src/ui/dialog/filter-effects-dialog.h @@ -171,7 +171,7 @@ private: template void set_attr_comboboxenum(const SPAttributeEnum attr, ComboBoxEnum* input) { if(input->is_sensitive()) - set_attr(attr, input->get_active_data()->name.c_str()); + set_attr(attr, input->get_active_data()->key.c_str()); } void set_attr_special(const SPAttributeEnum); void set_attr(const SPAttributeEnum, const gchar* val); diff --git a/src/ui/widget/Makefile_insert b/src/ui/widget/Makefile_insert index 72fb9cfc2..11c18738c 100644 --- a/src/ui/widget/Makefile_insert +++ b/src/ui/widget/Makefile_insert @@ -12,6 +12,7 @@ ui_widget_libuiwidget_a_SOURCES = \ ui/widget/color-picker.h \ ui/widget/color-preview.cpp \ ui/widget/color-preview.h \ + ui/widget/combo-enums.h \ ui/widget/combo-text.cpp \ ui/widget/combo-text.h \ ui/widget/entity-entry.cpp \ @@ -20,7 +21,6 @@ ui_widget_libuiwidget_a_SOURCES = \ ui/widget/entry.h \ ui/widget/filter-effect-chooser.h \ ui/widget/filter-effect-chooser.cpp \ - ui/widget/filter-effect-enums.h \ ui/widget/handlebox.cpp \ ui/widget/handlebox.h \ ui/widget/icon-widget.cpp \ diff --git a/src/ui/widget/combo-enums.h b/src/ui/widget/combo-enums.h new file mode 100644 index 000000000..826f13e69 --- /dev/null +++ b/src/ui/widget/combo-enums.h @@ -0,0 +1,94 @@ +/** + * \brief Simplified management of enumerations in the UI as combobox. + * + * Authors: + * Nicholas Bishop + * Johan Engelen + * + * Copyright (C) 2007 Authors + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + +#ifndef INKSCAPE_UI_WIDGET_COMBO_ENUMS_H +#define INKSCAPE_UI_WIDGET_COMBO_ENUMS_H + +#include +#include +#include "util/enums.h" + +namespace Inkscape { +namespace UI { +namespace Widget { + +template class ComboBoxEnum : public Gtk::ComboBox +{ +public: + ComboBoxEnum(const Util::EnumDataConverter& c) + : _converter(c) + { + _model = Gtk::ListStore::create(_columns); + set_model(_model); + + pack_start(_columns.label); + + // Initialize list + for(int i = 0; i < _converter.end; ++i) { + Gtk::TreeModel::Row row = *_model->append(); + const Util::EnumData* data = &_converter.data(i); + row[_columns.data] = data; + row[_columns.label] = _converter.get_label(data->id); + } + + set_active(0); + } + + const Util::EnumData* get_active_data() + { + Gtk::TreeModel::iterator i = this->get_active(); + if(i) + return (*i)[_columns.data]; + return 0; + } + + void add_row(const Glib::ustring& s) + { + Gtk::TreeModel::Row row = *_model->append(); + row[_columns.data] = 0; + row[_columns.label] = s; + } +private: + class Columns : public Gtk::TreeModel::ColumnRecord + { + public: + Columns() + { + add(data); + add(label); + } + + Gtk::TreeModelColumn*> data; + Gtk::TreeModelColumn label; + }; + + Columns _columns; + Glib::RefPtr _model; + const Util::EnumDataConverter& _converter; +}; + +} +} +} + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/ui/widget/filter-effect-chooser.cpp b/src/ui/widget/filter-effect-chooser.cpp index 005e2c2dc..9cc235895 100644 --- a/src/ui/widget/filter-effect-chooser.cpp +++ b/src/ui/widget/filter-effect-chooser.cpp @@ -155,7 +155,7 @@ sigc::signal& SimpleFilterModifier::signal_blend_blur_changed() const Glib::ustring SimpleFilterModifier::get_blend_mode() { - return _blend.get_active_row_number() == 5 ? "filter" : _blend.get_active_data()->name; + return _blend.get_active_row_number() == 5 ? "filter" : _blend.get_active_data()->key; } void SimpleFilterModifier::set_blend_mode(const int val) @@ -215,47 +215,6 @@ void SimpleFilterModifier::blend_mode_changed() } } -/*** From filter-effect-enums.h ***/ -const EnumData FPData[NR::NR_FILTER_ENDPRIMITIVETYPE] = { - {NR::NR_FILTER_BLEND, _("Blend"), "svg:feBlend"}, - {NR::NR_FILTER_COLORMATRIX, _("Color Matrix"), "svg:feColorMatrix"}, - {NR::NR_FILTER_COMPONENTTRANSFER, _("Component Transfer"), "svg:feComponentTransfer"}, - {NR::NR_FILTER_COMPOSITE, _("Composite"), "svg:feComposite"}, - {NR::NR_FILTER_CONVOLVEMATRIX, _("Convolve Matrix"), "svg:feConvolveMatrix"}, - {NR::NR_FILTER_DIFFUSELIGHTING, _("Diffuse Lighting"), "svg:feDiffuseLighting"}, - {NR::NR_FILTER_DISPLACEMENTMAP, _("Displacement Map"), "svg:feDisplacementMap"}, - {NR::NR_FILTER_FLOOD, _("Flood"), "svg:feFlood"}, - {NR::NR_FILTER_GAUSSIANBLUR, _("Gaussian Blur"), "svg:feGaussianBlur"}, - {NR::NR_FILTER_IMAGE, _("Image"), "svg:feImage"}, - {NR::NR_FILTER_MERGE, _("Merge"), "svg:feMerge"}, - {NR::NR_FILTER_MORPHOLOGY, _("Morphology"), "svg:feMorphology"}, - {NR::NR_FILTER_OFFSET, _("Offset"), "svg:feOffset"}, - {NR::NR_FILTER_SPECULARLIGHTING, _("Specular Lighting"), "svg:feSpecularLighting"}, - {NR::NR_FILTER_TILE, _("Tile"), "svg:feTile"}, - {NR::NR_FILTER_TURBULENCE, _("Turbulence"), "svg:feTurbulence"} -}; -const Converter FPConverter(FPData, NR::NR_FILTER_ENDPRIMITIVETYPE); - -const EnumData BlendModeData[NR::BLEND_ENDMODE] = { - {NR::BLEND_NORMAL, _("Normal"), "normal"}, - {NR::BLEND_MULTIPLY, _("Multiply"), "multiply"}, - {NR::BLEND_SCREEN, _("Screen"), "screen"}, - {NR::BLEND_DARKEN, _("Darken"), "darken"}, - {NR::BLEND_LIGHTEN, _("Lighten"), "lighten"} -}; -const Converter BlendModeConverter(BlendModeData, NR::BLEND_ENDMODE); - -const EnumData CompositeOperatorData[COMPOSITE_ENDOPERATOR] = { - {COMPOSITE_DEFAULT, _("Default"), ""}, - {COMPOSITE_OVER, _("Over"), "over"}, - {COMPOSITE_IN, _("In"), "in"}, - {COMPOSITE_OUT, _("Out"), "out"}, - {COMPOSITE_ATOP, _("Atop"), "atop"}, - {COMPOSITE_XOR, _("XOR"), "xor"}, - {COMPOSITE_ARITHMETIC, _("Arithmetic"), "arithmetic"} -}; -const Converter CompositeOperatorConverter(CompositeOperatorData, COMPOSITE_ENDOPERATOR); - } } } diff --git a/src/ui/widget/filter-effect-chooser.h b/src/ui/widget/filter-effect-chooser.h index 05f9faf32..3410e0146 100644 --- a/src/ui/widget/filter-effect-chooser.h +++ b/src/ui/widget/filter-effect-chooser.h @@ -17,7 +17,8 @@ #include #include -#include "filter-effect-enums.h" +#include "combo-enums.h" +#include "filter-enums.h" #include "labelled.h" #include "spin-slider.h" #include "sp-filter.h" diff --git a/src/ui/widget/filter-effect-enums.h b/src/ui/widget/filter-effect-enums.h deleted file mode 100644 index ec9dcc851..000000000 --- a/src/ui/widget/filter-effect-enums.h +++ /dev/null @@ -1,161 +0,0 @@ -/** - * \brief Simplified management of enumerations for filter effects - * - * Authors: - * Nicholas Bishop - * - * Copyright (C) 2007 Authors - * - * Released under GNU GPL. Read the file 'COPYING' for more information. - */ - -#ifndef INKSCAPE_UI_WIDGET_FILTER_EFFECT_ENUMS_H -#define INKSCAPE_UI_WIDGET_FILTER_EFFECT_ENUMS_H - -#include "sp-fecomposite.h" -#include "display/nr-filter-blend.h" -#include "display/nr-filter-types.h" - -namespace Inkscape { -namespace UI { -namespace Widget { - -template struct EnumData -{ - E id; - const Glib::ustring label; - const Glib::ustring name; -}; - -template class Converter -{ -public: - typedef EnumData Data; - - Converter(const EnumData* cd, const int endval) - : end(endval), _data(cd) - {} - - E get_id_from_label(const Glib::ustring& label) const - { - for(int i = 0; i < end; ++i) { - if(_data[i].label == label) - return (E)i; - } - - return (E)0; - } - - E get_id_from_name(const Glib::ustring& name) const - { - for(int i = 0; i < end; ++i) { - if(_data[i].name == name) - return (E)i; - } - - return (E)0; - } - - const Glib::ustring& get_label(const E e) const - { - return _data[e].label; - } - - const Glib::ustring& get_name(const E e) const - { - return _data[e].name; - } - - const EnumData& data(const int i) const - { - return _data[i]; - } - - const int end; -private: - const EnumData* _data; -}; - -template class ComboBoxEnum : public Gtk::ComboBox -{ -public: - ComboBoxEnum(const Converter& c) - : _converter(c) - { - _model = Gtk::ListStore::create(_columns); - set_model(_model); - - pack_start(_columns.label); - - // Initialize list - for(int i = 0; i < _converter.end; ++i) { - Gtk::TreeModel::Row row = *_model->append(); - const EnumData* data = &_converter.data(i); - row[_columns.data] = data; - row[_columns.label] = _converter.get_label(data->id); - } - - set_active(0); - } - - const EnumData* get_active_data() - { - Gtk::TreeModel::iterator i = this->get_active(); - if(i) - return (*i)[_columns.data]; - return 0; - } - - void add_row(const Glib::ustring& s) - { - Gtk::TreeModel::Row row = *_model->append(); - row[_columns.data] = 0; - row[_columns.label] = s; - } -private: - class Columns : public Gtk::TreeModel::ColumnRecord - { - public: - Columns() - { - add(data); - add(label); - } - - Gtk::TreeModelColumn*> data; - Gtk::TreeModelColumn label; - }; - - Columns _columns; - Glib::RefPtr _model; - const Converter& _converter; -}; - -/*** Filter Primitives ***/ -extern const EnumData FPData[NR::NR_FILTER_ENDPRIMITIVETYPE]; -extern const Converter FPConverter; - -/*** feBlend Mode ***/ -extern const EnumData BlendModeData[NR::BLEND_ENDMODE]; -extern const Converter BlendModeConverter; - -/*** feComposite Operator ***/ -extern const EnumData CompositeOperatorData[COMPOSITE_ENDOPERATOR]; -extern const Converter CompositeOperatorConverter; - -} -} -} - -#endif - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/util/Makefile_insert b/src/util/Makefile_insert index 465fce469..41d3b9fb4 100644 --- a/src/util/Makefile_insert +++ b/src/util/Makefile_insert @@ -7,6 +7,7 @@ util/clean: util_libinkutil_a_SOURCES = \ util/compose.hpp \ util/ucompose.hpp \ + util/enums.h \ util/filter-list.h \ util/fixed_point.h \ util/format.h \ diff --git a/src/util/enums.h b/src/util/enums.h new file mode 100644 index 000000000..e7a6fd868 --- /dev/null +++ b/src/util/enums.h @@ -0,0 +1,93 @@ +/** + * \brief Simplified management of enumerations of svg items with UI labels + * + * Authors: + * Nicholas Bishop + * Johan Engelen + * + * Copyright (C) 2007 Authors + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + +#ifndef INKSCAPE_UTIL_ENUMS_H +#define INKSCAPE_UTIL_ENUMS_H + +#include + +namespace Inkscape { +namespace Util { + +template class EnumData +{ +public: + E id; + const Glib::ustring label; + const Glib::ustring key; +}; + +template class EnumDataConverter +{ +public: + typedef EnumData Data; + + EnumDataConverter(const EnumData* cd, const int endval) + : end(endval), _data(cd) + {} + + E get_id_from_label(const Glib::ustring& label) const + { + for(int i = 0; i < end; ++i) { + if(_data[i].label == label) + return (E)i; + } + + return (E)0; + } + + E get_id_from_key(const Glib::ustring& key) const + { + for(int i = 0; i < end; ++i) { + if(_data[i].key == key) + return (E)i; + } + + return (E)0; + } + + const Glib::ustring& get_label(const E e) const + { + return _data[e].label; + } + + const Glib::ustring& get_key(const E e) const + { + return _data[e].key; + } + + const EnumData& data(const int i) const + { + return _data[i]; + } + + const int end; +private: + const EnumData* _data; +}; + + +} +} + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :