Code

Pot and Dutch translation update
[inkscape.git] / src / filters / pointlight.cpp
1 #define __SP_FEPOINTLIGHT_CPP__
3 /** \file
4  * SVG <fepointlight> 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  */
17 #ifdef HAVE_CONFIG_H
18 # include "config.h"
19 #endif
21 #include <glib.h>
23 #include "attributes.h"
24 #include "document.h"
25 #include "pointlight.h"
26 #include "diffuselighting-fns.h"
27 #include "specularlighting-fns.h"
28 #include "xml/repr.h"
30 #define SP_MACROS_SILENT
31 #include "macros.h"
33 /* FePointLight class */
35 static void sp_fepointlight_class_init(SPFePointLightClass *klass);
36 static void sp_fepointlight_init(SPFePointLight *fepointlight);
38 static void sp_fepointlight_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
39 static void sp_fepointlight_release(SPObject *object);
40 static void sp_fepointlight_set(SPObject *object, unsigned int key, gchar const *value);
41 static void sp_fepointlight_update(SPObject *object, SPCtx *ctx, guint flags);
42 static Inkscape::XML::Node *sp_fepointlight_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
44 static SPObjectClass *fePointLight_parent_class;
46 GType
47 sp_fepointlight_get_type()
48 {
49     static GType fepointlight_type = 0;
51     if (!fepointlight_type) {
52         GTypeInfo fepointlight_info = {
53             sizeof(SPFePointLightClass),
54             NULL, NULL,
55             (GClassInitFunc) sp_fepointlight_class_init,
56             NULL, NULL,
57             sizeof(SPFePointLight),
58             16,
59             (GInstanceInitFunc) sp_fepointlight_init,
60             NULL,    /* value_table */
61         };
62         fepointlight_type = g_type_register_static(SP_TYPE_OBJECT, "SPFePointLight", &fepointlight_info, (GTypeFlags)0);
63     }
64     return fepointlight_type;
65 }
67 static void
68 sp_fepointlight_class_init(SPFePointLightClass *klass)
69 {
71     SPObjectClass *sp_object_class = (SPObjectClass *)klass;
73     fePointLight_parent_class = (SPObjectClass*)g_type_class_peek_parent(klass);
75     sp_object_class->build = sp_fepointlight_build;
76     sp_object_class->release = sp_fepointlight_release;
77     sp_object_class->write = sp_fepointlight_write;
78     sp_object_class->set = sp_fepointlight_set;
79     sp_object_class->update = sp_fepointlight_update;
80 }
82 static void
83 sp_fepointlight_init(SPFePointLight *fepointlight)
84 {
85     fepointlight->x = 0;
86     fepointlight->y = 0;
87     fepointlight->z = 0;
89     fepointlight->x_set = FALSE;
90     fepointlight->y_set = FALSE;
91     fepointlight->z_set = FALSE;
92 }
94 /**
95  * Reads the Inkscape::XML::Node, and initializes SPPointLight variables.  For this to get called,
96  * our name must be associated with a repr via "sp_object_type_register".  Best done through
97  * sp-object-repr.cpp's repr_name_entries array.
98  */
99 static void
100 sp_fepointlight_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
102     if (((SPObjectClass *) fePointLight_parent_class)->build) {
103         ((SPObjectClass *) fePointLight_parent_class)->build(object, document, repr);
104     }
106     //Read values of key attributes from XML nodes into object.
107     sp_object_read_attr(object, "x");
108     sp_object_read_attr(object, "y");
109     sp_object_read_attr(object, "z");
111 //is this necessary?
112     sp_document_add_resource(document, "fepointlight", object);
115 /**
116  * Drops any allocated memory.
117  */
118 static void
119 sp_fepointlight_release(SPObject *object)
121     //SPFePointLight *fepointlight = SP_FEPOINTLIGHT(object);
123     if (SP_OBJECT_DOCUMENT(object)) {
124         /* Unregister ourselves */
125         sp_document_remove_resource(SP_OBJECT_DOCUMENT(object), "fepointlight", SP_OBJECT(object));
126     }
128 //TODO: release resources here
131 /**
132  * Sets a specific value in the SPFePointLight.
133  */
134 static void
135 sp_fepointlight_set(SPObject *object, unsigned int key, gchar const *value)
137     SPFePointLight *fepointlight = SP_FEPOINTLIGHT(object);
138     gchar *end_ptr;
139     switch (key) {
140     case SP_ATTR_X:
141         end_ptr = NULL;
142         if (value) {
143             fepointlight->x = g_ascii_strtod(value, &end_ptr);
144             if (end_ptr) {
145                 fepointlight->x_set = TRUE;
146             }
147         }
148         if (!value || !end_ptr) {
149             fepointlight->x = 0;
150             fepointlight->x_set = FALSE;
151         }
152         if (object->parent &&
153                 (SP_IS_FEDIFFUSELIGHTING(object->parent) ||
154                  SP_IS_FESPECULARLIGHTING(object->parent))) {
155             object->parent->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
156         }
157         break;
158     case SP_ATTR_Y:
159         end_ptr = NULL;
160         if (value) {
161             fepointlight->y = g_ascii_strtod(value, &end_ptr);
162             if (end_ptr) {
163                 fepointlight->y_set = TRUE;
164             }
165         }
166         if (!value || !end_ptr) {
167             fepointlight->y = 0;
168             fepointlight->y_set = FALSE;
169         }
170         if (object->parent &&
171                 (SP_IS_FEDIFFUSELIGHTING(object->parent) ||
172                  SP_IS_FESPECULARLIGHTING(object->parent))) {
173             object->parent->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
174         }
175         break;
176     case SP_ATTR_Z:
177         end_ptr = NULL;
178         if (value) {
179             fepointlight->z = g_ascii_strtod(value, &end_ptr);
180             if (end_ptr) {
181                 fepointlight->z_set = TRUE;
182             }
183         }
184         if (!value || !end_ptr) {
185             fepointlight->z = 0;
186             fepointlight->z_set = FALSE;
187         }
188         if (object->parent &&
189                 (SP_IS_FEDIFFUSELIGHTING(object->parent) ||
190                  SP_IS_FESPECULARLIGHTING(object->parent))) {
191             object->parent->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
192         }
193         break;
194     default:
195         // See if any parents need this value.
196         if (((SPObjectClass *) fePointLight_parent_class)->set) {
197             ((SPObjectClass *) fePointLight_parent_class)->set(object, key, value);
198         }
199         break;
200     }
203 /**
204  *  * Receives update notifications.
205  *   */
206 static void
207 sp_fepointlight_update(SPObject *object, SPCtx *ctx, guint flags)
209     SPFePointLight *fePointLight = SP_FEPOINTLIGHT(object);
210     (void)fePointLight;
212     if (flags & SP_OBJECT_MODIFIED_FLAG) {
213         /* do something to trigger redisplay, updates? */
214         sp_object_read_attr(object, "x");
215         sp_object_read_attr(object, "y");
216         sp_object_read_attr(object, "z");
217     }
219     if (((SPObjectClass *) fePointLight_parent_class)->update) {
220         ((SPObjectClass *) fePointLight_parent_class)->update(object, ctx, flags);
221     }
224 /**
225  * Writes its settings to an incoming repr object, if any.
226  */
227 static Inkscape::XML::Node *
228 sp_fepointlight_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags)
230     SPFePointLight *fepointlight = SP_FEPOINTLIGHT(object);
232     if (!repr) {
233         repr = SP_OBJECT_REPR(object)->duplicate(doc);
234     }
236     if (fepointlight->x_set)
237         sp_repr_set_css_double(repr, "x", fepointlight->x);
238     if (fepointlight->y_set)
239         sp_repr_set_css_double(repr, "y", fepointlight->y);
240     if (fepointlight->z_set)
241         sp_repr_set_css_double(repr, "z", fepointlight->z);
243     if (((SPObjectClass *) fePointLight_parent_class)->write) {
244         ((SPObjectClass *) fePointLight_parent_class)->write(object, doc, repr, flags);
245     }
247     return repr;
250 /*
251   Local Variables:
252   mode:c++
253   c-file-style:"stroustrup"
254   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
255   indent-tabs-mode:nil
256   fill-column:99
257   End:
258 */
259 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :