Code

boilerplate code for the remaining filters. My next commits will
[inkscape.git] / src / sp-fecolormatrix.cpp
1 #define __SP_FECOLORMATRIX_CPP__
3 /** \file
4  * SVG <feColorMatrix> 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-fecolormatrix.h"
23 #include "xml/repr.h"
26 /* FeColorMatrix base class */
28 static void sp_feColorMatrix_class_init(SPFeColorMatrixClass *klass);
29 static void sp_feColorMatrix_init(SPFeColorMatrix *feColorMatrix);
31 static void sp_feColorMatrix_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
32 static void sp_feColorMatrix_release(SPObject *object);
33 static void sp_feColorMatrix_set(SPObject *object, unsigned int key, gchar const *value);
34 static void sp_feColorMatrix_update(SPObject *object, SPCtx *ctx, guint flags);
35 static Inkscape::XML::Node *sp_feColorMatrix_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
36 static void sp_feColorMatrix_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter);
38 static SPFilterPrimitiveClass *feColorMatrix_parent_class;
40 GType
41 sp_feColorMatrix_get_type()
42 {
43     static GType feColorMatrix_type = 0;
45     if (!feColorMatrix_type) {
46         GTypeInfo feColorMatrix_info = {
47             sizeof(SPFeColorMatrixClass),
48             NULL, NULL,
49             (GClassInitFunc) sp_feColorMatrix_class_init,
50             NULL, NULL,
51             sizeof(SPFeColorMatrix),
52             16,
53             (GInstanceInitFunc) sp_feColorMatrix_init,
54             NULL,    /* value_table */
55         };
56         feColorMatrix_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeColorMatrix", &feColorMatrix_info, (GTypeFlags)0);
57     }
58     return feColorMatrix_type;
59 }
61 static void
62 sp_feColorMatrix_class_init(SPFeColorMatrixClass *klass)
63 {
64     SPObjectClass *sp_object_class = (SPObjectClass *)klass;
65     SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass;
66     
67     feColorMatrix_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass);
69     sp_object_class->build = sp_feColorMatrix_build;
70     sp_object_class->release = sp_feColorMatrix_release;
71     sp_object_class->write = sp_feColorMatrix_write;
72     sp_object_class->set = sp_feColorMatrix_set;
73     sp_object_class->update = sp_feColorMatrix_update;
74     sp_primitive_class->build_renderer = sp_feColorMatrix_build_renderer;
75 }
77 static void
78 sp_feColorMatrix_init(SPFeColorMatrix *feColorMatrix)
79 {
80 }
82 /**
83  * Reads the Inkscape::XML::Node, and initializes SPFeColorMatrix 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_feColorMatrix_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
89 {
90     if (((SPObjectClass *) feColorMatrix_parent_class)->build) {
91         ((SPObjectClass *) feColorMatrix_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_feColorMatrix_release(SPObject *object)
103     if (((SPObjectClass *) feColorMatrix_parent_class)->release)
104         ((SPObjectClass *) feColorMatrix_parent_class)->release(object);
107 /**
108  * Sets a specific value in the SPFeColorMatrix.
109  */
110 static void
111 sp_feColorMatrix_set(SPObject *object, unsigned int key, gchar const *value)
113     SPFeColorMatrix *feColorMatrix = SP_FECOLORMATRIX(object);
114     (void)feColorMatrix;
116     switch(key) {
117         /*DEAL WITH SETTING ATTRIBUTES HERE*/
118         default:
119             if (((SPObjectClass *) feColorMatrix_parent_class)->set)
120                 ((SPObjectClass *) feColorMatrix_parent_class)->set(object, key, value);
121             break;
122     }
126 /**
127  * Receives update notifications.
128  */
129 static void
130 sp_feColorMatrix_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 *) feColorMatrix_parent_class)->update) {
140         ((SPObjectClass *) feColorMatrix_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_feColorMatrix_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 *) feColorMatrix_parent_class)->write) {
161         ((SPObjectClass *) feColorMatrix_parent_class)->write(object, repr, flags);
162     }
164     return repr;
167 static void sp_feColorMatrix_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter) {
168     g_assert(primitive != NULL);
169     g_assert(filter != NULL);
171     SPFeColorMatrix *sp_colormatrix = SP_FECOLORMATRIX(primitive);
173     int primitive_n = filter->add_primitive(NR::NR_FILTER_COLORMATRIX);
174     NR::FilterPrimitive *nr_primitive = filter->get_primitive(primitive_n);
175     NR::FilterColorMatrix *nr_colormatrix = dynamic_cast<NR::FilterColorMatrix*>(nr_primitive);
176     g_assert(nr_colormatrix != NULL);
178     sp_filter_primitive_renderer_common(primitive, nr_primitive);
181 /*
182   Local Variables:
183   mode:c++
184   c-file-style:"stroustrup"
185   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
186   indent-tabs-mode:nil
187   fill-column:99
188   End:
189 */
190 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :