Code

r19125@shi: ted | 2008-04-23 23:32:56 -0700
authorgouldtj <gouldtj@users.sourceforge.net>
Thu, 24 Apr 2008 06:36:02 +0000 (06:36 +0000)
committergouldtj <gouldtj@users.sourceforge.net>
Thu, 24 Apr 2008 06:36:02 +0000 (06:36 +0000)
 Cleaning up a couple things.  Making sure we don't leak memory through
 the destructor (rarely used in reality, but we should be clean about these
 things, that's what destructors are for).
 r19126@shi:  ted | 2008-04-23 23:33:30 -0700
 Making it so that snow has a parameter for drift size.  It seems like that
 is what most people would want to change on this relatively complex filter.

src/extension/internal/filter/drop-shadow.h
src/extension/internal/filter/snow.h

index b19adffa23ae87e21d910ec570217968abef0498..7516bacf9820c5cf2496caded76624d4d1407856 100644 (file)
@@ -22,13 +22,12 @@ namespace Internal {
 namespace Filter {
 
 class DropShadow : public Inkscape::Extension::Internal::Filter::Filter {
-       int myvar;
 protected:
        virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
 
 public:
        DropShadow ( ) : Filter() { };
-       //virtual ~DropShadow ( ) { if (_filter != NULL) g_free(_filter); return; }
+       virtual ~DropShadow ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
 
        static void init (void) {
                Inkscape::Extension::build_from_mem(
index 0b99cbc86685c26a5ea8650ba23d19dd16c8792c..366bdcf1f007c432239123e5ba79325c04c69625 100644 (file)
@@ -18,30 +18,56 @@ namespace Internal {
 namespace Filter {
 
 class Snow : public Inkscape::Extension::Internal::Filter::Filter {
+protected:
+       virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
+
+public:
+       Snow ( ) : Filter() { };
+       virtual ~Snow ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
+
 public:
        static void init (void) {
-               filter_init("snow",     /* ID -- should be unique */
-                           N_("Snow"), /* Name in the menus, should have a N_() around it for translation */
-                           N_("When the weather outside is frightening..."),
-                                                    /* Menu tooltip to help users understand the name.  Should also have a N_() */
-                                       "<filter>\n"
-                        "<feConvolveMatrix order=\"3 3\" kernelMatrix=\"1 1 1 0 0 0 -1 -1 -1\" preserveAlpha=\"false\" divisor=\"3\"/>\n"
-                        "<feMorphology operator=\"dilate\" radius=\"1 3.2345013477088949\"/>\n"
-                        "<feGaussianBlur stdDeviation=\"1.6270889487870621\" result=\"result0\"/>\n"
-                        "<feColorMatrix values=\"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0\" result=\"result1\"/>\n"
-                        "<feOffset dx=\"0\" dy=\"1\" result=\"result5\"/>\n"
-                        "<feDiffuseLighting in=\"result0\" diffuseConstant=\"2.2613065326633168\" surfaceScale=\"1\">\n"
-                          "<feDistantLight azimuth=\"225\" elevation=\"32\"/>\n"
-                        "</feDiffuseLighting>\n"
-                        "<feComposite in2=\"result1\" operator=\"in\" result=\"result2\"/>\n"
-                        "<feColorMatrix values=\"0.4 0 0 0 0.6 0 0.4 0 0 0.6 0 0 0 0 1 0 0 0 1 0\" result=\"result4\"/>\n"
-                        "<feComposite in2=\"result5\" in=\"result4\"/>\n"
-                        "<feComposite in2=\"SourceGraphic\"/>\n"
-                                       "</filter>\n");
-                                                /* The XML of the filter that should be added.  There
-                                                 * should be a <svg:filter> surrounding what you'd like
-                                                 * to be added with this effect. */
+               Inkscape::Extension::build_from_mem(
+                       "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
+                               "<name>" N_("Snow") "</name>\n"
+                               "<id>org.inkscape.effect.filter.snow</id>\n"
+                               "<param name=\"drift\" gui-text=\"" N_("Drift Size") "\" type=\"float\" min=\"0.0\" max=\"20.0\">3.5</param>\n"
+                               "<effect>\n"
+                                       "<object-type>all</object-type>\n"
+                                       "<effects-menu>\n"
+                                               "<submenu name=\"" N_("Filter") "\" />\n"
+                                       "</effects-menu>\n"
+                                       "<menu-tip>" N_("When the weather outside is frightening...") "</menu-tip>\n"
+                               "</effect>\n"
+                       "</inkscape-extension>\n", new Snow());
        };
+
+};
+
+gchar const *
+Snow::get_filter_text (Inkscape::Extension::Extension * ext)
+{
+       if (_filter != NULL) g_free((void *)_filter);
+
+       float drift = ext->get_param_float("drift");
+
+       _filter = g_strdup_printf(
+                               "<filter>\n"
+                                       "<feConvolveMatrix order=\"3 3\" kernelMatrix=\"1 1 1 0 0 0 -1 -1 -1\" preserveAlpha=\"false\" divisor=\"3\"/>\n"
+                                       "<feMorphology operator=\"dilate\" radius=\"1 %f\"/>\n"
+                                       "<feGaussianBlur stdDeviation=\"1.6270889487870621\" result=\"result0\"/>\n"
+                                       "<feColorMatrix values=\"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0\" result=\"result1\"/>\n"
+                                       "<feOffset dx=\"0\" dy=\"1\" result=\"result5\"/>\n"
+                                       "<feDiffuseLighting in=\"result0\" diffuseConstant=\"2.2613065326633168\" surfaceScale=\"1\">\n"
+                                         "<feDistantLight azimuth=\"225\" elevation=\"32\"/>\n"
+                                       "</feDiffuseLighting>\n"
+                                       "<feComposite in2=\"result1\" operator=\"in\" result=\"result2\"/>\n"
+                                       "<feColorMatrix values=\"0.4 0 0 0 0.6 0 0.4 0 0 0.6 0 0 0 0 1 0 0 0 1 0\" result=\"result4\"/>\n"
+                                       "<feComposite in2=\"result5\" in=\"result4\"/>\n"
+                                       "<feComposite in2=\"SourceGraphic\"/>\n"
+                               "</filter>\n", drift);
+
+       return _filter;
 };
 
 }; /* namespace Filter */