~danieljabailey/inkscape/arc_node_editor

« back to all changes in this revision

Viewing changes to src/sp-linear-gradient.cpp

  • Committer: scislac
  • Date: 2009-08-12 07:57:52 UTC
  • Revision ID: scislac@users.sourceforge.net-20090812075752-3zt99jgeqr3bm16j
much better quality multi-size windows icon, thanks ChrisMorgan

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <cairo.h>
2
 
 
3
 
#include "sp-linear-gradient.h"
4
 
 
5
 
#include "attributes.h"
6
 
#include "xml/repr.h"
7
 
 
8
 
/*
9
 
 * Linear Gradient
10
 
 */
11
 
SPLinearGradient::SPLinearGradient() : SPGradient() {
12
 
    this->x1.unset(SVGLength::PERCENT, 0.0, 0.0);
13
 
    this->y1.unset(SVGLength::PERCENT, 0.0, 0.0);
14
 
    this->x2.unset(SVGLength::PERCENT, 1.0, 1.0);
15
 
    this->y2.unset(SVGLength::PERCENT, 0.0, 0.0);
16
 
}
17
 
 
18
 
SPLinearGradient::~SPLinearGradient() {
19
 
}
20
 
 
21
 
void SPLinearGradient::build(SPDocument *document, Inkscape::XML::Node *repr) {
22
 
    SPGradient::build(document, repr);
23
 
 
24
 
    this->readAttr( "x1" );
25
 
    this->readAttr( "y1" );
26
 
    this->readAttr( "x2" );
27
 
    this->readAttr( "y2" );
28
 
}
29
 
 
30
 
/**
31
 
 * Callback: set attribute.
32
 
 */
33
 
void SPLinearGradient::set(unsigned int key, const gchar* value) {
34
 
    switch (key) {
35
 
        case SP_ATTR_X1:
36
 
            this->x1.readOrUnset(value, SVGLength::PERCENT, 0.0, 0.0);
37
 
            this->requestModified(SP_OBJECT_MODIFIED_FLAG);
38
 
            break;
39
 
 
40
 
        case SP_ATTR_Y1:
41
 
            this->y1.readOrUnset(value, SVGLength::PERCENT, 0.0, 0.0);
42
 
            this->requestModified(SP_OBJECT_MODIFIED_FLAG);
43
 
            break;
44
 
 
45
 
        case SP_ATTR_X2:
46
 
            this->x2.readOrUnset(value, SVGLength::PERCENT, 1.0, 1.0);
47
 
            this->requestModified(SP_OBJECT_MODIFIED_FLAG);
48
 
            break;
49
 
 
50
 
        case SP_ATTR_Y2:
51
 
            this->y2.readOrUnset(value, SVGLength::PERCENT, 0.0, 0.0);
52
 
            this->requestModified(SP_OBJECT_MODIFIED_FLAG);
53
 
            break;
54
 
 
55
 
        default:
56
 
            SPGradient::set(key, value);
57
 
            break;
58
 
    }
59
 
}
60
 
 
61
 
/**
62
 
 * Callback: write attributes to associated repr.
63
 
 */
64
 
Inkscape::XML::Node* SPLinearGradient::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) {
65
 
    if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
66
 
        repr = xml_doc->createElement("svg:linearGradient");
67
 
    }
68
 
 
69
 
    if ((flags & SP_OBJECT_WRITE_ALL) || this->x1._set) {
70
 
        sp_repr_set_svg_double(repr, "x1", this->x1.computed);
71
 
    }
72
 
 
73
 
    if ((flags & SP_OBJECT_WRITE_ALL) || this->y1._set) {
74
 
        sp_repr_set_svg_double(repr, "y1", this->y1.computed);
75
 
    }
76
 
 
77
 
    if ((flags & SP_OBJECT_WRITE_ALL) || this->x2._set) {
78
 
        sp_repr_set_svg_double(repr, "x2", this->x2.computed);
79
 
    }
80
 
 
81
 
    if ((flags & SP_OBJECT_WRITE_ALL) || this->y2._set) {
82
 
        sp_repr_set_svg_double(repr, "y2", this->y2.computed);
83
 
    }
84
 
 
85
 
    SPGradient::write(xml_doc, repr, flags);
86
 
 
87
 
    return repr;
88
 
}
89
 
 
90
 
cairo_pattern_t* SPLinearGradient::pattern_new(cairo_t * /*ct*/, Geom::OptRect const &bbox, double opacity) {
91
 
    this->ensureVector();
92
 
 
93
 
    cairo_pattern_t *cp = cairo_pattern_create_linear(
94
 
        this->x1.computed, this->y1.computed,
95
 
        this->x2.computed, this->y2.computed);
96
 
 
97
 
    sp_gradient_pattern_common_setup(cp, this, bbox, opacity);
98
 
 
99
 
    return cp;
100
 
}