~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

« back to all changes in this revision

Viewing changes to src/filters/distantlight.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Ted Gould, Kees Cook
  • Date: 2009-06-24 14:00:43 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090624140043-07stp20mry48hqup
Tags: 0.47~pre0-0ubuntu1
* New upstream release

[ Ted Gould ]
* debian/control: Adding libgsl0 and removing version specifics on boost

[ Kees Cook ]
* debian/watch: updated to run uupdate and mangle pre-release versions.
* Dropped patches that have been taken upstream:
  - 01_mips
  - 02-poppler-0.8.3
  - 03-chinese-inkscape
  - 05_fix_latex_patch
  - 06_gcc-4.4
  - 07_cdr2svg
  - 08_skip-bad-utf-on-pdf-import
  - 09_gtk-clist
  - 10_belarussian
  - 11_libpng
  - 12_desktop
  - 13_slider
  - 100_svg_import_improvements
  - 102_sp_pattern_painter_free
  - 103_bitmap_type_print

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#define __SP_FEDISTANTLIGHT_CPP__
 
2
 
 
3
/** \file
 
4
 * SVG <fedistantlight> implementation.
 
5
 */
 
6
/*
 
7
 * Authors:
 
8
 *   Hugo Rodrigues <haa.rodrigues@gmail.com>
 
9
 *   Niko Kiirala <niko@kiirala.com>
 
10
 *   Jean-Rene Reinhard <jr@komite.net>
 
11
 *
 
12
 * Copyright (C) 2006,2007 Authors
 
13
 *
 
14
 * Released under GNU GPL, read the file 'COPYING' for more information
 
15
 */
 
16
 
 
17
#ifdef HAVE_CONFIG_H
 
18
# include "config.h"
 
19
#endif
 
20
 
 
21
#include <glib.h>
 
22
 
 
23
#include "attributes.h"
 
24
#include "document.h"
 
25
#include "distantlight.h"
 
26
#include "diffuselighting-fns.h"
 
27
#include "specularlighting-fns.h"
 
28
#include "xml/repr.h"
 
29
 
 
30
#define SP_MACROS_SILENT
 
31
#include "macros.h"
 
32
 
 
33
/* FeDistantLight class */
 
34
 
 
35
static void sp_fedistantlight_class_init(SPFeDistantLightClass *klass);
 
36
static void sp_fedistantlight_init(SPFeDistantLight *fedistantlight);
 
37
 
 
38
static void sp_fedistantlight_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
 
39
static void sp_fedistantlight_release(SPObject *object);
 
40
static void sp_fedistantlight_set(SPObject *object, unsigned int key, gchar const *value);
 
41
static void sp_fedistantlight_update(SPObject *object, SPCtx *ctx, guint flags);
 
42
static Inkscape::XML::Node *sp_fedistantlight_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
 
43
 
 
44
static SPObjectClass *feDistantLight_parent_class;
 
45
 
 
46
GType
 
47
sp_fedistantlight_get_type()
 
48
{
 
49
    static GType fedistantlight_type = 0;
 
50
 
 
51
    if (!fedistantlight_type) {
 
52
        GTypeInfo fedistantlight_info = {
 
53
            sizeof(SPFeDistantLightClass),
 
54
            NULL, NULL,
 
55
            (GClassInitFunc) sp_fedistantlight_class_init,
 
56
            NULL, NULL,
 
57
            sizeof(SPFeDistantLight),
 
58
            16,
 
59
            (GInstanceInitFunc) sp_fedistantlight_init,
 
60
            NULL,    /* value_table */
 
61
        };
 
62
        fedistantlight_type = g_type_register_static(SP_TYPE_OBJECT, "SPFeDistantLight", &fedistantlight_info, (GTypeFlags)0);
 
63
    }
 
64
    return fedistantlight_type;
 
65
}
 
66
 
 
67
static void
 
68
sp_fedistantlight_class_init(SPFeDistantLightClass *klass)
 
69
{
 
70
 
 
71
    SPObjectClass *sp_object_class = (SPObjectClass *)klass;
 
72
 
 
73
    feDistantLight_parent_class = (SPObjectClass*)g_type_class_peek_parent(klass);
 
74
 
 
75
    sp_object_class->build = sp_fedistantlight_build;
 
76
    sp_object_class->release = sp_fedistantlight_release;
 
77
    sp_object_class->write = sp_fedistantlight_write;
 
78
    sp_object_class->set = sp_fedistantlight_set;
 
79
    sp_object_class->update = sp_fedistantlight_update;
 
80
}
 
81
 
 
82
static void
 
83
sp_fedistantlight_init(SPFeDistantLight *fedistantlight)
 
84
{
 
85
    fedistantlight->azimuth = 0;
 
86
    fedistantlight->elevation = 0;
 
87
    fedistantlight->azimuth_set = FALSE;
 
88
    fedistantlight->elevation_set = FALSE;
 
89
}
 
90
 
 
91
/**
 
92
 * Reads the Inkscape::XML::Node, and initializes SPDistantLight variables.  For this to get called,
 
93
 * our name must be associated with a repr via "sp_object_type_register".  Best done through
 
94
 * sp-object-repr.cpp's repr_name_entries array.
 
95
 */
 
96
static void
 
97
sp_fedistantlight_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
 
