63680a10bf5ad238cd9fab01de0b38e6e1c26a99
1 #define __SP_GAUSSIANBLUR_CPP__
3 /** \file
4 * SVG <gaussianBlur> implementation.
5 *
6 */
7 /*
8 * Authors:
9 * hugo Rodrigues <haa.rodrigues@gmail.com>
10 *
11 * Copyright (C) 2006 Hugo Rodrigues
12 *
13 * Released under GNU GPL, read the file 'COPYING' for more information
14 */
16 #ifdef HAVE_CONFIG_H
17 # include "config.h"
18 #endif
20 #include "attributes.h"
21 #include "svg/svg.h"
22 #include "sp-gaussian-blur.h"
23 #include "xml/repr.h"
25 //#define SP_MACROS_SILENT
26 //#include "macros.h"
28 /* GaussianBlur base class */
30 static void sp_gaussianBlur_class_init(SPGaussianBlurClass *klass);
31 static void sp_gaussianBlur_init(SPGaussianBlur *gaussianBlur);
33 static void sp_gaussianBlur_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
34 static void sp_gaussianBlur_release(SPObject *object);
35 static void sp_gaussianBlur_set(SPObject *object, unsigned int key, gchar const *value);
36 static void sp_gaussianBlur_update(SPObject *object, SPCtx *ctx, guint flags);
37 static Inkscape::XML::Node *sp_gaussianBlur_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
39 static SPFilterPrimitiveClass *gaussianBlur_parent_class;
41 GType
42 sp_gaussianBlur_get_type()
43 {
44 static GType gaussianBlur_type = 0;
46 if (!gaussianBlur_type) {
47 GTypeInfo gaussianBlur_info = {
48 sizeof(SPGaussianBlurClass),
49 NULL, NULL,
50 (GClassInitFunc) sp_gaussianBlur_class_init,
51 NULL, NULL,
52 sizeof(SPGaussianBlur),
53 16,
54 (GInstanceInitFunc) sp_gaussianBlur_init,
55 NULL, /* value_table */
56 };
57 gaussianBlur_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPGaussianBlur", &gaussianBlur_info, (GTypeFlags)0);
58 }
59 return gaussianBlur_type;
60 }
62 static void
63 sp_gaussianBlur_class_init(SPGaussianBlurClass *klass)
64 {
65 SPObjectClass *sp_object_class = (SPObjectClass *)klass;
67 gaussianBlur_parent_class = (SPFilterPrimitiveClass *)g_type_class_peek_parent(klass);
69 sp_object_class->build = sp_gaussianBlur_build;
70 sp_object_class->release = sp_gaussianBlur_release;
71 sp_object_class->write = sp_gaussianBlur_write;
72 sp_object_class->set = sp_gaussianBlur_set;
73 sp_object_class->update = sp_gaussianBlur_update;
74 }
76 static void
77 sp_gaussianBlur_init(SPGaussianBlur *gaussianBlur)
78 {
79 }
81 /**
82 * Reads the Inkscape::XML::Node, and initializes SPGaussianBlur variables. For this to get called,
83 * our name must be associated with a repr via "sp_object_type_register". Best done through
84 * sp-object-repr.cpp's repr_name_entries array.
85 */
86 static void
87 sp_gaussianBlur_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
88 {
89 if (((SPObjectClass *) gaussianBlur_parent_class)->build) {
90 ((SPObjectClass *) gaussianBlur_parent_class)->build(object, document, repr);
91 }
93 sp_object_read_attr(object, "stdDeviation");
95 }
97 /**
98 * Drops any allocated memory.
99 */
100 static void
101 sp_gaussianBlur_release(SPObject *object)
102 {
104 if (((SPObjectClass *) gaussianBlur_parent_class)->release)
105 ((SPObjectClass *) gaussianBlur_parent_class)->release(object);
106 }
108 /**
109 * Sets a specific value in the SPGaussianBlur.
110 */
111 static void
112 sp_gaussianBlur_set(SPObject *object, unsigned int key, gchar const *value)
113 {
114 SPGaussianBlur *gaussianBlur = SP_GAUSSIANBLUR(object);
116 switch(key) {
117 case SP_ATTR_STDDEVIATION:
118 gaussianBlur->stdDeviation.set(value);
119 break;
120 default:
121 if (((SPObjectClass *) gaussianBlur_parent_class)->set)
122 ((SPObjectClass *) gaussianBlur_parent_class)->set(object, key, value);
123 break;
124 }
126 }
128 /**
129 * Receives update notifications.
130 */
131 static void
132 sp_gaussianBlur_update(SPObject *object, SPCtx *ctx, guint flags)
133 {
135 if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG |
136 SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
138 /* do something to trigger redisplay, updates? */
140 }
142 if (((SPObjectClass *) gaussianBlur_parent_class)->update) {
143 ((SPObjectClass *) gaussianBlur_parent_class)->update(object, ctx, flags);
144 }
145 }
147 /**
148 * Writes its settings to an incoming repr object, if any.
149 */
150 static Inkscape::XML::Node *
151 sp_gaussianBlur_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
152 {
154 // Inkscape-only object, not copied during an "plain SVG" dump:
155 if (flags & SP_OBJECT_WRITE_EXT) {
156 if (repr) {
157 // is this sane?
158 // repr->mergeFrom(SP_OBJECT_REPR(object), "id");
159 } else {
160 repr = SP_OBJECT_REPR(object)->duplicate();
161 }
162 }
164 if (((SPObjectClass *) gaussianBlur_parent_class)->write) {
165 ((SPObjectClass *) gaussianBlur_parent_class)->write(object, repr, flags);
166 }
168 return repr;
169 }
172 void sp_gaussianBlur_setDeviation(SPGaussianBlur *blur, float num)
173 {
174 blur->stdDeviation.setNumber(num);
175 }
176 void sp_gaussianBlur_setDeviation(SPGaussianBlur *blur, float num, float optnum)
177 {
178 blur->stdDeviation.setNumber(num);
179 blur->stdDeviation.setOptNumber(optnum);
180 }
183 /*
184 Local Variables:
185 mode:c++
186 c-file-style:"stroustrup"
187 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
188 indent-tabs-mode:nil
189 fill-column:99
190 End:
191 */
192 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :