source: josm/trunk/src/com/kitfox/svg/RadialGradient.java@ 9514

Last change on this file since 9514 was 8084, checked in by bastiK, 9 years ago

add svn:eol-style=native for svgsalamander

  • Property svn:eol-style set to native
File size: 6.3 KB
Line 
1/*
2 * SVG Salamander
3 * Copyright (c) 2004, Mark McKay
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
8 * conditions are met:
9 *
10 * - Redistributions of source code must retain the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer.
13 * - Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials
16 * provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29 * OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
32 * projects can be found at http://www.kitfox.com
33 *
34 * Created on January 26, 2004, 1:55 AM
35 */
36package com.kitfox.svg;
37
38import com.kitfox.svg.xml.StyleAttribute;
39import java.awt.Color;
40import java.awt.Paint;
41import java.awt.geom.AffineTransform;
42import java.awt.geom.Point2D;
43import java.awt.geom.Rectangle2D;
44
45/**
46 * @author Mark McKay
47 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
48 */
49public class RadialGradient extends Gradient
50{
51 public static final String TAG_NAME = "radialgradient";
52
53 float cx = 0.5f;
54 float cy = 0.5f;
55 float fx = 0.5f;
56 float fy = 0.5f;
57 float r = 0.5f;
58
59 /**
60 * Creates a new instance of RadialGradient
61 */
62 public RadialGradient()
63 {
64 }
65
66 public String getTagName()
67 {
68 return TAG_NAME;
69 }
70
71 protected void build() throws SVGException
72 {
73 super.build();
74
75 StyleAttribute sty = new StyleAttribute();
76
77 if (getPres(sty.setName("cx")))
78 {
79 cx = sty.getFloatValueWithUnits();
80 }
81
82 if (getPres(sty.setName("cy")))
83 {
84 cy = sty.getFloatValueWithUnits();
85 }
86
87 if (getPres(sty.setName("fx")))
88 {
89 fx = sty.getFloatValueWithUnits();
90 }
91
92 if (getPres(sty.setName("fy")))
93 {
94 fy = sty.getFloatValueWithUnits();
95 }
96
97 if (getPres(sty.setName("r")))
98 {
99 r = sty.getFloatValueWithUnits();
100 }
101 }
102
103 public Paint getPaint(Rectangle2D bounds, AffineTransform xform)
104 {
105 com.kitfox.svg.batik.MultipleGradientPaint.CycleMethodEnum method;
106 switch (spreadMethod)
107 {
108 default:
109 case SM_PAD:
110 method = com.kitfox.svg.batik.MultipleGradientPaint.NO_CYCLE;
111 break;
112 case SM_REPEAT:
113 method = com.kitfox.svg.batik.MultipleGradientPaint.REPEAT;
114 break;
115 case SM_REFLECT:
116 method = com.kitfox.svg.batik.MultipleGradientPaint.REFLECT;
117 break;
118 }
119
120 Paint paint;
121 Point2D.Float pt1 = new Point2D.Float(cx, cy);
122 Point2D.Float pt2 = new Point2D.Float(fx, fy);
123 if (gradientUnits == GU_USER_SPACE_ON_USE)
124 {
125 paint = new com.kitfox.svg.batik.RadialGradientPaint(
126 pt1,
127 r,
128 pt2,
129 getStopFractions(),
130 getStopColors(),
131 method,
132 com.kitfox.svg.batik.MultipleGradientPaint.SRGB,
133 gradientTransform);
134 } else
135 {
136 AffineTransform viewXform = new AffineTransform();
137 viewXform.translate(bounds.getX(), bounds.getY());
138 viewXform.scale(bounds.getWidth(), bounds.getHeight());
139
140 viewXform.concatenate(gradientTransform);
141
142 paint = new com.kitfox.svg.batik.RadialGradientPaint(
143 pt1,
144 r,
145 pt2,
146 getStopFractions(),
147 getStopColors(),
148 method,
149 com.kitfox.svg.batik.MultipleGradientPaint.SRGB,
150 viewXform);
151 }
152
153 return paint;
154 }
155
156 /**
157 * Updates all attributes in this diagram associated with a time event. Ie,
158 * all attributes with track information.
159 *
160 * @return - true if this node has changed state as a result of the time
161 * update
162 */
163 public boolean updateTime(double curTime) throws SVGException
164 {
165// if (trackManager.getNumTracks() == 0) return false;
166 boolean changeState = super.updateTime(curTime);
167
168 //Get current values for parameters
169 StyleAttribute sty = new StyleAttribute();
170 boolean shapeChange = false;
171
172 if (getPres(sty.setName("cx")))
173 {
174 float newVal = sty.getFloatValueWithUnits();
175 if (newVal != cx)
176 {
177 cx = newVal;
178 shapeChange = true;
179 }
180 }
181
182 if (getPres(sty.setName("cy")))
183 {
184 float newVal = sty.getFloatValueWithUnits();
185 if (newVal != cy)
186 {
187 cy = newVal;
188 shapeChange = true;
189 }
190 }
191
192 if (getPres(sty.setName("fx")))
193 {
194 float newVal = sty.getFloatValueWithUnits();
195 if (newVal != fx)
196 {
197 fx = newVal;
198 shapeChange = true;
199 }
200 }
201
202 if (getPres(sty.setName("fy")))
203 {
204 float newVal = sty.getFloatValueWithUnits();
205 if (newVal != fy)
206 {
207 fy = newVal;
208 shapeChange = true;
209 }
210 }
211
212 if (getPres(sty.setName("r")))
213 {
214 float newVal = sty.getFloatValueWithUnits();
215 if (newVal != r)
216 {
217 r = newVal;
218 shapeChange = true;
219 }
220 }
221
222 return changeState;
223 }
224}
Note: See TracBrowser for help on using the repository browser.