1 #ifndef __INKSCAPE_EXTENSION_INTERNAL_FILTER_SHADOWS_H__
2 #define __INKSCAPE_EXTENSION_INTERNAL_FILTER_SHADOWS_H__
3 /* Change the 'SHADOWS' above to be your file name */
5 /*
6 * Copyright (C) 2011 Authors:
7 * Ivan Louette (filters)
8 * Nicolas Dufour (UI) <nicoduf@yahoo.fr>
9 *
10 * Color filters
11 * Drop shadow
12 *
13 * Released under GNU GPL, read the file 'COPYING' for more information
14 */
15 /* ^^^ Change the copyright to be you and your e-mail address ^^^ */
17 #include "filter.h"
19 #include "extension/internal/clear-n_.h"
20 #include "extension/system.h"
21 #include "extension/extension.h"
23 namespace Inkscape {
24 namespace Extension {
25 namespace Internal {
26 namespace Filter {
28 /**
29 \brief Custom predefined Drop shadow filter.
31 Colorizable Drop shadow.
33 Filter's parameters:
34 * Blur radius (0.->200., default 3) -> blur (stdDeviation)
35 * Horizontal offset (-50.->50., default 6.0) -> offset (dx)
36 * Vertical offset (-50.->50., default 6.0) -> offset (dy)
37 * Color (guint, default 0,0,0,127) -> flood (flood-opacity, flood-color)
38 */
39 class ColorizableDropShadow : public Inkscape::Extension::Internal::Filter::Filter {
40 protected:
41 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
43 public:
44 ColorizableDropShadow ( ) : Filter() { };
45 virtual ~ColorizableDropShadow ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
47 static void init (void) {
48 Inkscape::Extension::build_from_mem(
49 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
50 "<name>" N_("Drop shadow, custom (Shadows and Glows)") "</name>\n"
51 "<id>org.inkscape.effect.filter.ColorDropShadow</id>\n"
52 "<param name=\"blur\" gui-text=\"" N_("Blur radius (px):") "\" type=\"float\" min=\"0.0\" max=\"200.0\">3.0</param>\n"
53 "<param name=\"xoffset\" gui-text=\"" N_("Horizontal offset (px):") "\" type=\"float\" min=\"-50.0\" max=\"50.0\">6.0</param>\n"
54 "<param name=\"yoffset\" gui-text=\"" N_("Vertical offset (px):") "\" type=\"float\" min=\"-50.0\" max=\"50.0\">6.0</param>\n"
55 "<param name=\"color\" gui-text=\"" N_("Color") "\" type=\"color\">127</param>\n"
56 "<effect>\n"
57 "<object-type>all</object-type>\n"
58 "<effects-menu>\n"
59 "<submenu name=\"" N_("Filters") "\">\n"
60 "<submenu name=\"" N_("Experimental") "\"/>\n"
61 "</submenu>\n"
62 "</effects-menu>\n"
63 "<menu-tip>" N_("Colorizable Drop shadow") "</menu-tip>\n"
64 "</effect>\n"
65 "</inkscape-extension>\n", new ColorizableDropShadow());
66 };
68 };
70 gchar const *
71 ColorizableDropShadow::get_filter_text (Inkscape::Extension::Extension * ext)
72 {
73 if (_filter != NULL) g_free((void *)_filter);
75 std::ostringstream blur;
76 std::ostringstream a;
77 std::ostringstream r;
78 std::ostringstream g;
79 std::ostringstream b;
80 std::ostringstream x;
81 std::ostringstream y;
83 guint32 color = ext->get_param_color("color");
85 blur << ext->get_param_float("blur");
86 x << ext->get_param_float("xoffset");
87 y << ext->get_param_float("yoffset");
88 a << (color & 0xff) / 255.0F;
89 r << ((color >> 24) & 0xff);
90 g << ((color >> 16) & 0xff);
91 b << ((color >> 8) & 0xff);
93 _filter = g_strdup_printf(
94 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" color-interpolation-filters=\"sRGB\" height=\"1.2\" width=\"1.2\" y=\"-0.1\" x=\"-0.1\" inkscape:label=\"Drop shadow, custom\">\n"
95 "<feFlood flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood\" />\n"
96 "<feComposite in=\"flood\" in2=\"SourceGraphic\" operator=\"in\" result=\"composite1\" />\n"
97 "<feGaussianBlur in=\"composite1\" stdDeviation=\"%s\" result=\"blur\" />\n"
98 "<feOffset dx=\"%s\" dy=\"%s\" result=\"offset\" />\n"
99 "<feComposite in=\"SourceGraphic\" in2=\"offset\" operator=\"over\" result=\"composite2\" />\n"
100 "</filter>\n", a.str().c_str(), r.str().c_str(), g.str().c_str(), b.str().c_str(), blur.str().c_str(), x.str().c_str(), y.str().c_str());
102 return _filter;
103 };
105 }; /* namespace Filter */
106 }; /* namespace Internal */
107 }; /* namespace Extension */
108 }; /* namespace Inkscape */
110 /* Change the 'SHADOWS' below to be your file name */
111 #endif /* __INKSCAPE_EXTENSION_INTERNAL_FILTER_SHADOWS_H__ */