98
{
 
99
    if (((SPObjectClass *) feDistantLight_parent_class)->build) {
 
100
        ((SPObjectClass *) feDistantLight_parent_class)->build(object, document, repr);
 
101
    }
 
102
 
 
103
    //Read values of key attributes from XML nodes into object.
 
104
    sp_object_read_attr(object, "azimuth");
 
105
    sp_object_read_attr(object, "elevation");
 
106
 
 
107
//is this necessary?
 
108
    sp_document_add_resource(document, "fedistantlight", object);
 
109
}
 
110
 
 
111
/**
 
112
 * Drops any allocated memory.
 
113
 */
 
114
static void
 
115
sp_fedistantlight_release(SPObject *object)
 
116
{
 
117
    //SPFeDistantLight *fedistantlight = SP_FEDISTANTLIGHT(object);
 
118
 
 
119
    if (SP_OBJECT_DOCUMENT(object)) {
 
120
        /* Unregister ourselves */
 
121
        sp_document_remove_resource(SP_OBJECT_DOCUMENT(object), "fedistantlight", SP_OBJECT(object));
 
122
    }
 
123
 
 
124
//TODO: release resources here
 
125
}
 
126
 
 
127
/**
 
128
 * Sets a specific value in the SPFeDistantLight.
 
129
 */
 
130
static void
 
131
sp_fedistantlight_set(SPObject *object, unsigned int key, gchar const *value)
 
132
{
 
133
    SPFeDistantLight *fedistantlight = SP_FEDISTANTLIGHT(object);
 
134
    gchar *end_ptr;
 
135
    switch (key) {
 
136
    case SP_ATTR_AZIMUTH:
 
137
        end_ptr =NULL;
 
138
        if (value) {
 
139
            fedistantlight->azimuth = g_ascii_strtod(value, &end_ptr);
 
140
            if (end_ptr) {
 
141
                fedistantlight->azimuth_set = TRUE;
 
142
            }
 
143
        }
 
144
        if (!value || !end_ptr) {
 
145
                fedistantlight->azimuth_set = FALSE;
 
146
                fedistantlight->azimuth = 0;
 
147
        }
 
148
        if (object->parent &&
 
149
                (SP_IS_FEDIFFUSELIGHTING(object->parent) ||
 
150
                 SP_IS_FESPECULARLIGHTING(object->parent))) {
 
151
            object->parent->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
 
152
        }
 
153
        break;
 
154
    case SP_ATTR_ELEVATION:
 
155
        end_ptr =NULL;
 
156
        if (value) {
 
157
            fedistantlight->elevation = g_ascii_strtod(value, &end_ptr);
 
158
            if (end_ptr) {
 
159
                fedistantlight->elevation_set = TRUE;
 
160
            }
 
161
        }
 
162
        if (!value || !end_ptr) {
 
163
                fedistantlight->elevation_set = FALSE;
 
164
                fedistantlight->elevation = 0;
 
165
        }
 
166
        if (object->parent &&
 
167
                (SP_IS_FEDIFFUSELIGHTING(object->parent) ||
 
168
                 SP_IS_FESPECULARLIGHTING(object->parent))) {
 
169
            object->parent->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
 
170
        }
 
171
        break;
 
172
    default:
 
173
        // See if any parents need this value.
 
174
        if (((SPObjectClass *) feDistantLight_parent_class)->set) {
 
175
            ((SPObjectClass *) feDistantLight_parent_class)->set(object, key, value);
 
176
        }
 
177
        break;
 
178
    }
 
179
}
 
180
 
 
181
/**
 
182
 *  * Receives update notifications.
 
183
 *   */
 
184
static void
 
185
sp_fedistantlight_update(SPObject *object, SPCtx *ctx, guint flags)
 
186
{
 
187
    SPFeDistantLight *feDistantLight = SP_FEDISTANTLIGHT(object);
 
188
    (void)feDistantLight;
 
189
 
 
190
    if (flags & SP_OBJECT_MODIFIED_FLAG) {
 
191
        /* do something to trigger redisplay, updates? */
 
192
        sp_object_read_attr(object, "azimuth");
 
193
        sp_object_read_attr(object, "elevation");
 
194
    }
 
195
 
 
196
    if (((SPObjectClass *) feDistantLight_parent_class)->update) {
 
197
        ((SPObjectClass *) feDistantLight_parent_class)->update(object, ctx, flags);
 
198
    }
 
199
}
 
200
 
 
201
/**
 
202
 * Writes its settings to an incoming repr object, if any.
 
203
 */
 
204
static Inkscape::XML::Node *
 
205
sp_fedistantlight_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags)
 
206
{
 
207
    SPFeDistantLight *fedistantlight = SP_FEDISTANTLIGHT(object);
 
208
 
 
209
    if (!repr) {
 
210
        repr = SP_OBJECT_REPR(object)->duplicate(doc);
 
211
    }
 
212
 
 
213
    if (fedistantlight->azimuth_set)
 
214
        sp_repr_set_css_double(repr, "azimuth", fedistantlight->azimuth);
 
215
    if (fedistantlight->elevation_set)
 
216
        sp_repr_set_css_double(repr, "elevation", fedistantlight->elevation);
 
217
 
 
218
    if (((SPObjectClass *) feDistantLight_parent_class)->write) {
 
219
        ((SPObjectClass *) feDistantLight_parent_class)->write(object, doc, repr, flags);
 
220
    }
 
221
 
 
222
    return repr;
 
223
}
 
224
 
 
225
/*
 
226
  Local Variables:
 
227
  mode:c++
 
228
  c-file-style:"stroustrup"
 
229
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
230
  indent-tabs-mode:nil
 
231
  fill-column:99
 
232
  End:
 
233
*/
 
234
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :