Code

Filter effects:
authornicholasbishop <nicholasbishop@users.sourceforge.net>
Sat, 14 Jul 2007 20:55:43 +0000 (20:55 +0000)
committernicholasbishop <nicholasbishop@users.sourceforge.net>
Sat, 14 Jul 2007 20:55:43 +0000 (20:55 +0000)
* 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

14 files changed:
src/Makefile_insert
src/filter-chemistry.cpp
src/filter-chemistry.h
src/filter-enums.cpp [new file with mode: 0644]
src/filter-enums.h [new file with mode: 0644]
src/ui/dialog/filter-effects-dialog.cpp
src/ui/dialog/filter-effects-dialog.h
src/ui/widget/Makefile_insert
src/ui/widget/combo-enums.h [new file with mode: 0644]
src/ui/widget/filter-effect-chooser.cpp
src/ui/widget/filter-effect-chooser.h
src/ui/widget/filter-effect-enums.h [deleted file]
src/util/Makefile_insert
src/util/enums.h [new file with mode: 0644]

index 989b0cb1df3c8da07659a1212da1ac0317cb7404..1371039c15bf472251d1a2f6c311d541edd446c8 100644 (file)
@@ -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   \
index e59036362bdff71760bbcce65d09e65af7e97b02..d9bf33d60ca1a3489adc7591e3aea7827e4fa3f3 100644 (file)
@@ -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);
index 125c527b290e9e6d1c37ab7113a1ea53c04dc159..25ba0c997bdcb7f84486ec9f2379c3e921f13bc8 100644 (file)
@@ -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 (file)
index 0000000..b5e1cfb
--- /dev/null
@@ -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 <glibmm/i18n.h>
+
+#include "filter-enums.h"
+
+using Inkscape::Util::EnumData;
+using Inkscape::Util::EnumDataConverter;
+
+const EnumData<NR::FilterPrimitiveType> 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<NR::FilterPrimitiveType> FPConverter(FPData, NR::NR_FILTER_ENDPRIMITIVETYPE);
+
+const EnumData<NR::FilterBlendMode> 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<NR::FilterBlendMode> BlendModeConverter(BlendModeData, NR::BLEND_ENDMODE);
+
+const EnumData<FeCompositeOperator> 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<FeCompositeOperator> 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 (file)
index 0000000..98b8b0e
--- /dev/null
@@ -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<NR::FilterPrimitiveType> FPData[NR::NR_FILTER_ENDPRIMITIVETYPE];
+extern const Inkscape::Util::EnumDataConverter<NR::FilterPrimitiveType> FPConverter;
+// Blend mode
+extern const Inkscape::Util::EnumData<NR::FilterBlendMode> BlendModeData[NR::BLEND_ENDMODE];
+extern const Inkscape::Util::EnumDataConverter<NR::FilterBlendMode> BlendModeConverter;
+// Composite operator
+extern const Inkscape::Util::EnumData<FeCompositeOperator> CompositeOperatorData[COMPOSITE_ENDOPERATOR];
+extern const Inkscape::Util::EnumDataConverter<FeCompositeOperator> 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 :
index cd6aa986a85f841fa698f5222e18c76506eea277..a2ae18f6fbdc0f06a6b697b8866e3759651c80c5 100644 (file)
@@ -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<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);
@@ -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();
index 78b2eeb386135f23bcdf322dd0b006bf56cbd7fb..ab30268dd1c6e14429a3c399a172560510706807 100644 (file)
@@ -171,7 +171,7 @@ private:
     template<typename T> void set_attr_comboboxenum(const SPAttributeEnum attr, ComboBoxEnum<T>* 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);
index 72fb9cfc25723e8c8a213d32eca5940f50c17ede..11c18738c002117163c23dbd3f084aafe638ba38 100644 (file)
@@ -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 (file)
index 0000000..826f13e
--- /dev/null
@@ -0,0 +1,94 @@
+/**
+ * \brief Simplified management of enumerations in the UI as combobox.
+ *
+ * Authors:
+ *   Nicholas Bishop <nicholasbishop@gmail.com>
+ *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
+ *
+ * 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 <gtkmm/combobox.h>
+#include <gtkmm/liststore.h>
+#include "util/enums.h"
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+template<typename E> class ComboBoxEnum : public Gtk::ComboBox
+{
+public:
+    ComboBoxEnum(const Util::EnumDataConverter<E>& 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<E>* data = &_converter.data(i);
+            row[_columns.data] = data;
+            row[_columns.label] = _converter.get_label(data->id);
+        }
+
+        set_active(0);
+    }
+    
+    const Util::EnumData<E>* 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<const Util::EnumData<E>*> data;
+        Gtk::TreeModelColumn<Glib::ustring> label;
+    };
+
+    Columns _columns;
+    Glib::RefPtr<Gtk::ListStore> _model;
+    const Util::EnumDataConverter<E>& _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 :
index 005e2c2dc37f5b16081c0a730b2e77a758ef74a2..9cc235895e580733de95cad026a6ee64336e73a4 100644 (file)
@@ -155,7 +155,7 @@ sigc::signal<void>& 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<NR::FilterPrimitiveType> 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<NR::FilterPrimitiveType> FPConverter(FPData, NR::NR_FILTER_ENDPRIMITIVETYPE);
-
-const EnumData<NR::FilterBlendMode> 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<NR::FilterBlendMode> BlendModeConverter(BlendModeData, NR::BLEND_ENDMODE);
-
-const EnumData<FeCompositeOperator> 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<FeCompositeOperator> CompositeOperatorConverter(CompositeOperatorData, COMPOSITE_ENDOPERATOR);
-
 }
 }
 }
index 05f9faf32685202d43509860c8dd1cf5a57849cb..3410e0146a9c2a13618f7a45ae8f62c77cb22390 100644 (file)
@@ -17,7 +17,8 @@
 #include <gtkmm/liststore.h>
 #include <gtkmm/treeview.h>
 
-#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 (file)
index ec9dcc8..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-/**
- * \brief Simplified management of enumerations for filter effects
- *
- * Authors:
- *   Nicholas Bishop <nicholasbishop@gmail.com>
- *
- * 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<typename E> struct EnumData
-{
-    E id;
-    const Glib::ustring label;
-    const Glib::ustring name;
-};
-
-template<typename E> class Converter
-{
-public:
-    typedef EnumData<E> Data;
-
-    Converter(const EnumData<E>* 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<E>& data(const int i) const
-    {
-        return _data[i];
-    }
-
-    const int end;
-private:
-    const EnumData<E>* _data;
-};
-
-template<typename E> class ComboBoxEnum : public Gtk::ComboBox
-{
-public:
-    ComboBoxEnum(const Converter<E>& 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<E>* data = &_converter.data(i);
-            row[_columns.data] = data;
-            row[_columns.label] = _converter.get_label(data->id);
-        }
-
-        set_active(0);
-    }
-    
-    const EnumData<E>* 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<const EnumData<E>*> data;
-        Gtk::TreeModelColumn<Glib::ustring> label;
-    };
-
-    Columns _columns;
-    Glib::RefPtr<Gtk::ListStore> _model;
-    const Converter<E>& _converter;
-};
-
-/*** Filter Primitives ***/
-extern const EnumData<NR::FilterPrimitiveType> FPData[NR::NR_FILTER_ENDPRIMITIVETYPE];
-extern const Converter<NR::FilterPrimitiveType> FPConverter;
-
-/*** feBlend Mode ***/
-extern const EnumData<NR::FilterBlendMode> BlendModeData[NR::BLEND_ENDMODE];
-extern const Converter<NR::FilterBlendMode> BlendModeConverter;
-
-/*** feComposite Operator ***/
-extern const EnumData<FeCompositeOperator> CompositeOperatorData[COMPOSITE_ENDOPERATOR];
-extern const Converter<FeCompositeOperator> 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 :
index 465fce46955f156177eb534d14defa0d50a13715..41d3b9fb44d3a92b0671472e8bc749aae3cbad7e 100644 (file)
@@ -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 (file)
index 0000000..e7a6fd8
--- /dev/null
@@ -0,0 +1,93 @@
+/**
+ * \brief Simplified management of enumerations of svg items with UI labels
+ *
+ * Authors:
+ *   Nicholas Bishop <nicholasbishop@gmail.com>
+ *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
+ *
+ * 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 <glibmm/ustring.h>
+
+namespace Inkscape {
+namespace Util {
+
+template<typename E> class EnumData
+{
+public:
+    E id;
+    const Glib::ustring label;
+    const Glib::ustring key;
+};
+
+template<typename E> class EnumDataConverter
+{
+public:
+    typedef EnumData<E> Data;
+
+    EnumDataConverter(const EnumData<E>* 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<E>& data(const int i) const
+    {
+        return _data[i];
+    }
+
+    const int end;
+private:
+    const EnumData<E>* _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 :