Logo Search packages:      
Sourcecode: inkscape version File versions

int objects_query_opacity ( GSList *  objects,
SPStyle style_res 
)

Write to style_res the average opacity of a list of objects.

Definition at line 591 of file desktop-style.cpp.

References SPStyle::opacity, and SPIScale24::value.

Referenced by sp_desktop_query_style_from_list().

{
    if (g_slist_length(objects) == 0) {
        /* No objects, set empty */
        return QUERY_STYLE_NOTHING;
    }

    gdouble opacity_sum = 0;
    gdouble opacity_prev = -1;
    bool same_opacity = true;
    guint opacity_items = 0;


    for (GSList const *i = objects; i != NULL; i = i->next) {
        SPObject *obj = SP_OBJECT (i->data);
        SPStyle *style = SP_OBJECT_STYLE (obj);
        if (!style) continue;

        double opacity = SP_SCALE24_TO_FLOAT(style->opacity.value);
        opacity_sum += opacity;
        if (opacity_prev != -1 && opacity != opacity_prev)
            same_opacity = false;
        opacity_prev = opacity;
        opacity_items ++;
    }
    if (opacity_items > 1)
        opacity_sum /= opacity_items;

    style_res->opacity.value = SP_SCALE24_FROM_FLOAT(opacity_sum);

    if (opacity_items == 0) {
        return QUERY_STYLE_NOTHING;
    } else if (opacity_items == 1) {
        return QUERY_STYLE_SINGLE;
    } else {
        if (same_opacity)
            return QUERY_STYLE_MULTIPLE_SAME;
        else
            return QUERY_STYLE_MULTIPLE_AVERAGED;
    }
}


Generated by  Doxygen 1.6.0   Back to index