1 #define __SP_FETILE_CPP__
3 /** \file
4 * SVG <feTile> 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-fetile.h"
23 #include "xml/repr.h"
26 /* FeTile base class */
28 static void sp_feTile_class_init(SPFeTileClass *klass);
29 static void sp_feTile_init(SPFeTile *feTile);
31 static void sp_feTile_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
32 static void sp_feTile_release(SPObject *object);
33 static void sp_feTile_set(SPObject *object, unsigned int key, gchar const *value);
34 static void sp_feTile_update(SPObject *object, SPCtx *ctx, guint flags);
35 static Inkscape::XML::Node *sp_feTile_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
36 static void sp_feTile_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter);
38 static SPFilterPrimitiveClass *feTile_parent_class;
40 GType
41 sp_feTile_get_type()
42 {
43 static GType feTile_type = 0;
45 if (!feTile_type) {
46 GTypeInfo feTile_info = {
47 sizeof(SPFeTileClass),
48 NULL, NULL,
49 (GClassInitFunc) sp_feTile_class_init,
50 NULL, NULL,
51 sizeof(SPFeTile),
52 16,
53 (GInstanceInitFunc) sp_feTile_init,
54 NULL, /* value_table */
55 };
56 feTile_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeTile", &feTile_info, (GTypeFlags)0);
57 }
58 return feTile_type;
59 }
61 static void
62 sp_feTile_class_init(SPFeTileClass *klass)
63 {
64 SPObjectClass *sp_object_class = (SPObjectClass *)klass;
65 SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass;
67 feTile_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass);
69 sp_object_class->build = sp_feTile_build;
70 sp_object_class->release = sp_feTile_release;
71 sp_object_class->write = sp_feTile_write;
72 sp_object_class->set = sp_feTile_set;
73 sp_object_class->update = sp_feTile_update;
74 sp_primitive_class->build_renderer = sp_feTile_build_renderer;
75 }
77 static void
78 sp_feTile_init(SPFeTile */*feTile*/)
79 {
80 }
82 /**
83 * Reads the Inkscape::XML::Node, and initializes SPFeTile 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_feTile_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
89 {
90 if (((SPObjectClass *) feTile_parent_class)->build) {
91 ((SPObjectClass *) feTile_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_feTile_release(SPObject *object)
102 {
103 if (((SPObjectClass *) feTile_parent_class)->release)
104 ((SPObjectClass *) feTile_parent_class)->release(object);
105 }
107 /**
108 * Sets a specific value in the SPFeTile.
109 */
110 static void
111 sp_feTile_set(SPObject *object, unsigned int key, gchar const *value)
112 {
113 SPFeTile *feTile = SP_FETILE(object);
114 (void)feTile;
116 switch(key) {
117 /*DEAL WITH SETTING ATTRIBUTES HERE*/
118 default:
119 if (((SPObjectClass *) feTile_parent_class)->set)
120 ((SPObjectClass *) feTile_parent_class)->set(object, key, value);
121 break;
122 }
124 }
126 /**
127 * Receives update notifications.
128 */
129 static void
130 sp_feTile_update(SPObject *object, SPCtx *ctx, guint flags)
131 {
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 *) feTile_parent_class)->update) {
140 ((SPObjectClass *) feTile_parent_class)->update(object, ctx, flags);
141 }
142 }
144 /**
145 * Writes its settings to an incoming repr object, if any.
146 */
147 static Inkscape::XML::Node *
148 sp_feTile_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
149 {
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 *) feTile_parent_class)->write) {
161 ((SPObjectClass *) feTile_parent_class)->write(object, repr, flags);
162 }
164 return repr;
165 }
167 static void sp_feTile_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter) {
168 g_assert(primitive != NULL);
169 g_assert(filter != NULL);
171 SPFeTile *sp_tile = SP_FETILE(primitive);
172 (void)sp_tile;
174 int primitive_n = filter->add_primitive(NR::NR_FILTER_TILE);
175 NR::FilterPrimitive *nr_primitive = filter->get_primitive(primitive_n);
176 NR::FilterTile *nr_tile = dynamic_cast<NR::FilterTile*>(nr_primitive);
177 g_assert(nr_tile != NULL);
179 sp_filter_primitive_renderer_common(primitive, nr_primitive);
180 }
182 /*
183 Local Variables:
184 mode:c++
185 c-file-style:"stroustrup"
186 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
187 indent-tabs-mode:nil
188 fill-column:99
189 End:
190 */
191 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :