Code

Status bar tips for VP draggers
[inkscape.git] / src / sp-feimage.cpp
1         #define __SP_FEIMAGE_CPP__
3 /** \file
4  * SVG <feImage> implementation.
5  *
6  */
7 /*
8  * Authors:
9  *   Felipe CorrĂȘa da Silva Sanches <felipe.sanches@gmail.com>
10  *   hugo Rodrigues <haa.rodrigues@gmail.com>
11  *
12  * Copyright (C) 2007 Felipe Sanches
13  * Copyright (C) 2006 Hugo Rodrigues
14  *
15  * Released under GNU GPL, read the file 'COPYING' for more information
16  */
18 #ifdef HAVE_CONFIG_H
19 # include "config.h"
20 #endif
22 #include "attributes.h"
23 #include "svg/svg.h"
24 #include "sp-feimage.h"
25 #include "xml/repr.h"
26 #include <string.h>
28 #include "display/nr-filter.h"
29 #include "display/nr-filter-image.h"
31 /* FeImage base class */
33 static void sp_feImage_class_init(SPFeImageClass *klass);
34 static void sp_feImage_init(SPFeImage *feImage);
36 static void sp_feImage_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
37 static void sp_feImage_release(SPObject *object);
38 static void sp_feImage_set(SPObject *object, unsigned int key, gchar const *value);
39 static void sp_feImage_update(SPObject *object, SPCtx *ctx, guint flags);
40 static Inkscape::XML::Node *sp_feImage_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
41 static void sp_feImage_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter);
43 static SPFilterPrimitiveClass *feImage_parent_class;
45 GType
46 sp_feImage_get_type()
47 {
48     static GType feImage_type = 0;
50     if (!feImage_type) {
51         GTypeInfo feImage_info = {
52             sizeof(SPFeImageClass),
53             NULL, NULL,
54             (GClassInitFunc) sp_feImage_class_init,
55             NULL, NULL,
56             sizeof(SPFeImage),
57             16,
58             (GInstanceInitFunc) sp_feImage_init,
59             NULL,    /* value_table */
60         };
61         feImage_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeImage", &feImage_info, (GTypeFlags)0);
62     }
63     return feImage_type;
64 }
66 static void
67 sp_feImage_class_init(SPFeImageClass *klass)
68 {
69     SPObjectClass *sp_object_class = (SPObjectClass *)klass;
70     SPFilterPrimitiveClass * sp_primitive_class = (SPFilterPrimitiveClass *)klass;
72     feImage_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass);
74     sp_object_class->build = sp_feImage_build;
75     sp_object_class->release = sp_feImage_release;
76     sp_object_class->write = sp_feImage_write;
77     sp_object_class->set = sp_feImage_set;
78     sp_object_class->update = sp_feImage_update;
80     sp_primitive_class->build_renderer = sp_feImage_build_renderer;
81 }
83 static void
84 sp_feImage_init(SPFeImage *feImage)
85 {
86 }
88 /**
89  * Reads the Inkscape::XML::Node, and initializes SPFeImage variables.  For this to get called,
90  * our name must be associated with a repr via "sp_object_type_register".  Best done through
91  * sp-object-repr.cpp's repr_name_entries array.
92  */
93 static void
94 sp_feImage_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
95 {
96     if (((SPObjectClass *) feImage_parent_class)->build) {
97         ((SPObjectClass *) feImage_parent_class)->build(object, document, repr);
98     }
100     /*LOAD ATTRIBUTES FROM REPR HERE*/
101 /* apparently there's no attribute to load here 
102 since 'in' and 'xlink:href' are common filter attributes.
103 --Juca
104 */
108 /**
109  * Drops any allocated memory.
110  */
111 static void
112 sp_feImage_release(SPObject *object)
115     if (((SPObjectClass *) feImage_parent_class)->release)
116         ((SPObjectClass *) feImage_parent_class)->release(object);
119 /**
120  * Sets a specific value in the SPFeImage.
121  */
122 static void
123 sp_feImage_set(SPObject *object, unsigned int key, gchar const *value)
125     SPFeImage *feImage = SP_FEIMAGE(object);
126     (void)feImage;
128     switch(key) {
129         /*DEAL WITH SETTING ATTRIBUTES HERE*/
130         default:
131             if (((SPObjectClass *) feImage_parent_class)->set)
132                 ((SPObjectClass *) feImage_parent_class)->set(object, key, value);
133             break;
134     }
138 /**
139  * Receives update notifications.
140  */
141 static void
142 sp_feImage_update(SPObject *object, SPCtx *ctx, guint flags)
144     if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG |
145                  SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
147         /* do something to trigger redisplay, updates? */
149     }
151     if (((SPObjectClass *) feImage_parent_class)->update) {
152         ((SPObjectClass *) feImage_parent_class)->update(object, ctx, flags);
153     }
156 /**
157  * Writes its settings to an incoming repr object, if any.
158  */
159 static Inkscape::XML::Node *
160 sp_feImage_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
162     // Inkscape-only object, not copied during an "plain SVG" dump:
163     if (flags & SP_OBJECT_WRITE_EXT) {
164         if (repr) {
165             // is this sane?
166             repr->mergeFrom(SP_OBJECT_REPR(object), "id");
167         } else {
168             repr = SP_OBJECT_REPR(object)->duplicate(NULL); // FIXME
169         }
170     }
172     if (((SPObjectClass *) feImage_parent_class)->write) {
173         ((SPObjectClass *) feImage_parent_class)->write(object, repr, flags);
174     }
176     return repr;
179 static void sp_feImage_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter) {
180     g_assert(primitive != NULL);
181     g_assert(filter != NULL);
183     SPFeImage *sp_image = SP_FEIMAGE(primitive);
185     int primitive_n = filter->add_primitive(NR::NR_FILTER_IMAGE);
186     NR::FilterPrimitive *nr_primitive = filter->get_primitive(primitive_n);
187     NR::FilterImage *nr_image = dynamic_cast<NR::FilterImage*>(nr_primitive);
188     g_assert(nr_image != NULL);
190     sp_filter_primitive_renderer_common(primitive, nr_primitive);
194 /*
195   Local Variables:
196   mode:c++
197   c-file-style:"stroustrup"
198   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
199   indent-tabs-mode:nil
200   fill-column:99
201   End:
202 */
203 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :