Code

Extensions. Compressed+media export improvements (see Bug #386664, Gather Resources...
[inkscape.git] / src / filters / tile.cpp
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 "tile.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::Document *doc, Inkscape::XML::Node *repr, guint flags);
36 static void sp_feTile_build_renderer(SPFilterPrimitive *primitive, Inkscape::Filters::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)
103     if (((SPObjectClass *) feTile_parent_class)->release)
104         ((SPObjectClass *) feTile_parent_class)->release(object);
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)
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     }
126 /**
127  * Receives update notifications.
128  */
129 static void
130 sp_feTile_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 *) feTile_parent_class)->update) {
140         ((SPObjectClass *) feTile_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_feTile_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags)
150     /* TODO: Don't just clone, but create a new repr node and write all
151      * relevant values into it */
152     if (!repr) {
153         repr = SP_OBJECT_REPR(object)->duplicate(doc);
154     }
156     if (((SPObjectClass *) feTile_parent_class)->write) {
157         ((SPObjectClass *) feTile_parent_class)->write(object, doc, repr, flags);
158     }
160     return repr;
163 static void sp_feTile_build_renderer(SPFilterPrimitive *primitive, Inkscape::Filters::Filter *filter) {
164     g_assert(primitive != NULL);
165     g_assert(filter != NULL);
167     SPFeTile *sp_tile = SP_FETILE(primitive);
168     (void)sp_tile;
170     int primitive_n = filter->add_primitive(Inkscape::Filters::NR_FILTER_TILE);
171     Inkscape::Filters::FilterPrimitive *nr_primitive = filter->get_primitive(primitive_n);
172     Inkscape::Filters::FilterTile *nr_tile = dynamic_cast<Inkscape::Filters::FilterTile*>(nr_primitive);
173     g_assert(nr_tile != NULL);
175     sp_filter_primitive_renderer_common(primitive, nr_primitive);
178 /*
179   Local Variables:
180   mode:c++
181   c-file-style:"stroustrup"
182   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
183   indent-tabs-mode:nil
184   fill-column:99
185   End:
186 */
187 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :