001: /*
002: * $Id: MorphGradient.java,v 1.1 2002/02/15 23:46:26 skavish Exp $
003: *
004: * ==========================================================================
005: *
006: * The JGenerator Software License, Version 1.0
007: *
008: * Copyright (c) 2000 Dmitry Skavish (skavish@usa.net). All rights reserved.
009: *
010: * Redistribution and use in source and binary forms, with or without
011: * modification, are permitted provided that the following conditions are met:
012: *
013: * 1. Redistributions of source code must retain the above copyright
014: * notice, this list of conditions and the following disclaimer.
015: *
016: * 2. Redistributions in binary form must reproduce the above copyright
017: * notice, this list of conditions and the following disclaimer in
018: * the documentation and/or other materials provided with the
019: * distribution.
020: *
021: * 3. The end-user documentation included with the redistribution, if
022: * any, must include the following acknowlegement:
023: * "This product includes software developed by Dmitry Skavish
024: * (skavish@usa.net, http://www.flashgap.com/)."
025: * Alternately, this acknowlegement may appear in the software itself,
026: * if and wherever such third-party acknowlegements normally appear.
027: *
028: * 4. The name "The JGenerator" must not be used to endorse or promote
029: * products derived from this software without prior written permission.
030: * For written permission, please contact skavish@usa.net.
031: *
032: * 5. Products derived from this software may not be called "The JGenerator"
033: * nor may "The JGenerator" appear in their names without prior written
034: * permission of Dmitry Skavish.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL DMITRY SKAVISH OR THE OTHER
040: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: *
049: */
050:
051: package org.openlaszlo.iv.flash.api.shape;
052:
053: import org.openlaszlo.iv.flash.util.*;
054: import org.openlaszlo.iv.flash.api.*;
055: import org.openlaszlo.iv.flash.parser.Parser;
056: import java.io.PrintStream;
057:
058: /**
059: * MorphGradient
060: *
061: * @author Dmitry Skavish
062: * @see Gradient
063: */
064: public final class MorphGradient extends FlashItem {
065:
066: private int nGrads;
067: private int[] ratios_start = new int[8];
068: private int[] ratios_end = new int[8];
069: private Color[] colors_start = new Color[8];
070: private Color[] colors_end = new Color[8];
071:
072: /**
073: * Creates empty gradient
074: */
075: public MorphGradient() {
076: }
077:
078: /**
079: * Creates gradient with one transition
080: *
081: * @param ratio_start start ratio
082: * @param color_start start color
083: * @param ratio_end end ratio
084: * @param color_end end color
085: */
086: public MorphGradient(int ratio_start, Color color_start,
087: int ratio_end, Color color_end) {
088: nGrads = 0;
089: addTransition(ratio_start, color_start, ratio_end, color_end);
090: }
091:
092: public Color[] getColorsStart() {
093: return colors_start;
094: }
095:
096: public int[] getRatiosStart() {
097: return ratios_start;
098: }
099:
100: public Color[] getColorsEnd() {
101: return colors_end;
102: }
103:
104: public int[] getRatiosEnd() {
105: return ratios_end;
106: }
107:
108: public int getNumber() {
109: return nGrads;
110: }
111:
112: /**
113: * Adds transition
114: *
115: * @param ratio_start start ratio
116: * @param color_start start color
117: * @param ratio_end end ratio
118: * @param color_end end color
119: */
120: public void addTransition(int ratio_start, Color color_start,
121: int ratio_end, Color color_end) {
122: ratios_start[nGrads] = ratio_start;
123: colors_start[nGrads] = color_start;
124: ratios_end[nGrads] = ratio_end;
125: colors_end[nGrads] = color_end;
126: nGrads++;
127: }
128:
129: public static MorphGradient parse(Parser p) {
130: MorphGradient g = new MorphGradient();
131: int nGrads = p.getUByte();
132: for (int i = 0; i < nGrads; i++) {
133: int ratio_start = p.getUByte();
134: AlphaColor color_start = AlphaColor.parse(p);
135: int ratio_end = p.getUByte();
136: AlphaColor color_end = AlphaColor.parse(p);
137: g.addTransition(ratio_start, color_start, ratio_end,
138: color_end);
139: }
140: return g;
141: }
142:
143: public void write(FlashOutput fob) {
144: fob.writeByte(nGrads);
145: for (int i = 0; i < nGrads; i++) {
146: fob.writeByte(ratios_start[i]);
147: colors_start[i].writeRGBA(fob);
148: fob.writeByte(ratios_end[i]);
149: colors_end[i].writeRGBA(fob);
150: }
151: }
152:
153: public void printContent(PrintStream out, String indent) {
154: out.println(indent + "MorphGradient: num=" + nGrads);
155: for (int i = 0; i < nGrads; i++) {
156: out.println(indent + " ratio_start[" + i + "]="
157: + ratios_start[i]);
158: out.print(indent + " color_start[" + i + "]=");
159: colors_start[i].printContent(out, "");
160: out.println(indent + " ratio_end[" + i + "]="
161: + ratios_end[i]);
162: out.print(indent + " color_end[" + i + "]=");
163: colors_end[i].printContent(out, "");
164: }
165: }
166:
167: protected FlashItem copyInto(FlashItem item, ScriptCopier copier) {
168: for (int i = 0; i < nGrads; i++) {
169: ((MorphGradient) item).addTransition(ratios_start[i],
170: colors_start[i], ratios_end[i], colors_end[i]);
171: }
172: return item;
173: }
174:
175: public FlashItem getCopy(ScriptCopier copier) {
176: return copyInto(new MorphGradient(), copier);
177: }
178: }
|