001/*
002 * SVG Salamander
003 * Copyright (c) 2004, Mark McKay
004 * All rights reserved.
005 *
006 * Redistribution and use in source and binary forms, with or 
007 * without modification, are permitted provided that the following
008 * conditions are met:
009 *
010 *   - Redistributions of source code must retain the above 
011 *     copyright notice, this list of conditions and the following
012 *     disclaimer.
013 *   - Redistributions in binary form must reproduce the above
014 *     copyright notice, this list of conditions and the following
015 *     disclaimer in the documentation and/or other materials 
016 *     provided with the distribution.
017 *
018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
019 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
020 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
021 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
022 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
023 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
025 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
026 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
027 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
028 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
029 * OF THE POSSIBILITY OF SUCH DAMAGE. 
030 * 
031 * Mark McKay can be contacted at mark@kitfox.com.  Salamander and other
032 * projects can be found at http://www.kitfox.com
033 *
034 * Created on March 18, 2004, 6:52 AM
035 */
036package com.kitfox.svg;
037
038import com.kitfox.svg.xml.StyleAttribute;
039
040/**
041 * @author Mark McKay
042 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
043 */
044public class FeSpotLight extends FeLight
045{
046
047    public static final String TAG_NAME = "fespotlight";
048    float x = 0f;
049    float y = 0f;
050    float z = 0f;
051    float pointsAtX = 0f;
052    float pointsAtY = 0f;
053    float pointsAtZ = 0f;
054    float specularComponent = 0f;
055    float limitingConeAngle = 0f;
056
057    /**
058     * Creates a new instance of FillElement
059     */
060    public FeSpotLight()
061    {
062    }
063
064    @Override
065    public String getTagName()
066    {
067        return TAG_NAME;
068    }
069
070    @Override
071    protected void build() throws SVGException
072    {
073        super.build();
074
075        StyleAttribute sty = new StyleAttribute();
076
077        if (getPres(sty.setName("x")))
078        {
079            x = sty.getFloatValueWithUnits();
080        }
081        if (getPres(sty.setName("y")))
082        {
083            y = sty.getFloatValueWithUnits();
084        }
085        if (getPres(sty.setName("z")))
086        {
087            z = sty.getFloatValueWithUnits();
088        }
089        if (getPres(sty.setName("pointsAtX")))
090        {
091            pointsAtX = sty.getFloatValueWithUnits();
092        }
093        if (getPres(sty.setName("pointsAtY")))
094        {
095            pointsAtY = sty.getFloatValueWithUnits();
096        }
097        if (getPres(sty.setName("pointsAtZ")))
098        {
099            pointsAtZ = sty.getFloatValueWithUnits();
100        }
101        if (getPres(sty.setName("specularComponent")))
102        {
103            specularComponent = sty.getFloatValueWithUnits();
104        }
105        if (getPres(sty.setName("limitingConeAngle")))
106        {
107            limitingConeAngle = sty.getFloatValueWithUnits();
108        }
109    }
110
111    @Override
112    public float getX()
113    {
114        return x;
115    }
116
117    @Override
118    public float getY()
119    {
120        return y;
121    }
122
123    public float getZ()
124    {
125        return z;
126    }
127
128    public float getPointsAtX()
129    {
130        return pointsAtX;
131    }
132
133    public float getPointsAtY()
134    {
135        return pointsAtY;
136    }
137
138    public float getPointsAtZ()
139    {
140        return pointsAtZ;
141    }
142
143    public float getSpecularComponent()
144    {
145        return specularComponent;
146    }
147
148    public float getLimitingConeAngle()
149    {
150        return limitingConeAngle;
151    }
152
153    @Override
154    public boolean updateTime(double curTime) throws SVGException
155    {
156//        if (trackManager.getNumTracks() == 0) return false;
157
158        //Get current values for parameters
159        StyleAttribute sty = new StyleAttribute();
160        boolean stateChange = false;
161
162        if (getPres(sty.setName("x")))
163        {
164            float newVal = sty.getFloatValueWithUnits();
165            if (newVal != x)
166            {
167                x = newVal;
168                stateChange = true;
169            }
170        }
171
172        if (getPres(sty.setName("y")))
173        {
174            float newVal = sty.getFloatValueWithUnits();
175            if (newVal != y)
176            {
177                y = newVal;
178                stateChange = true;
179            }
180        }
181
182        if (getPres(sty.setName("z")))
183        {
184            float newVal = sty.getFloatValueWithUnits();
185            if (newVal != z)
186            {
187                z = newVal;
188                stateChange = true;
189            }
190        }
191
192        if (getPres(sty.setName("pointsAtX")))
193        {
194            float newVal = sty.getFloatValueWithUnits();
195            if (newVal != pointsAtX)
196            {
197                pointsAtX = newVal;
198                stateChange = true;
199            }
200        }
201
202        if (getPres(sty.setName("pointsAtY")))
203        {
204            float newVal = sty.getFloatValueWithUnits();
205            if (newVal != pointsAtY)
206            {
207                pointsAtY = newVal;
208                stateChange = true;
209            }
210        }
211
212        if (getPres(sty.setName("pointsAtZ")))
213        {
214            float newVal = sty.getFloatValueWithUnits();
215            if (newVal != pointsAtZ)
216            {
217                pointsAtZ = newVal;
218                stateChange = true;
219            }
220        }
221
222        if (getPres(sty.setName("specularComponent")))
223        {
224            float newVal = sty.getFloatValueWithUnits();
225            if (newVal != specularComponent)
226            {
227                specularComponent = newVal;
228                stateChange = true;
229            }
230        }
231
232        if (getPres(sty.setName("limitingConeAngle")))
233        {
234            float newVal = sty.getFloatValueWithUnits();
235            if (newVal != limitingConeAngle)
236            {
237                limitingConeAngle = newVal;
238                stateChange = true;
239            }
240        }
241
242        return stateChange;
243    }
244}