| •1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
package com.github.weisj.jsvg.nodes.animation; |
| 23 |
|
| 24 |
import java.awt.*; |
| 25 |
|
| 26 |
import org.jetbrains.annotations.NotNull; |
| 27 |
import org.jetbrains.annotations.Nullable; |
| 28 |
|
| 29 |
import com.github.weisj.jsvg.animation.value.*; |
| 30 |
import com.github.weisj.jsvg.attributes.value.*; |
| 31 |
import com.github.weisj.jsvg.geometry.size.Length; |
| 32 |
import com.github.weisj.jsvg.geometry.size.Percentage; |
| 33 |
import com.github.weisj.jsvg.nodes.prototype.spec.Category; |
| 34 |
import com.github.weisj.jsvg.nodes.prototype.spec.ElementCategories; |
| 35 |
import com.github.weisj.jsvg.nodes.prototype.spec.PermittedContent; |
| 36 |
import com.github.weisj.jsvg.paint.SVGPaint; |
| 37 |
import com.github.weisj.jsvg.paint.impl.PredefinedPaints; |
| 38 |
import com.github.weisj.jsvg.paint.impl.RGBColor; |
| 39 |
import com.github.weisj.jsvg.parser.PaintParser; |
| 40 |
import com.github.weisj.jsvg.parser.impl.AttributeNode; |
| 41 |
|
| 42 |
@ElementCategories(Category.Animation) |
| 43 |
@PermittedContent(categories = {Category.Descriptive}) |
| 44 |
public final class Animate extends BaseAnimationNode { |
| 45 |
public static final String TAG = "animate"; |
| 46 |
|
| 47 |
@Override |
| 48 |
public @NotNull String tagName() { |
| 49 |
return TAG; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
public @Nullable AnimatedLength animatedLength( |
| 54 |
@NotNull LengthValue initial, |
| 55 |
PercentageDimension dimension, |
| 56 |
@NotNull AttributeNode attributeNode) { |
| 57 |
if (track == null) return null; |
| 58 |
|
| 59 |
Length[] lengths = new Length[values.length]; |
| 60 |
for (int i = 0; i < values.length; i++) { |
| 61 |
if (isPlaceholder(values[i])) { |
| 62 |
lengths[i] = Length.ZERO; |
| 63 |
} else { |
| 64 |
lengths[i] = attributeNode.parser().parseLength(values[i], null, dimension); |
| 65 |
} |
| 66 |
if (lengths[i] == null) return null; |
| 67 |
} |
| 68 |
return new AnimatedLength(track, initial, lengths); |
| 69 |
} |
| 70 |
|
| 71 |
public @Nullable AnimatedFloatList animatedFloatList(@NotNull FloatListValue initial, |
| 72 |
@NotNull AttributeNode attributeNode) { |
| 73 |
if (track == null) return null; |
| 74 |
|
| 75 |
float[][] lists = new float[values.length][]; |
| 76 |
for (int i = 0; i < values.length; i++) { |
| 77 |
if (isPlaceholder(values[i])) { |
| 78 |
lists[i] = new float[0]; |
| 79 |
} else { |
| 80 |
lists[i] = attributeNode.parser().parseFloatList(values[i]); |
| 81 |
} |
| 82 |
} |
| 83 |
return new AnimatedFloatList(track, initial, lists); |
| 84 |
} |
| 85 |
|
| 86 |
public @Nullable AnimatedPercentage animatedPercentage(@NotNull PercentageValue initial, |
| 87 |
@NotNull AttributeNode attributeNode) { |
| 88 |
if (track == null) return null; |
| 89 |
float[] percentages = new float[this.values.length]; |
| 90 |
for (int i = 0; i < this.values.length; i++) { |
| 91 |
if (isPlaceholder(values[i])) { |
| 92 |
percentages[i] = Percentage.ZERO.value(); |
| 93 |
} else { |
| 94 |
Percentage p = attributeNode.parser().parsePercentage(this.values[i], null); |
| 95 |
if (p == null) return null; |
| 96 |
percentages[i] = p.value(); |
| 97 |
} |
| 98 |
} |
| 99 |
return new AnimatedPercentage(track, initial, percentages, Percentage.ONE); |
| 100 |
} |
| 101 |
|
| 102 |
public @Nullable AnimatedPaint animatedPaint(@NotNull SVGPaint initial, @NotNull AttributeNode attributeNode) { |
| 103 |
if (track == null) return null; |
| 104 |
SVGPaint[] paints = new SVGPaint[this.values.length]; |
| 105 |
for (int i = 0; i < this.values.length; i++) { |
| 106 |
if (isPlaceholder(values[i])) { |
| 107 |
paints[i] = PredefinedPaints.NONE; |
| 108 |
} else { |
| 109 |
SVGPaint p = attributeNode.parsePaint(this.values[i]); |
| 110 |
if (p == null) return null; |
| 111 |
paints[i] = p; |
| 112 |
} |
| 113 |
} |
| 114 |
return new AnimatedPaint(track, initial, paints); |
| 115 |
} |
| 116 |
|
| 117 |
public @Nullable AnimatedColor animatedColor(@NotNull ColorValue initial, @NotNull AttributeNode attributeNode) { |
| 118 |
if (track == null) return null; |
| 119 |
RGBColor[] paints = new RGBColor[this.values.length]; |
| 120 |
for (int i = 0; i < this.values.length; i++) { |
| 121 |
if (isPlaceholder(values[i])) { |
| 122 |
paints[i] = new RGBColor(PaintParser.DEFAULT_COLOR); |
| 123 |
} else { |
| 124 |
Color c = attributeNode.parser().paintParser().parseColor(this.values[i]); |
| 125 |
if (c == null) return null; |
| 126 |
paints[i] = new RGBColor(c); |
| 127 |
} |
| 128 |
} |
| 129 |
return new AnimatedColor(track, initial, paints); |
| 130 |
} |
| 131 |
} |