Code

copyedit
[inkscape.git] / src / sp-feflood.cpp
1 #define __SP_FEFLOOD_CPP__
3 /** \file
4  * SVG <feFlood> 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-feflood.h"
23 #include "xml/repr.h"
26 /* FeFlood base class */
28 static void sp_feFlood_class_init(SPFeFloodClass *klass);
29 static void sp_feFlood_init(SPFeFlood *feFlood);
31 static void sp_feFlood_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
32 static void sp_feFlood_release(SPObject *object);
33 static void sp_feFlood_set(SPObject *object, unsigned int key, gchar const *value);
34 static void sp_feFlood_update(SPObject *object, SPCtx *ctx, guint flags);
35 static Inkscape::XML::Node *sp_feFlood_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
36 static void sp_feFlood_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter);
38 static SPFilterPrimitiveClass *feFlood_parent_class;
40 GType
41 sp_feFlood_get_type()
42 {
43     static GType feFlood_type = 0;
45     if (!feFlood_type) {
46         GTypeInfo feFlood_info = {
47             sizeof(SPFeFloodClass),
48             NULL, NULL,
49             (GClassInitFunc) sp_feFlood_class_init,
50             NULL, NULL,
51             sizeof(SPFeFlood),
52             16,
53             (GInstanceInitFunc) sp_feFlood_init,
54             NULL,    /* value_table */
55         };
56         feFlood_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeFlood", &feFlood_info, (GTypeFlags)0);
57     }
58     return feFlood_type;
59 }
61 static void
62 sp_feFlood_class_init(SPFeFloodClass *klass)
63 {
64     SPObjectClass *sp_object_class = (SPObjectClass *)klass;
65     SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass;
67     feFlood_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass);
69     sp_object_class->build = sp_feFlood_build;
70     sp_object_class->release = sp_feFlood_release;
71     sp_object_class->write = sp_feFlood_write;
72     sp_object_class->set = sp_feFlood_set;
73     sp_object_class->update = sp_feFlood_update;
74     sp_primitive_class->build_renderer = sp_feFlood_build_renderer;
75 }
77 static void
78 sp_feFlood_init(SPFeFlood */*feFlood*/)
79 {
80 }
82 /**
83  * Reads the Inkscape::XML::Node, and initializes SPFeFlood variables.  For this to get called,
84  * our name must be associated with a repr via "sp_object_type_register".  Best done through
85  * sp-object-repr.cpp's repr_name_entries array.
86  */
87 static void
88 sp_feFlood_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
89 {
90     if (((SPObjectClass *) feFlood_parent_class)->build) {
91         ((SPObjectClass *) feFlood_parent_class)->build(object, document, repr);
92     }
94     /*LOAD ATTRIBUTES FROM REPR HERE*/
95 }
97 /**
98  * Drops any allocated memory.
99  */
100 static void
101 sp_feFlood_release(SPObject *object)
103     if (((SPObjectClass *) feFlood_parent_class)->release)
104         ((SPObjectClass *) feFlood_parent_class)->release(object);
107 /**
108  * Sets a specific value in the SPFeFlood.
109  */
110 static void
111 sp_feFlood_set(SPObject *object, unsigned int key, gchar const *value)
113     SPFeFlood *feFlood = SP_FEFLOOD(object);
114     (void)feFlood;
116     switch(key) {
117         /*DEAL WITH SETTING ATTRIBUTES HERE*/
118         default:
119             if (((SPObjectClass *) feFlood_parent_class)->set)
120                 ((SPObjectClass *) feFlood_parent_class)->set(object, key, value);
121             break;
122     }
126 /**
127  * Receives update notifications.
128  */
129 static void
130 sp_feFlood_update(SPObject *object, SPCtx *ctx, guint flags)
132     if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG |
133                  SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
135         /* do something to trigger redisplay, updates? */
137     }
139     if (((SPObjectClass *) feFlood_parent_class)->update) {
140         ((SPObjectClass *) feFlood_parent_class)->update(object, ctx, flags);
141     }
144 /**
145  * Writes its settings to an incoming repr object, if any.
146  */
147 static Inkscape::XML::Node *
148 sp_feFlood_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
150     // Inkscape-only object, not copied during an "plain SVG" dump:
151     if (flags & SP_OBJECT_WRITE_EXT) {
152         if (repr) {
153             // is this sane?
154             //repr->mergeFrom(SP_OBJECT_REPR(object), "id");
155         } else {
156             repr = SP_OBJECT_REPR(object)->duplicate(NULL); // FIXME
157         }
158     }
160     if (((SPObjectClass *) feFlood_parent_class)->write) {
161         ((SPObjectClass *) feFlood_parent_class)->write(object, repr, flags);
162     }
164     return repr;
167 static void sp_feFlood_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter) {
168     g_assert(primitive != NULL);
169     g_assert(filter != NULL);
171     SPFeFlood *sp_flood = SP_FEFLOOD(primitive);
172     (void)sp_flood;
174     int primitive_n = filter->add_primitive(NR::NR_FILTER_FLOOD);
175     NR::FilterPrimitive *nr_primitive = filter->get_primitive(primitive_n);
176     NR::FilterFlood *nr_flood = dynamic_cast<NR::FilterFlood*>(nr_primitive);
177     g_assert(nr_flood != NULL);
179     sp_filter_primitive_renderer_common(primitive, nr_primitive);
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 :