From: jucablues Date: Tue, 19 Feb 2008 20:57:06 +0000 (+0000) Subject: * use enums to deal with displacementmap channel selectors X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2b3b5a2a04c62bc07b7f0740e7c705f142f9b173;p=inkscape.git * use enums to deal with displacementmap channel selectors * set default values explicitly for all combobox filter settings at the filters dialog. --- diff --git a/src/display/nr-filter-displacement-map.cpp b/src/display/nr-filter-displacement-map.cpp index 838db0fdf..5d454e6cd 100644 --- a/src/display/nr-filter-displacement-map.cpp +++ b/src/display/nr-filter-displacement-map.cpp @@ -115,8 +115,8 @@ void FilterDisplacementMap::set_input(int input, int slot) { if (input == 1) _input2 = slot; } -void FilterDisplacementMap::set_channel_selector(int s, int channel) { - if (channel>3 || channel <0) { +void FilterDisplacementMap::set_channel_selector(int s, FilterDisplacementMapChannelSelector channel) { + if (channel > DISPLACEMENTMAP_CHANNEL_ALPHA || channel < DISPLACEMENTMAP_CHANNEL_RED) { g_warning("Selected an invalid channel value. (%d)", channel); return; } diff --git a/src/display/nr-filter-displacement-map.h b/src/display/nr-filter-displacement-map.h index b89553697..34ba3aad2 100644 --- a/src/display/nr-filter-displacement-map.h +++ b/src/display/nr-filter-displacement-map.h @@ -12,6 +12,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include "sp-fedisplacementmap.h" #include "display/nr-filter-primitive.h" #include "display/nr-filter-slot.h" #include "display/nr-filter-units.h" @@ -29,7 +30,7 @@ public: virtual void set_input(int slot); virtual void set_input(int input, int slot); virtual void set_scale(double s); - virtual void set_channel_selector(int channel, int s); + virtual void set_channel_selector(int s, FilterDisplacementMapChannelSelector channel); virtual int render(FilterSlot &slot, FilterUnits const &units); virtual void area_enlarge(NRRectL &area, Matrix const &trans); virtual FilterTraits get_input_traits(); @@ -37,8 +38,8 @@ public: private: double scale; int _input2; - int Xchannel; - int Ychannel; + FilterDisplacementMapChannelSelector Xchannel; + FilterDisplacementMapChannelSelector Ychannel; int out_x0, out_y0, out_w, out_h; }; diff --git a/src/filter-enums.cpp b/src/filter-enums.cpp index df494c50c..45a1c4c72 100644 --- a/src/filter-enums.cpp +++ b/src/filter-enums.cpp @@ -97,13 +97,13 @@ const EnumData ConvolveMatrixEdgeModeData[NR:: const EnumDataConverter ConvolveMatrixEdgeModeConverter(ConvolveMatrixEdgeModeData, NR::CONVOLVEMATRIX_EDGEMODE_ENDTYPE); // feDisplacementMap -const EnumData DisplacementMapChannelData[4] = { - {0, _("Red"), "R"}, - {1, _("Green"), "G"}, - {2, _("Blue"), "B"}, - {3, _("Alpha"), "A"} +const EnumData DisplacementMapChannelData[DISPLACEMENTMAP_CHANNEL_ENDTYPE] = { + {DISPLACEMENTMAP_CHANNEL_RED, _("Red"), "R"}, + {DISPLACEMENTMAP_CHANNEL_GREEN, _("Green"), "G"}, + {DISPLACEMENTMAP_CHANNEL_BLUE, _("Blue"), "B"}, + {DISPLACEMENTMAP_CHANNEL_ALPHA, _("Alpha"), "A"} }; -const EnumDataConverter DisplacementMapChannelConverter(DisplacementMapChannelData, 4); +const EnumDataConverter DisplacementMapChannelConverter(DisplacementMapChannelData, DISPLACEMENTMAP_CHANNEL_ENDTYPE); // feMorphology const EnumData MorphologyOperatorData[NR::MORPHOLOGY_OPERATOR_END] = { diff --git a/src/filter-enums.h b/src/filter-enums.h index fe517ea5e..87d5c1217 100644 --- a/src/filter-enums.h +++ b/src/filter-enums.h @@ -20,6 +20,7 @@ #include "display/nr-filter-morphology.h" #include "display/nr-filter-turbulence.h" #include "display/nr-filter-types.h" +#include "sp-fedisplacementmap.h" #include "util/enums.h" // Filter primitives @@ -55,8 +56,8 @@ extern const Inkscape::Util::EnumDataConverter CompositeOpe extern const Inkscape::Util::EnumData ConvolveMatrixEdgeModeData[NR::CONVOLVEMATRIX_EDGEMODE_ENDTYPE]; extern const Inkscape::Util::EnumDataConverter ConvolveMatrixEdgeModeConverter; // DisplacementMap channel -extern const Inkscape::Util::EnumData DisplacementMapChannelData[4]; -extern const Inkscape::Util::EnumDataConverter DisplacementMapChannelConverter; +extern const Inkscape::Util::EnumData DisplacementMapChannelData[4]; +extern const Inkscape::Util::EnumDataConverter DisplacementMapChannelConverter; // Morphology operator extern const Inkscape::Util::EnumData MorphologyOperatorData[NR::MORPHOLOGY_OPERATOR_END]; extern const Inkscape::Util::EnumDataConverter MorphologyOperatorConverter; diff --git a/src/sp-fedisplacementmap.cpp b/src/sp-fedisplacementmap.cpp index 0fb531842..b53238093 100644 --- a/src/sp-fedisplacementmap.cpp +++ b/src/sp-fedisplacementmap.cpp @@ -79,8 +79,8 @@ static void sp_feDisplacementMap_init(SPFeDisplacementMap *feDisplacementMap) { feDisplacementMap->scale=0; - feDisplacementMap->xChannelSelector=3; - feDisplacementMap->yChannelSelector=3; + feDisplacementMap->xChannelSelector = DISPLACEMENTMAP_CHANNEL_ALPHA; + feDisplacementMap->yChannelSelector = DISPLACEMENTMAP_CHANNEL_ALPHA; feDisplacementMap->in2 = NR::NR_FILTER_SLOT_NOT_SET; } @@ -113,28 +113,28 @@ sp_feDisplacementMap_release(SPObject *object) ((SPObjectClass *) feDisplacementMap_parent_class)->release(object); } -static int sp_feDisplacementMap_readChannelSelector(gchar const *value) +static FilterDisplacementMapChannelSelector sp_feDisplacementMap_readChannelSelector(gchar const *value) { - if (!value) return 3; + if (!value) return DISPLACEMENTMAP_CHANNEL_ALPHA; switch (value[0]) { case 'R': - return 0; + return DISPLACEMENTMAP_CHANNEL_RED; break; case 'G': - return 1; + return DISPLACEMENTMAP_CHANNEL_GREEN; break; case 'B': - return 2; + return DISPLACEMENTMAP_CHANNEL_BLUE; break; case 'A': - return 3; + return DISPLACEMENTMAP_CHANNEL_ALPHA; break; default: // error g_warning("Invalid attribute for Channel Selector. Valid modes are 'R', 'G', 'B' or 'A'"); break; } - return 3; //default is Alpha Channel + return DISPLACEMENTMAP_CHANNEL_ALPHA; //default is Alpha Channel } /** @@ -147,7 +147,7 @@ sp_feDisplacementMap_set(SPObject *object, unsigned int key, gchar const *value) (void)feDisplacementMap; int input; double read_num; - int read_selector; + FilterDisplacementMapChannelSelector read_selector; switch(key) { /*DEAL WITH SETTING ATTRIBUTES HERE*/ case SP_ATTR_XCHANNELSELECTOR: diff --git a/src/sp-fedisplacementmap.h b/src/sp-fedisplacementmap.h index 427bce153..914f770b5 100644 --- a/src/sp-fedisplacementmap.h +++ b/src/sp-fedisplacementmap.h @@ -16,6 +16,14 @@ #include "sp-filter.h" #include "sp-fedisplacementmap-fns.h" +enum FilterDisplacementMapChannelSelector { + DISPLACEMENTMAP_CHANNEL_RED, + DISPLACEMENTMAP_CHANNEL_GREEN, + DISPLACEMENTMAP_CHANNEL_BLUE, + DISPLACEMENTMAP_CHANNEL_ALPHA, + DISPLACEMENTMAP_CHANNEL_ENDTYPE +}; + /* FeDisplacementMap base class */ class SPFeDisplacementMapClass; @@ -23,8 +31,8 @@ struct SPFeDisplacementMap : public SPFilterPrimitive { /** DISPLACEMENTMAP ATTRIBUTES HERE */ int in2; double scale; - int xChannelSelector; - int yChannelSelector; + FilterDisplacementMapChannelSelector xChannelSelector; + FilterDisplacementMapChannelSelector yChannelSelector; }; struct SPFeDisplacementMapClass { diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index a97654b75..c78c3a7ee 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -871,11 +871,11 @@ public: } // ComboBoxEnum - template ComboBoxEnum* add_combo(const SPAttributeEnum attr, + template ComboBoxEnum* add_combo(T default_value, const SPAttributeEnum attr, const Glib::ustring& label, const Util::EnumDataConverter& conv) { - ComboBoxEnum* combo = new ComboBoxEnum(conv, attr); + ComboBoxEnum* combo = new ComboBoxEnum(default_value, conv, attr); add_widget(combo, label); add_attr_widget(combo); return combo; @@ -2043,9 +2043,9 @@ FilterEffectsDialog::FilterEffectsDialog() _add_primitive(_("Add Effect:")), _empty_settings(_("No effect selected"), Gtk::ALIGN_LEFT), _no_filter_selected(_("No filter selected"), Gtk::ALIGN_LEFT), + _settings_initialized(false), _locked(false), - _attr_lock(false), - _settings_initialized(false) + _attr_lock(false) { _settings = new Settings(*this, _settings_tab1, sigc::mem_fun(*this, &FilterEffectsDialog::set_attr_direct), NR_FILTER_ENDPRIMITIVETYPE); @@ -2138,16 +2138,16 @@ void FilterEffectsDialog::init_settings_widgets() _filter_general_settings->add_multispinbutton(/*default width:*/ (double) 1.2, /*default height:*/ (double) 1.2, SP_ATTR_WIDTH, SP_ATTR_HEIGHT, _("Dimensions"), 0, 1000, 0.01, 0.1, 2); _settings->type(NR_FILTER_BLEND); - _settings->add_combo(SP_ATTR_MODE, _("Mode"), BlendModeConverter); + _settings->add_combo(BLEND_NORMAL, SP_ATTR_MODE, _("Mode"), BlendModeConverter); _settings->type(NR_FILTER_COLORMATRIX); - ComboBoxEnum* colmat = _settings->add_combo(SP_ATTR_TYPE, _("Type"), ColorMatrixTypeConverter); + ComboBoxEnum* colmat = _settings->add_combo(COLORMATRIX_MATRIX, SP_ATTR_TYPE, _("Type"), ColorMatrixTypeConverter); _color_matrix_values = _settings->add_colormatrixvalues(_("Value(s)")); colmat->signal_attr_changed().connect(sigc::mem_fun(*this, &FilterEffectsDialog::update_color_matrix)); _settings->type(NR_FILTER_COMPONENTTRANSFER); _settings->add_notimplemented(); - /*_settings->add_combo(SP_ATTR_TYPE, _("Type"), ComponentTransferTypeConverter); + /*_settings->add_combo(COMPONENTTRANSFER_TYPE_IDENTITY, SP_ATTR_TYPE, _("Type"), ComponentTransferTypeConverter); _ct_slope = _settings->add_spinslider(SP_ATTR_SLOPE, _("Slope"), -100, 100, 1, 0.01, 1); _ct_intercept = _settings->add_spinslider(SP_ATTR_INTERCEPT, _("Intercept"), -100, 100, 1, 0.01, 1); _ct_amplitude = _settings->add_spinslider(SP_ATTR_AMPLITUDE, _("Amplitude"), 0, 100, 1, 0.01, 1); @@ -2155,7 +2155,7 @@ void FilterEffectsDialog::init_settings_widgets() _ct_offset = _settings->add_spinslider(SP_ATTR_OFFSET, _("Offset"), -100, 100, 1, 0.01, 1);*/ _settings->type(NR_FILTER_COMPOSITE); - _settings->add_combo(SP_ATTR_OPERATOR, _("Operator"), CompositeOperatorConverter); + _settings->add_combo(COMPOSITE_OVER, SP_ATTR_OPERATOR, _("Operator"), CompositeOperatorConverter); _k1 = _settings->add_spinslider(SP_ATTR_K1, _("K1"), -10, 10, 0.1, 0.01, 2); _k2 = _settings->add_spinslider(SP_ATTR_K2, _("K2"), -10, 10, 0.1, 0.01, 2); _k3 = _settings->add_spinslider(SP_ATTR_K3, _("K3"), -10, 10, 0.1, 0.01, 2); @@ -2168,7 +2168,7 @@ void FilterEffectsDialog::init_settings_widgets() _convolve_order->signal_attr_changed().connect(sigc::mem_fun(*this, &FilterEffectsDialog::convolve_order_changed)); _settings->add_spinslider(SP_ATTR_DIVISOR, _("Divisor"), 1, 20, 1, 0.1, 2); _settings->add_spinslider(SP_ATTR_BIAS, _("Bias"), -10, 10, 1, 0.01, 1); - _settings->add_combo(SP_ATTR_EDGEMODE, _("Edge Mode"), ConvolveMatrixEdgeModeConverter); + _settings->add_combo(CONVOLVEMATRIX_EDGEMODE_DUPLICATE, SP_ATTR_EDGEMODE, _("Edge Mode"), ConvolveMatrixEdgeModeConverter); _settings->add_checkbutton(SP_ATTR_PRESERVEALPHA, _("Preserve Alpha"), "true", "false"); _settings->type(NR_FILTER_DIFFUSELIGHTING); @@ -2180,8 +2180,8 @@ void FilterEffectsDialog::init_settings_widgets() _settings->type(NR_FILTER_DISPLACEMENTMAP); _settings->add_spinslider(SP_ATTR_SCALE, _("Scale"), 0, 100, 1, 0.01, 1); - _settings->add_combo(SP_ATTR_XCHANNELSELECTOR, _("X Channel"), DisplacementMapChannelConverter); - _settings->add_combo(SP_ATTR_YCHANNELSELECTOR, _("Y Channel"), DisplacementMapChannelConverter); + _settings->add_combo(DISPLACEMENTMAP_CHANNEL_ALPHA, SP_ATTR_XCHANNELSELECTOR, _("X Channel"), DisplacementMapChannelConverter); + _settings->add_combo(DISPLACEMENTMAP_CHANNEL_ALPHA, SP_ATTR_YCHANNELSELECTOR, _("Y Channel"), DisplacementMapChannelConverter); _settings->type(NR_FILTER_FLOOD); _settings->add_color(SP_PROP_FLOOD_COLOR, _("Flood Color")); @@ -2191,7 +2191,7 @@ void FilterEffectsDialog::init_settings_widgets() _settings->add_dualspinslider(SP_ATTR_STDDEVIATION, _("Standard Deviation"), 0.01, 100, 1, 0.01, 1); _settings->type(NR_FILTER_MORPHOLOGY); - _settings->add_combo(SP_ATTR_OPERATOR, _("Operator"), MorphologyOperatorConverter); + _settings->add_combo(MORPHOLOGY_OPERATOR_ERODE, SP_ATTR_OPERATOR, _("Operator"), MorphologyOperatorConverter); _settings->add_dualspinslider(SP_ATTR_RADIUS, _("Radius"), 0, 100, 1, 0.01, 1); _settings->type(NR_FILTER_IMAGE); @@ -2214,7 +2214,7 @@ void FilterEffectsDialog::init_settings_widgets() _settings->type(NR_FILTER_TURBULENCE); _settings->add_checkbutton(SP_ATTR_STITCHTILES, _("Stitch Tiles"), "stitch", "noStitch"); - _settings->add_combo(SP_ATTR_TYPE, _("Type"), TurbulenceTypeConverter); + _settings->add_combo(TURBULENCE_TURBULENCE, SP_ATTR_TYPE, _("Type"), TurbulenceTypeConverter); _settings->add_dualspinslider(SP_ATTR_BASEFREQUENCY, _("Base Frequency"), 0, 1, 0.001, 0.01, 3); _settings->add_spinslider(SP_ATTR_NUMOCTAVES, _("Octaves"), 1, 10, 1, 1, 0); _settings->add_spinslider(SP_ATTR_SEED, _("Seed"), 0, 1000, 1, 1, 0); diff --git a/src/ui/dialog/filter-effects-dialog.h b/src/ui/dialog/filter-effects-dialog.h index 0bd47b52f..16d684dd4 100644 --- a/src/ui/dialog/filter-effects-dialog.h +++ b/src/ui/dialog/filter-effects-dialog.h @@ -243,6 +243,7 @@ private: Gtk::Label _empty_settings; Gtk::Label _no_filter_selected; bool _settings_initialized; + class Settings; class MatrixAttr; class ColorMatrixValues; diff --git a/src/ui/widget/attr-widget.h b/src/ui/widget/attr-widget.h index c87e860d5..34aae7db9 100644 --- a/src/ui/widget/attr-widget.h +++ b/src/ui/widget/attr-widget.h @@ -26,7 +26,8 @@ enum DefaultValueType T_NONE, T_DOUBLE, T_VECT_DOUBLE, - T_BOOL + T_BOOL, + T_UINT }; class DefaultValueHolder @@ -36,6 +37,7 @@ class DefaultValueHolder double d_val; std::vector* vt_val; bool b_val; + unsigned int uint_val; } value; //FIXME remove copy ctor and assignment operator as private to avoid double free of the vector @@ -59,11 +61,21 @@ public: value.b_val = d; } + DefaultValueHolder (unsigned int ui) { + type = T_UINT; + value.uint_val = ui; + } + ~DefaultValueHolder() { if (type == T_VECT_DOUBLE) delete value.vt_val; } + unsigned int as_uint() { + g_assert (type == T_UINT); + return value.uint_val; + } + bool as_bool() { g_assert (type == T_BOOL); return value.b_val; @@ -83,6 +95,11 @@ public: class AttrWidget { public: + AttrWidget(const SPAttributeEnum a, unsigned int value) + : _attr(a), + _default(value) + {} + AttrWidget(const SPAttributeEnum a, double value) : _attr(a), _default(value) diff --git a/src/ui/widget/combo-enums.h b/src/ui/widget/combo-enums.h index c77c2f5a8..75760ab12 100644 --- a/src/ui/widget/combo-enums.h +++ b/src/ui/widget/combo-enums.h @@ -26,6 +26,26 @@ namespace Widget { template class ComboBoxEnum : public Gtk::ComboBox, public AttrWidget { public: + ComboBoxEnum(E default_value, const Util::EnumDataConverter& c, const SPAttributeEnum a = SP_ATTR_INVALID) + : AttrWidget(a, (unsigned int)default_value), setProgrammatically(false), _converter(c) + { + signal_changed().connect(signal_attr_changed().make_slot()); + + _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).c_str() ); + } + set_active_by_id(default_value); + } + ComboBoxEnum(const Util::EnumDataConverter& c, const SPAttributeEnum a = SP_ATTR_INVALID) : AttrWidget(a), setProgrammatically(false), _converter(c) { @@ -43,7 +63,6 @@ public: row[_columns.data] = data; row[_columns.label] = _( _converter.get_label(data->id).c_str() ); } - set_active(0); } @@ -59,7 +78,7 @@ public: if(val) set_active(_converter.get_id_from_key(val)); else - set_active(0); + set_active(get_default()->as_uint()); } const Util::EnumData* get_active_data() const