Code

We don't really need two separate "Shadows" and "Shadows and glows" submenus, do...
[inkscape.git] / src / extension / internal / filter / drop-shadow.h
1 #ifndef __INKSCAPE_EXTENSION_INTERNAL_FILTER_DROP_SHADOW_H__
2 #define __INKSCAPE_EXTENSION_INTERNAL_FILTER_DROP_SHADOW_H__
3 /* Change the 'DROP_SHADOW' 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 #include "extension/internal/clear-n_.h"
16 #include "extension/system.h"
17 #include "extension/extension.h"
19 namespace Inkscape {
20 namespace Extension {
21 namespace Internal {
22 namespace Filter {
24 class DropShadow : public Inkscape::Extension::Internal::Filter::Filter {
25 protected:
26         virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
28 public:
29         DropShadow ( ) : Filter() { };
30         virtual ~DropShadow ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
32         static void init (void) {
33                 Inkscape::Extension::build_from_mem(
34                         "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
35                                 "<name>" N_("Drop Shadow") "</name>\n"
36                                 "<id>org.inkscape.effect.filter.drop-shadow</id>\n"
37                                 "<param name=\"blur\" gui-text=\"" N_("Blur radius, px") "\" type=\"float\" min=\"0.0\" max=\"200.0\">2.0</param>\n"
38                                 "<param name=\"opacity\" gui-text=\"" N_("Opacity, %") "\" type=\"float\" min=\"0.0\" max=\"100.0\">50</param>\n"                               
39                                 "<param name=\"xoffset\" gui-text=\"" N_("Horizontal offset, px") "\" type=\"float\" min=\"-50.0\" max=\"50.0\">4.0</param>\n"
40                                 "<param name=\"yoffset\" gui-text=\"" N_("Vertical offset, px") "\" type=\"float\" min=\"-50.0\" max=\"50.0\">4.0</param>\n"
41                                 "<effect>\n"
42                                         "<object-type>all</object-type>\n"
43                                         "<effects-menu>\n"
44                                                 "<submenu name=\"" N_("Filters") "\" >\n"
45                                                 "<submenu name=\"" N_("Shadows and Glows") "\"/>\n"
46                               "</submenu>\n"
47                                         "</effects-menu>\n"
48                                         "<menu-tip>" N_("Black, blurred drop shadow") "</menu-tip>\n"
49                                 "</effect>\n"
50                         "</inkscape-extension>\n", new DropShadow());
51         };
53 };
55 gchar const *
56 DropShadow::get_filter_text (Inkscape::Extension::Extension * ext)
57 {
58         if (_filter != NULL) g_free((void *)_filter);
60         float blur = ext->get_param_float("blur");
61         float opacity = ext->get_param_float("opacity") / 100;
62         float x = ext->get_param_float("xoffset");
63         float y = ext->get_param_float("yoffset");
65         _filter = g_strdup_printf(
66                 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" inkscape:label=\"Drop shadow\" width=\"1.5\" height=\"1.5\" x=\"-.25\" y=\"-.25\">\n"
67                         "<feGaussianBlur in=\"SourceAlpha\" stdDeviation=\"%f\" result=\"blur\"/>\n"
68                         "<feColorMatrix result=\"bluralpha\" type=\"matrix\" values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 %f 0 \" />\n"
69                         "<feOffset in=\"bluralpha\" dx=\"%f\" dy=\"%f\" result=\"offsetBlur\"/>\n"
70                         "<feMerge>\n"
71                                 "<feMergeNode in=\"offsetBlur\"/>\n"
72                                 "<feMergeNode in=\"SourceGraphic\"/>\n"
73                         "</feMerge>\n"
74                 "</filter>\n", blur, opacity, x, y);
76         return _filter;
77 };
79 class DropGlow : public Inkscape::Extension::Internal::Filter::Filter {
80 protected:
81         virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
83 public:
84         DropGlow ( ) : Filter() { };
85         virtual ~DropGlow ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
87         static void init (void) {
88                 Inkscape::Extension::build_from_mem(
89                         "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
90                                 "<name>" N_("Drop Glow") "</name>\n"
91                                 "<id>org.inkscape.effect.filter.drop-glow</id>\n"
92                                 "<param name=\"blur\" gui-text=\"" N_("Blur radius, px") "\" type=\"float\" min=\"0.0\" max=\"200.0\">2.0</param>\n"
93                                 "<param name=\"opacity\" gui-text=\"" N_("Opacity, %") "\" type=\"float\" min=\"0.0\" max=\"100.0\">50</param>\n"                               
94                                 "<param name=\"xoffset\" gui-text=\"" N_("Horizontal offset, px") "\" type=\"float\" min=\"-50.0\" max=\"50.0\">4.0</param>\n"
95                                 "<param name=\"yoffset\" gui-text=\"" N_("Vertical offset, px") "\" type=\"float\" min=\"-50.0\" max=\"50.0\">4.0</param>\n"
96                                 "<effect>\n"
97                                         "<object-type>all</object-type>\n"
98                                         "<effects-menu>\n"
99                                                 "<submenu name=\"" N_("Filters") "\">\n"
100                                                 "<submenu name=\"" N_("Shadows and Glows") "\"/>\n"
101                               "</submenu>\n"
102                                         "</effects-menu>\n"
103                                         "<menu-tip>" N_("White, blurred drop glow") "</menu-tip>\n"
104                                 "</effect>\n"
105                         "</inkscape-extension>\n", new DropGlow());
106         };
108 };
110 gchar const *
111 DropGlow::get_filter_text (Inkscape::Extension::Extension * ext)
113         if (_filter != NULL) g_free((void *)_filter);
115         float blur = ext->get_param_float("blur");
116         float opacity = ext->get_param_float("opacity") / 100;
117         float x = ext->get_param_float("xoffset");
118         float y = ext->get_param_float("yoffset");
120         _filter = g_strdup_printf(
121                 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" inkscape:label=\"Drop shadow\" width=\"1.5\" height=\"1.5\" x=\"-.25\" y=\"-.25\">\n"
122                         "<feGaussianBlur in=\"SourceAlpha\" stdDeviation=\"%f\" result=\"blur\"/>\n"
123                         "<feColorMatrix result=\"bluralpha\" type=\"matrix\" values=\"-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 %f 0 \" />\n"
124                         "<feOffset in=\"bluralpha\" dx=\"%f\" dy=\"%f\" result=\"offsetBlur\"/>\n"
125                         "<feMerge>\n"
126                                 "<feMergeNode in=\"offsetBlur\"/>\n"
127                                 "<feMergeNode in=\"SourceGraphic\"/>\n"
128                         "</feMerge>\n"
129                 "</filter>\n", blur, opacity, x, y);
131         return _filter;
132 };
134 }; /* namespace Filter */
135 }; /* namespace Internal */
136 }; /* namespace Extension */
137 }; /* namespace Inkscape */
139 /* Change the 'DROP_SHADOW' below to be your file name */
140 #endif /* __INKSCAPE_EXTENSION_INTERNAL_FILTER_DROP_SHADOW_H__ */