1
#define __SP_FEDISTANTLIGHT_CPP__
4
* SVG <fedistantlight> implementation.
8
* Hugo Rodrigues <haa.rodrigues@gmail.com>
9
* Niko Kiirala <niko@kiirala.com>
10
* Jean-Rene Reinhard <jr@komite.net>
12
* Copyright (C) 2006,2007 Authors
14
* Released under GNU GPL, read the file 'COPYING' for more information
23
#include "attributes.h"
25
#include "distantlight.h"
26
#include "diffuselighting-fns.h"
27
#include "specularlighting-fns.h"
30
#define SP_MACROS_SILENT
33
/* FeDistantLight class */
35
static void sp_fedistantlight_class_init(SPFeDistantLightClass *klass);
36
static void sp_fedistantlight_init(SPFeDistantLight *fedistantlight);
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);
44
static SPObjectClass *feDistantLight_parent_class;
47
sp_fedistantlight_get_type()
49
static GType fedistantlight_type = 0;
51
if (!fedistantlight_type) {
52
GTypeInfo fedistantlight_info = {
53
sizeof(SPFeDistantLightClass),
55
(GClassInitFunc) sp_fedistantlight_class_init,
57
sizeof(SPFeDistantLight),
59
(GInstanceInitFunc) sp_fedistantlight_init,
60
NULL, /* value_table */
62
fedistantlight_type = g_type_register_static(SP_TYPE_OBJECT, "SPFeDistantLight", &fedistantlight_info, (GTypeFlags)0);
64
return fedistantlight_type;
68
sp_fedistantlight_class_init(SPFeDistantLightClass *klass)
71
SPObjectClass *sp_object_class = (SPObjectClass *)klass;
73
feDistantLight_parent_class = (SPObjectClass*)g_type_class_peek_parent(klass);
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;
83
sp_fedistantlight_init(SPFeDistantLight *fedistantlight)
85
fedistantlight->azimuth = 0;
86
fedistantlight->elevation = 0;
87
fedistantlight->azimuth_set = FALSE;
88
fedistantlight->elevation_set = FALSE;
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.
97
sp_fedistantlight_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
99
if (((SPObjectClass *) feDistantLight_parent_class)->build) {
100
((SPObjectClass *) feDistantLight_parent_class)->build(object, document, repr);
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");
108
sp_document_add_resource(document, "fedistantlight", object);
112
* Drops any allocated memory.
115
sp_fedistantlight_release(SPObject *object)
117
//SPFeDistantLight *fedistantlight = SP_FEDISTANTLIGHT(object);
119
if (SP_OBJECT_DOCUMENT(object)) {
120
/* Unregister ourselves */
121
sp_document_remove_resource(SP_OBJECT_DOCUMENT(object), "fedistantlight", SP_OBJECT(object));
124
//TODO: release resources here
128
* Sets a specific value in the SPFeDistantLight.
131
sp_fedistantlight_set(SPObject *object, unsigned int key, gchar const *value)
133
SPFeDistantLight *fedistantlight = SP_FEDISTANTLIGHT(object);
136
case SP_ATTR_AZIMUTH:
139
fedistantlight->azimuth = g_ascii_strtod(value, &end_ptr);
141
fedistantlight->azimuth_set = TRUE;
144
if (!value || !end_ptr) {
145
fedistantlight->azimuth_set = FALSE;
146
fedistantlight->azimuth = 0;
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);
154
case SP_ATTR_ELEVATION:
157
fedistantlight->elevation = g_ascii_strtod(value, &end_ptr);
159
fedistantlight->elevation_set = TRUE;
162
if (!value || !end_ptr) {
163
fedistantlight->elevation_set = FALSE;
164
fedistantlight->elevation = 0;
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);
173
// See if any parents need this value.
174
if (((SPObjectClass *) feDistantLight_parent_class)->set) {
175
((SPObjectClass *) feDistantLight_parent_class)->set(object, key, value);
182
* * Receives update notifications.
185
sp_fedistantlight_update(SPObject *object, SPCtx *ctx, guint flags)
187
SPFeDistantLight *feDistantLight = SP_FEDISTANTLIGHT(object);
188
(void)feDistantLight;
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");
196
if (((SPObjectClass *) feDistantLight_parent_class)->update) {
197
((SPObjectClass *) feDistantLight_parent_class)->update(object, ctx, flags);
202
* Writes its settings to an incoming repr object, if any.
204
static Inkscape::XML::Node *
205
sp_fedistantlight_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags)
207
SPFeDistantLight *fedistantlight = SP_FEDISTANTLIGHT(object);
210
repr = SP_OBJECT_REPR(object)->duplicate(doc);
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);
218
if (((SPObjectClass *) feDistantLight_parent_class)->write) {
219
((SPObjectClass *) feDistantLight_parent_class)->write(object, doc, repr, flags);
228
c-file-style:"stroustrup"
229
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
234
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :