~ubuntu-branches/debian/experimental/inkscape/experimental

« back to all changes in this revision

Viewing changes to src/sp-feflood.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-09-09 23:29:02 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080909232902-c50iujhk1w79u8e7
Tags: 0.46-2.1
* Non-maintainer upload.
* Add upstream patch fixing a crash in the open dialog
  in the zh_CN.utf8 locale. Closes: #487623.
  Thanks to Luca Bruno for the patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#define __SP_FEFLOOD_CPP__
 
2
 
 
3
/** \file
 
4
 * SVG <feFlood> 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
 */
 
15
 
 
16
#ifdef HAVE_CONFIG_H
 
17
# include "config.h"
 
18
#endif
 
19
 
 
20
#include "attributes.h"
 
21
#include "svg/svg.h"
 
22
#include "sp-feflood.h"
 
23
#include "xml/repr.h"
 
24
#include "helper-fns.h"
 
25
#include "svg/svg-color.h"
 
26
 
 
27
/* FeFlood base class */
 
28
 
 
29
static void sp_feFlood_class_init(SPFeFloodClass *klass);
 
30
static void sp_feFlood_init(SPFeFlood *feFlood);
 
31
 
 
32
static void sp_feFlood_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
 
33
static void sp_feFlood_release(SPObject *object);
 
34
static void sp_feFlood_set(SPObject *object, unsigned int key, gchar const *value);
 
35
static void sp_feFlood_update(SPObject *object, SPCtx *ctx, guint flags);
 
36
static Inkscape::XML::Node *sp_feFlood_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
 
37
static void sp_feFlood_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter);
 
38
 
 
39
static SPFilterPrimitiveClass *feFlood_parent_class;
 
40
 
 
41
GType
 
42
sp_feFlood_get_type()
 
43
{
 
44
    static GType feFlood_type = 0;
 
45
 
 
46
    if (!feFlood_type) {
 
47
        GTypeInfo feFlood_info = {
 
48
            sizeof(SPFeFloodClass),
 
49
            NULL, NULL,
 
50
            (GClassInitFunc) sp_feFlood_class_init,
 
51
            NULL, NULL,
 
52
            sizeof(SPFeFlood),
 
53
            16,
 
54
            (GInstanceInitFunc) sp_feFlood_init,
 
55
            NULL,    /* value_table */
 
56
        };
 
57
        feFlood_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeFlood", &feFlood_info, (GTypeFlags)0);
 
58
    }
 
59
    return feFlood_type;
 
60
}
 
61
 
 
62
static void
 
63
sp_feFlood_class_init(SPFeFloodClass *klass)
 
64
{
 
65
    SPObjectClass *sp_object_class = (SPObjectClass *)klass;
 
66
    SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass;
 
67
 
 
68
    feFlood_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass);
 
69
 
 
70
    sp_object_class->build = sp_feFlood_build;
 
71
    sp_object_class->release = sp_feFlood_release;
 
72
    sp_object_class->write = sp_feFlood_write;
 
73
    sp_object_class->set = sp_feFlood_set;
 
74
    sp_object_class->update = sp_feFlood_update;
 
75
    sp_primitive_class->build_renderer = sp_feFlood_build_renderer;
 
76
}
 
77
 
 
78
static void
 
79
sp_feFlood_init(SPFeFlood */*feFlood*/)
 
80
{
 
81
}
 
82
 
 
83
/**
 
84
 * Reads the Inkscape::XML::Node, and initializes SPFeFlood variables.  For this to get called,
 
85
 * our name must be associated with a repr via "sp_object_type_register".  Best done through
 
86
 * sp-object-repr.cpp's repr_name_entries array.
 
87
 */
 
88
static void
 
89
sp_feFlood_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
 
90
{
 
91
    if (((SPObjectClass *) feFlood_parent_class)->build) {
 
92
        ((SPObjectClass *) feFlood_parent_class)->build(object, document, repr);
 
93
    }
 
94
 
 
95
    /*LOAD ATTRIBUTES FROM REPR HERE*/
 
96
    sp_object_read_attr(object, "flood-opacity");
 
97
    sp_object_read_attr(object, "flood-color");
 
98
}
 
99
 
 
100
/**
 
101
 * Drops any allocated memory.
 
102
 */
 
103
static void
 
104
sp_feFlood_release(SPObject *object)
 
105
{
 
106
    if (((SPObjectClass *) feFlood_parent_class)->release)
 
107
        ((SPObjectClass *) feFlood_parent_class)->release(object);
 
108
}
 
109
 
 
110
/**
 
111
 * Sets a specific value in the SPFeFlood.
 
112
 */
 
113
static void
 
114
sp_feFlood_set(SPObject *object, unsigned int key, gchar const *value)
 
115
{
 
116
    SPFeFlood *feFlood = SP_FEFLOOD(object);
 
117
    (void)feFlood;
 
118
    gchar const *cend_ptr = NULL;
 
119
    guint32 read_color;
 
120
    double read_num;
 
121
    
 
122
    switch(key) {
 
123
        /*DEAL WITH SETTING ATTRIBUTES HERE*/
 
124
        case SP_PROP_FLOOD_COLOR:
 
125
            cend_ptr = NULL;
 
126
            read_color = sp_svg_read_color(value, &cend_ptr, 0xffffffff);
 
127
            if (cend_ptr && read_color != feFlood->color){
 
128
                feFlood->color = read_color;
 
129
                object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
 
130
            }
 
131
            break;
 
132
        case SP_PROP_FLOOD_OPACITY:
 
133
            read_num = helperfns_read_number(value);
 
134
            if (read_num != feFlood->opacity){
 
135
                feFlood->opacity = read_num;
 
136
                object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
 
137
            }
 
138
            break;
 
139
        default:
 
140
            if (((SPObjectClass *) feFlood_parent_class)->set)
 
141
                ((SPObjectClass *) feFlood_parent_class)->set(object, key, value);
 
142
            break;
 
143
    }
 
144
 
 
145
}
 
146
 
 
147
/**
 
148
 * Receives update notifications.
 
149
 */
 
150
static void
 
151
sp_feFlood_update(SPObject *object, SPCtx *ctx, guint flags)
 
152
{
 
153
    if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG |
 
154
                 SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) {
 
155
 
 
156
        /* do something to trigger redisplay, updates? */
 
157
 
 
158
    }
 
159
 
 
160
    if (((SPObjectClass *) feFlood_parent_class)->update) {
 
161
        ((SPObjectClass *) feFlood_parent_class)->update(object, ctx, flags);
 
162
    }
 
163
}
 
164
 
 
165
/**
 
166
 * Writes its settings to an incoming repr object, if any.
 
167
 */
 
168
static Inkscape::XML::Node *
 
169
sp_feFlood_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
 
170
{
 
171
    // Inkscape-only object, not copied during an "plain SVG" dump:
 
172
    if (flags & SP_OBJECT_WRITE_EXT) {
 
173
        if (repr) {
 
174
            // is this sane?
 
175
            //repr->mergeFrom(SP_OBJECT_REPR(object), "id");
 
176
        } else {
 
177
            repr = SP_OBJECT_REPR(object)->duplicate(NULL); // FIXME
 
178
        }
 
179
    }
 
180
 
 
181
    if (((SPObjectClass *) feFlood_parent_class)->write) {
 
182
        ((SPObjectClass *) feFlood_parent_class)->write(object, repr, flags);
 
183
    }
 
184
 
 
185
    return repr;
 
186
}
 
187
 
 
188
static void sp_feFlood_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter) {
 
189
    g_assert(primitive != NULL);
 
190
    g_assert(filter != NULL);
 
191
 
 
192
    SPFeFlood *sp_flood = SP_FEFLOOD(primitive);
 
193
    (void)sp_flood;
 
194
 
 
195
    int primitive_n = filter->add_primitive(NR::NR_FILTER_FLOOD);
 
196
    NR::FilterPrimitive *nr_primitive = filter->get_primitive(primitive_n);
 
197
    NR::FilterFlood *nr_flood = dynamic_cast<NR::FilterFlood*>(nr_primitive);
 
198
    g_assert(nr_flood != NULL);
 
199
 
 
200
    sp_filter_primitive_renderer_common(primitive, nr_primitive);
 
201
    
 
202
    nr_flood->set_opacity(sp_flood->opacity);
 
203
    nr_flood->set_color(sp_flood->color);
 
204
}
 
205
 
 
206
 
 
207
/*
 
208
  Local Variables:
 
209
  mode:c++
 
210
  c-file-style:"stroustrup"
 
211
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
212
  indent-tabs-mode:nil
 
213
  fill-column:99
 
214
  End:
 
215
*/
 
216
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :