X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fsp-fespotlight.cpp;h=b66912468ce8d5efa5606f7f6adc5cffa39d4e6a;hb=8d358698ecbf192ba7c6dc05d4f7de7592753d9f;hp=d5ae5306cd3a6b927f6779952e7f4adde607166b;hpb=af0732a2bf24fbea12a085b855224577e7101851;p=inkscape.git diff --git a/src/sp-fespotlight.cpp b/src/sp-fespotlight.cpp index d5ae5306c..b66912468 100644 --- a/src/sp-fespotlight.cpp +++ b/src/sp-fespotlight.cpp @@ -39,7 +39,7 @@ static void sp_fespotlight_build(SPObject *object, SPDocument *document, Inkscap static void sp_fespotlight_release(SPObject *object); static void sp_fespotlight_set(SPObject *object, unsigned int key, gchar const *value); static void sp_fespotlight_update(SPObject *object, SPCtx *ctx, guint flags); -static Inkscape::XML::Node *sp_fespotlight_write(SPObject *object, Inkscape::XML::Node *repr, guint flags); +static Inkscape::XML::Node *sp_fespotlight_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); static SPObjectClass *feSpotLight_parent_class; @@ -90,6 +90,15 @@ sp_fespotlight_init(SPFeSpotLight *fespotlight) fespotlight->pointsAtZ = 0; fespotlight->specularExponent = 1; fespotlight->limitingConeAngle = 90; + + fespotlight->x_set = FALSE; + fespotlight->y_set = FALSE; + fespotlight->z_set = FALSE; + fespotlight->pointsAtX_set = FALSE; + fespotlight->pointsAtY_set = FALSE; + fespotlight->pointsAtZ_set = FALSE; + fespotlight->specularExponent_set = FALSE; + fespotlight->limitingConeAngle_set = FALSE; } /** @@ -141,10 +150,20 @@ static void sp_fespotlight_set(SPObject *object, unsigned int key, gchar const *value) { SPFeSpotLight *fespotlight = SP_FESPOTLIGHT(object); + gchar *end_ptr; switch (key) { case SP_ATTR_X: - fespotlight->x = g_ascii_strtod(value, NULL); + end_ptr = NULL; + if (value) { + fespotlight->x = g_ascii_strtod(value, &end_ptr); + if (end_ptr) + fespotlight->x_set = TRUE; + } + if(!value || !end_ptr) { + fespotlight->x = 0; + fespotlight->x_set = FALSE; + } if (object->parent && (SP_IS_FEDIFFUSELIGHTING(object->parent) || SP_IS_FESPECULARLIGHTING(object->parent))) { @@ -152,7 +171,16 @@ sp_fespotlight_set(SPObject *object, unsigned int key, gchar const *value) } break; case SP_ATTR_Y: - fespotlight->y = g_ascii_strtod(value, NULL); + end_ptr = NULL; + if (value) { + fespotlight->y = g_ascii_strtod(value, &end_ptr); + if (end_ptr) + fespotlight->y_set = TRUE; + } + if(!value || !end_ptr) { + fespotlight->y = 0; + fespotlight->y_set = FALSE; + } if (object->parent && (SP_IS_FEDIFFUSELIGHTING(object->parent) || SP_IS_FESPECULARLIGHTING(object->parent))) { @@ -160,7 +188,16 @@ sp_fespotlight_set(SPObject *object, unsigned int key, gchar const *value) } break; case SP_ATTR_Z: - fespotlight->z = g_ascii_strtod(value, NULL); + end_ptr = NULL; + if (value) { + fespotlight->z = g_ascii_strtod(value, &end_ptr); + if (end_ptr) + fespotlight->z_set = TRUE; + } + if(!value || !end_ptr) { + fespotlight->z = 0; + fespotlight->z_set = FALSE; + } if (object->parent && (SP_IS_FEDIFFUSELIGHTING(object->parent) || SP_IS_FESPECULARLIGHTING(object->parent))) { @@ -168,7 +205,16 @@ sp_fespotlight_set(SPObject *object, unsigned int key, gchar const *value) } break; case SP_ATTR_POINTSATX: - fespotlight->pointsAtX = g_ascii_strtod(value, NULL); + end_ptr = NULL; + if (value) { + fespotlight->pointsAtX = g_ascii_strtod(value, &end_ptr); + if (end_ptr) + fespotlight->pointsAtX_set = TRUE; + } + if(!value || !end_ptr) { + fespotlight->pointsAtX = 0; + fespotlight->pointsAtX_set = FALSE; + } if (object->parent && (SP_IS_FEDIFFUSELIGHTING(object->parent) || SP_IS_FESPECULARLIGHTING(object->parent))) { @@ -176,7 +222,16 @@ sp_fespotlight_set(SPObject *object, unsigned int key, gchar const *value) } break; case SP_ATTR_POINTSATY: - fespotlight->pointsAtY = g_ascii_strtod(value, NULL); + end_ptr = NULL; + if (value) { + fespotlight->pointsAtY = g_ascii_strtod(value, &end_ptr); + if (end_ptr) + fespotlight->pointsAtY_set = TRUE; + } + if(!value || !end_ptr) { + fespotlight->pointsAtY = 0; + fespotlight->pointsAtY_set = FALSE; + } if (object->parent && (SP_IS_FEDIFFUSELIGHTING(object->parent) || SP_IS_FESPECULARLIGHTING(object->parent))) { @@ -184,7 +239,16 @@ sp_fespotlight_set(SPObject *object, unsigned int key, gchar const *value) } break; case SP_ATTR_POINTSATZ: - fespotlight->pointsAtZ = g_ascii_strtod(value, NULL); + end_ptr = NULL; + if (value) { + fespotlight->pointsAtZ = g_ascii_strtod(value, &end_ptr); + if (end_ptr) + fespotlight->pointsAtZ_set = TRUE; + } + if(!value || !end_ptr) { + fespotlight->pointsAtZ = 0; + fespotlight->pointsAtZ_set = FALSE; + } if (object->parent && (SP_IS_FEDIFFUSELIGHTING(object->parent) || SP_IS_FESPECULARLIGHTING(object->parent))) { @@ -192,7 +256,16 @@ sp_fespotlight_set(SPObject *object, unsigned int key, gchar const *value) } break; case SP_ATTR_SPECULAREXPONENT: - fespotlight->specularExponent = g_ascii_strtod(value, NULL); + end_ptr = NULL; + if (value) { + fespotlight->specularExponent = g_ascii_strtod(value, &end_ptr); + if (end_ptr) + fespotlight->specularExponent_set = TRUE; + } + if(!value || !end_ptr) { + fespotlight->specularExponent = 1; + fespotlight->specularExponent_set = FALSE; + } if (object->parent && (SP_IS_FEDIFFUSELIGHTING(object->parent) || SP_IS_FESPECULARLIGHTING(object->parent))) { @@ -200,7 +273,16 @@ sp_fespotlight_set(SPObject *object, unsigned int key, gchar const *value) } break; case SP_ATTR_LIMITINGCONEANGLE: - fespotlight->limitingConeAngle = g_ascii_strtod(value, NULL); + end_ptr = NULL; + if (value) { + fespotlight->limitingConeAngle = g_ascii_strtod(value, &end_ptr); + if (end_ptr) + fespotlight->limitingConeAngle_set = TRUE; + } + if(!value || !end_ptr) { + fespotlight->limitingConeAngle = 90; + fespotlight->limitingConeAngle_set = FALSE; + } if (object->parent && (SP_IS_FEDIFFUSELIGHTING(object->parent) || SP_IS_FESPECULARLIGHTING(object->parent))) { @@ -208,7 +290,7 @@ sp_fespotlight_set(SPObject *object, unsigned int key, gchar const *value) } break; default: - // See if any parents need this value. + // See if any parents need this value. if (((SPObjectClass *) feSpotLight_parent_class)->set) { ((SPObjectClass *) feSpotLight_parent_class)->set(object, key, value); } @@ -223,6 +305,7 @@ static void sp_fespotlight_update(SPObject *object, SPCtx *ctx, guint flags) { SPFeSpotLight *feSpotLight = SP_FESPOTLIGHT(object); + (void)feSpotLight; if (flags & SP_OBJECT_MODIFIED_FLAG) { /* do something to trigger redisplay, updates? */ @@ -235,7 +318,7 @@ sp_fespotlight_update(SPObject *object, SPCtx *ctx, guint flags) sp_object_read_attr(object, "specularExponent"); sp_object_read_attr(object, "limitingConeAngle"); } - + if (((SPObjectClass *) feSpotLight_parent_class)->update) { ((SPObjectClass *) feSpotLight_parent_class)->update(object, ctx, flags); } @@ -245,25 +328,33 @@ sp_fespotlight_update(SPObject *object, SPCtx *ctx, guint flags) * Writes its settings to an incoming repr object, if any. */ static Inkscape::XML::Node * -sp_fespotlight_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) +sp_fespotlight_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags) { SPFeSpotLight *fespotlight = SP_FESPOTLIGHT(object); if (!repr) { - repr = SP_OBJECT_REPR(object)->duplicate(NULL); // FIXME + repr = SP_OBJECT_REPR(object)->duplicate(doc); } - sp_repr_set_css_double(repr, "x", fespotlight->x); - sp_repr_set_css_double(repr, "y", fespotlight->y); - sp_repr_set_css_double(repr, "z", fespotlight->z); - sp_repr_set_css_double(repr, "pointsAtX", fespotlight->pointsAtX); - sp_repr_set_css_double(repr, "pointsAtY", fespotlight->pointsAtY); - sp_repr_set_css_double(repr, "pointsAtZ", fespotlight->pointsAtZ); - sp_repr_set_css_double(repr, "specularExponent", fespotlight->specularExponent); - sp_repr_set_css_double(repr, "limitingConeAngle", fespotlight->limitingConeAngle); - + if (fespotlight->x_set) + sp_repr_set_css_double(repr, "x", fespotlight->x); + if (fespotlight->y_set) + sp_repr_set_css_double(repr, "y", fespotlight->y); + if (fespotlight->z_set) + sp_repr_set_css_double(repr, "z", fespotlight->z); + if (fespotlight->pointsAtX_set) + sp_repr_set_css_double(repr, "pointsAtX", fespotlight->pointsAtX); + if (fespotlight->pointsAtY_set) + sp_repr_set_css_double(repr, "pointsAtY", fespotlight->pointsAtY); + if (fespotlight->pointsAtZ_set) + sp_repr_set_css_double(repr, "pointsAtZ", fespotlight->pointsAtZ); + if (fespotlight->specularExponent_set) + sp_repr_set_css_double(repr, "specularExponent", fespotlight->specularExponent); + if (fespotlight->limitingConeAngle_set) + sp_repr_set_css_double(repr, "limitingConeAngle", fespotlight->limitingConeAngle); + if (((SPObjectClass *) feSpotLight_parent_class)->write) { - ((SPObjectClass *) feSpotLight_parent_class)->write(object, repr, flags); + ((SPObjectClass *) feSpotLight_parent_class)->write(object, doc, repr, flags); } return repr;