Code

2bb798cf12e614b5958feebb6c58253aa73540df
[inkscape.git] / src / extension / internal / filter / snow.h
1 #ifndef __INKSCAPE_EXTENSION_INTERNAL_FILTER_SNOW_H__
2 #define __INKSCAPE_EXTENSION_INTERNAL_FILTER_SNOW_H__
3 /* Change the 'SNOW' above to be your file name */
5 /*
6  * Copyright (C) 2008 Authors:
7  *   Ted Gould <ted@gould.cx>
8  *
9  * Released under GNU GPL, read the file 'COPYING' for more information
10  */
11 /* ^^^ Change the copyright to be you and your e-mail address ^^^ */
13 #include "filter.h"
15 namespace Inkscape {
16 namespace Extension {
17 namespace Internal {
18 namespace Filter {
20 class Snow : public Inkscape::Extension::Internal::Filter::Filter {
21 protected:
22         virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
24 public:
25         Snow ( ) : Filter() { };
26         virtual ~Snow ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
28 public:
29         static void init (void) {
30                 Inkscape::Extension::build_from_mem(
31                         "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
32                                 "<name>" N_("Snow crest") "</name>\n"
33                                 "<id>org.inkscape.effect.filter.snow</id>\n"
34                                 "<param name=\"drift\" gui-text=\"" N_("Drift Size") "\" type=\"float\" min=\"0.0\" max=\"20.0\">3.5</param>\n"
35                                 "<effect>\n"
36                                         "<object-type>all</object-type>\n"
37                                         "<effects-menu>\n"
38                                                 "<submenu name=\"" N_("Filters") "\">\n"
39                                                 "<submenu name=\"Protrusions\"/>\n"
40                               "</submenu>\n"
41                                         "</effects-menu>\n"
42                                         "<menu-tip>" N_("Snow has fallen on object") "</menu-tip>\n"
43                                 "</effect>\n"
44                         "</inkscape-extension>\n", new Snow());
45         };
47 };
49 gchar const *
50 Snow::get_filter_text (Inkscape::Extension::Extension * ext)
51 {
52         if (_filter != NULL) g_free((void *)_filter);
54         std::ostringstream drift;
55         drift << ext->get_param_float("drift");
57         _filter = g_strdup_printf(
58                                 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" inkscape:label=\"Snow\">\n"
59                                         "<feConvolveMatrix order=\"3 3\" kernelMatrix=\"1 1 1 0 0 0 -1 -1 -1\" preserveAlpha=\"false\" divisor=\"3\"/>\n"
60                                         "<feMorphology operator=\"dilate\" radius=\"1 %s\"/>\n"
61                                         "<feGaussianBlur stdDeviation=\"1.6270889487870621\" result=\"result0\"/>\n"
62                                         "<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"
63                                         "<feOffset dx=\"0\" dy=\"1\" result=\"result5\"/>\n"
64                                         "<feDiffuseLighting in=\"result0\" diffuseConstant=\"2.2613065326633168\" surfaceScale=\"1\">\n"
65                                           "<feDistantLight azimuth=\"225\" elevation=\"32\"/>\n"
66                                         "</feDiffuseLighting>\n"
67                                         "<feComposite in2=\"result1\" operator=\"in\" result=\"result2\"/>\n"
68                                         "<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"
69                                         "<feComposite in2=\"result5\" in=\"result4\"/>\n"
70                                         "<feComposite in2=\"SourceGraphic\"/>\n"
71                                 "</filter>\n", drift.str().c_str());
73         return _filter;
74 };
76 }; /* namespace Filter */
77 }; /* namespace Internal */
78 }; /* namespace Extension */
79 }; /* namespace Inkscape */
81 /* Change the 'SNOW' below to be your file name */
82 #endif /* __INKSCAPE_EXTENSION_INTERNAL_FILTER_SNOW_H__ */