Code

Added skeleton files for other filter primitives' SP-objects. Added blur slider on...
[inkscape.git] / src / sp-feblend.cpp
1 #define __SP_FEBLEND_CPP__
3 /** \file
4  * SVG <feBlend> 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-feblend.h"
23 #include "xml/repr.h"
25 //#define SP_MACROS_SILENT
26 //#include "macros.h"
28 #define DEBUG_FEBLEND
29 #ifdef DEBUG_FEBLEND
30 # define debug(f, a...) { g_print("%s(%d) %s:", \
31                                   __FILE__,__LINE__,__FUNCTION__); \
32                           g_print(f, ## a); \
33                           g_print("\n"); \
34                         }
35 #else
36 # define debug(f, a...) /**/
37 #endif
39 /* FeBlend base class */
41 static void sp_feBlend_class_init(SPFeBlendClass *klass);
42 static void sp_feBlend_init(SPFeBlend *feBlend);
44 static void sp_feBlend_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
45 static void sp_feBlend_release(SPObject *object);
46 static void sp_feBlend_set(SPObject *object, unsigned int key, gchar const *value);
47 static void sp_feBlend_update(SPObject *object, SPCtx *ctx, guint flags);
48 static Inkscape::XML::Node *sp_feBlend_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
50 static SPObjectClass *feBlend_parent_class;
52 GType
53 sp_feBlend_get_type()
54 {
55     static GType feBlend_type = 0;
57     if (!feBlend_type) {
58         GTypeInfo feBlend_info = {
59             sizeof(SPFeBlendClass),
60             NULL, NULL,
61             (GClassInitFunc) sp_feBlend_class_init,
62             NULL, NULL,
63             sizeof(SPFeBlend),
64             16,
65             (GInstanceInitFunc) sp_feBlend_init,
66             NULL,    /* value_table */
67         };
68         feBlend_type = g_type_register_static(SP_TYPE_OBJECT, "SPFeBlend", &feBlend_info, (GTypeFlags)0);
69     }
70     return feBlend_type;
71 }
73 static void
74 sp_feBlend_class_init(SPFeBlendClass *klass)
75 {
76     SPObjectClass *sp_object_class = (SPObjectClass *)klass;
78     feBlend_parent_class = (SPObjectClass*)g_type_class_peek_parent(klass);
80     sp_object_class->build = sp_feBlend_build;
81     sp_object_class->release = sp_feBlend_release;
82     sp_object_class->write = sp_feBlend_write;
83     sp_object_class->set = sp_feBlend_set;
84     sp_object_class->update = sp_feBlend_update;
85 }
87 static void
88 sp_feBlend_init(SPFeBlend *feBlend)
89 {
90     debug("0x%p",feBlend);
91 }
93 /**
94  * Reads the Inkscape::XML::Node, and initializes SPFeBlend variables.  For this to get called,
95  * our name must be associated with a repr via "sp_object_type_register".  Best done through
96  * sp-object-repr.cpp's repr_name_entries array.
97  */
98 static void
99 sp_feBlend_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
101     debug("0x%p",object);
102     if (((SPObjectClass *) feBlend_parent_class)->build) {
103         ((SPObjectClass *) feBlend_parent_class)->build(object, document, repr);
104     }
106     /*LOAD ATTRIBUTES FROM REPR HERE*/
109 /**
110  * Drops any allocated memory.
111  */
112 static void
113 sp_feBlend_release(SPObject *object)
115     debug("0x%p",object);
117     if (((SPObjectClass *) feBlend_parent_class)->release)
118         ((SPObjectClass *) feBlend_parent_class)->release(object);
121 /**
122  * Sets a specific value in the SPFeBlend.
123  */
124 static void
125 sp_feBlend_set(SPObject *object, unsigned int key, gchar const *value)
127     debug("0x%p %s(%u): '%s'",object,
128             sp_attribute_name(key),key,value);
129     SPFeBlend *feBlend = SP_FEBLEND(object);
131     switch(key) {\r
132         /*DEAL WITH SETTING ATTRIBUTES HERE*/
133         default:
134             if (((SPObjectClass *) feBlend_parent_class)->set)
135                 ((SPObjectClass *) feBlend_parent_class)->set(object, key, value);
136             break;
137     }
141 /**
142  * Receives update notifications.
143  */
144 static void
145 sp_feBlend_update(SPObject *object, SPCtx *ctx, guint flags)
147     debug("0x%p",object);
149     if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG |
150                  SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
152         /* do something to trigger redisplay, updates? */
154     }
156     if (((SPObjectClass *) feBlend_parent_class)->update) {
157         ((SPObjectClass *) feBlend_parent_class)->update(object, ctx, flags);
158     }
161 /**
162  * Writes its settings to an incoming repr object, if any.
163  */
164 static Inkscape::XML::Node *
165 sp_feBlend_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
167     debug("0x%p",object);
169     // Inkscape-only object, not copied during an "plain SVG" dump:
170     if (flags & SP_OBJECT_WRITE_EXT) {
171         if (repr) {
172             // is this sane?
173             repr->mergeFrom(SP_OBJECT_REPR(object), "id");
174         } else {
175             repr = SP_OBJECT_REPR(object)->duplicate();
176         }
177     }
179     if (((SPObjectClass *) feBlend_parent_class)->write) {
180         ((SPObjectClass *) feBlend_parent_class)->write(object, repr, flags);
181     }
183     return repr;
187 /*
188   Local Variables:
189   mode:c++
190   c-file-style:"stroustrup"
191   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
192   indent-tabs-mode:nil
193   fill-column:99
194   End:
195 */
196 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :