2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
23 #include "core/svg/SVGFETurbulenceElement.h"
25 #include "core/SVGNames.h"
26 #include "core/svg/SVGParserUtilities.h"
30 template<> const SVGEnumerationStringEntries
& getStaticStringEntries
<SVGStitchOptions
>()
32 DEFINE_STATIC_LOCAL(SVGEnumerationStringEntries
, entries
, ());
33 if (entries
.isEmpty()) {
34 entries
.append(std::make_pair(SVG_STITCHTYPE_STITCH
, "stitch"));
35 entries
.append(std::make_pair(SVG_STITCHTYPE_NOSTITCH
, "noStitch"));
40 template<> const SVGEnumerationStringEntries
& getStaticStringEntries
<TurbulenceType
>()
42 DEFINE_STATIC_LOCAL(SVGEnumerationStringEntries
, entries
, ());
43 if (entries
.isEmpty()) {
44 entries
.append(std::make_pair(FETURBULENCE_TYPE_FRACTALNOISE
, "fractalNoise"));
45 entries
.append(std::make_pair(FETURBULENCE_TYPE_TURBULENCE
, "turbulence"));
50 inline SVGFETurbulenceElement::SVGFETurbulenceElement(Document
& document
)
51 : SVGFilterPrimitiveStandardAttributes(SVGNames::feTurbulenceTag
, document
)
52 , m_baseFrequency(SVGAnimatedNumberOptionalNumber::create(this, SVGNames::baseFrequencyAttr
))
53 , m_seed(SVGAnimatedNumber::create(this, SVGNames::seedAttr
, SVGNumber::create(0)))
54 , m_stitchTiles(SVGAnimatedEnumeration
<SVGStitchOptions
>::create(this, SVGNames::stitchTilesAttr
, SVG_STITCHTYPE_NOSTITCH
))
55 , m_type(SVGAnimatedEnumeration
<TurbulenceType
>::create(this, SVGNames::typeAttr
, FETURBULENCE_TYPE_TURBULENCE
))
56 , m_numOctaves(SVGAnimatedInteger::create(this, SVGNames::numOctavesAttr
, SVGInteger::create(1)))
58 addToPropertyMap(m_baseFrequency
);
59 addToPropertyMap(m_seed
);
60 addToPropertyMap(m_stitchTiles
);
61 addToPropertyMap(m_type
);
62 addToPropertyMap(m_numOctaves
);
65 DEFINE_TRACE(SVGFETurbulenceElement
)
67 visitor
->trace(m_baseFrequency
);
68 visitor
->trace(m_seed
);
69 visitor
->trace(m_stitchTiles
);
70 visitor
->trace(m_type
);
71 visitor
->trace(m_numOctaves
);
72 SVGFilterPrimitiveStandardAttributes::trace(visitor
);
75 DEFINE_NODE_FACTORY(SVGFETurbulenceElement
)
77 bool SVGFETurbulenceElement::setFilterEffectAttribute(FilterEffect
* effect
, const QualifiedName
& attrName
)
79 FETurbulence
* turbulence
= static_cast<FETurbulence
*>(effect
);
80 if (attrName
== SVGNames::typeAttr
)
81 return turbulence
->setType(m_type
->currentValue()->enumValue());
82 if (attrName
== SVGNames::stitchTilesAttr
)
83 return turbulence
->setStitchTiles(m_stitchTiles
->currentValue()->enumValue());
84 if (attrName
== SVGNames::baseFrequencyAttr
) {
85 bool baseFrequencyXChanged
= turbulence
->setBaseFrequencyX(baseFrequencyX()->currentValue()->value());
86 bool baseFrequencyYChanged
= turbulence
->setBaseFrequencyY(baseFrequencyY()->currentValue()->value());
87 return (baseFrequencyXChanged
|| baseFrequencyYChanged
);
89 if (attrName
== SVGNames::seedAttr
)
90 return turbulence
->setSeed(m_seed
->currentValue()->value());
91 if (attrName
== SVGNames::numOctavesAttr
)
92 return turbulence
->setNumOctaves(m_numOctaves
->currentValue()->value());
98 void SVGFETurbulenceElement::svgAttributeChanged(const QualifiedName
& attrName
)
100 if (attrName
== SVGNames::baseFrequencyAttr
101 || attrName
== SVGNames::numOctavesAttr
102 || attrName
== SVGNames::seedAttr
103 || attrName
== SVGNames::stitchTilesAttr
104 || attrName
== SVGNames::typeAttr
) {
105 SVGElement::InvalidationGuard
invalidationGuard(this);
106 primitiveAttributeChanged(attrName
);
110 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName
);
113 PassRefPtrWillBeRawPtr
<FilterEffect
> SVGFETurbulenceElement::build(SVGFilterBuilder
*, Filter
* filter
)
115 if (baseFrequencyX()->currentValue()->value() < 0 || baseFrequencyY()->currentValue()->value() < 0)
117 return FETurbulence::create(filter
, m_type
->currentValue()->enumValue(), baseFrequencyX()->currentValue()->value(), baseFrequencyY()->currentValue()->value(), m_numOctaves
->currentValue()->value(), m_seed
->currentValue()->value(), m_stitchTiles
->currentValue()->enumValue() == SVG_STITCHTYPE_STITCH
);