1 50 51 package org.openlaszlo.iv.flash.api.shape; 52 53 import org.openlaszlo.iv.flash.util.*; 54 import org.openlaszlo.iv.flash.api.*; 55 import org.openlaszlo.iv.flash.parser.Parser; 56 import java.io.PrintStream ; 57 58 73 public final class Gradient extends FlashItem { 74 75 private int nGrads; 76 private int[] ratios = new int[8]; 77 private Color[] colors = new Color[8]; 78 79 82 public Gradient() { 83 nGrads = 0; 84 } 85 86 92 public Gradient( int ratio, Color color ) { 93 nGrads = 0; 94 addTransition( ratio, color ); 95 } 96 97 public Color[] getColors() { 98 return colors; 99 } 100 101 public int[] getRatios() { 102 return ratios; 103 } 104 105 public int getNumber() { 106 return nGrads; 107 } 108 109 115 public void addTransition( int ratio, Color color ) { 116 ratios[nGrads] = ratio; 117 colors[nGrads] = color; 118 nGrads++; 119 } 120 121 public static Gradient parse( Parser p, boolean withAlpha ) { 122 Gradient g = new Gradient(); 123 int nGrads = p.getUByte(); 124 for( int i=0; i<nGrads; i++ ) { 125 int ratio = p.getUByte(); 126 Color color = Color.parse(p, withAlpha); 127 g.addTransition(ratio, color); 128 } 129 return g; 130 } 131 132 public void write( FlashOutput fob ) { 133 fob.writeByte(nGrads); 134 if( fob.getUserData() instanceof Shape ) { 135 if( ((Shape)fob.getUserData()).isWithAlpha() ) { 136 for( int i=0; i<nGrads; i++ ) { 137 fob.writeByte( ratios[i] ); 138 colors[i].writeRGBA(fob); 139 } 140 } else { 141 for( int i=0; i<nGrads; i++ ) { 142 fob.writeByte( ratios[i] ); 143 colors[i].writeRGB(fob); 144 } 145 } 146 } else { 147 for( int i=0; i<nGrads; i++ ) { 148 fob.writeByte( ratios[i] ); 149 colors[i].write(fob); 150 } 151 } 152 } 153 154 public void printContent( PrintStream out, String indent ) { 155 out.println( indent+"Gradient: num="+nGrads ); 156 for( int i=0; i<nGrads; i++ ) { 157 out.println( indent+" ratio["+i+"]="+ratios[i] ); 158 out.print( indent+" color["+i+"]=" ); colors[i].printContent(out, ""); 159 } 160 } 161 162 protected FlashItem copyInto( FlashItem item, ScriptCopier copier ) { 163 ((Gradient)item).nGrads = nGrads; 164 int[] r = new int[8]; 165 System.arraycopy(ratios, 0, r, 0, 8); 166 Color[] c = new Color[8]; 167 for( int i=0; i<nGrads; i++ ) { 168 c[i] = (Color) colors[i].getCopy(copier); 169 } 170 ((Gradient)item).ratios = r; 171 ((Gradient)item).colors = c; 172 return item; 173 } 174 175 public FlashItem getCopy( ScriptCopier copier ) { 176 return copyInto( new Gradient(), copier ); 177 } 178 } 179 | Popular Tags |