// Copyright 2000-2005 the Contributors, as shown in the revision logs. // Licensed under the GNU General Public License version 2 ("the License"). // You may not use this file except in compliance with the License. // FIXME package org.ibex.graphics; import java.util.*; public abstract class Paint { //public abstract void fillTrapezoid(float tx1, float tx2, float ty1, float tx3, float tx4, float ty2, PixelBuffer buf); public static class SingleColorPaint extends Paint { public int color; public SingleColorPaint(int color) { this.color = color; } /* public void fillTrapezoid(float x1, float x2, float y1, float x3, float x4, float y2, PixelBuffer buf) { buf.fillTrapezoid((int)Math.round(x1), (int)Math.round(x2), (int)Math.round(y1), (int)Math.round(x3), (int)Math.round(x4), (int)Math.round(y2), color); } */ } public static class TexturePaint extends Paint { Affine a, invert; Picture p; public TexturePaint(Picture p, Affine a) { this.p = p; this.a = a.copy(); this.invert = a.copy().invert(); } //public void fillTrapezoid(float tx1, float tx2, float ty1, float tx3, float tx4, float ty2, PixelBuffer buf) { /* float x1 = invert.multiply_px(tx1, ty1); float x2 = invert.multiply_px(tx2, ty1); float x3 = invert.multiply_px(tx3, ty2); float x4 = invert.multiply_px(tx4, ty2); float y1 = invert.multiply_py(tx1, ty1); float y2 = invert.multiply_py(tx3, ty2); */ //buf.paintTrapezoid((int)tx1, (int)tx2, (int)ty1, (int)tx3, (int)tx4, (int)ty2, p, a); //} } public static abstract class GradientPaint extends Paint { public GradientPaint(boolean reflect, boolean repeat, Affine gradientTransform, int[] stop_colors, float[] stop_offsets) { this.reflect = reflect; this.repeat = repeat; this.gradientTransform = gradientTransform; this.stop_colors = stop_colors; this.stop_offsets = stop_offsets; } Affine gradientTransform = Affine.identity(); boolean useBoundingBox = false; // FIXME not supported boolean patternUseBoundingBox = false; // FIXME not supported // it's invalid for both of these to be true boolean reflect = false; // FIXME not supported boolean repeat = false; // FIXME not supported int[] stop_colors; float[] stop_offsets; float cx, cy, r, fx, fy; //public void fillTrapezoid(float tx1, float tx2, float ty1, float tx3, float tx4, float ty2, PixelBuffer buf) { /* Affine a = buf.a; Affine inverse = a.copy().invert(); float slope1 = (tx3 - tx1) / (ty2 - ty1); float slope2 = (tx4 - tx2) / (ty2 - ty1); for(float y=ty1; y _x2) { float _x0 = _x1; _x1 = _x2; _x2 = _x0; } for(float x=_x1; x<_x2; x++) { float distance = isLinear ? // length of projection of onto the gradient vector == { \dot {grad \over |grad|}} (x * (x2 - x1) + y * (y2 - y1)) / (float)Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) : // radial form is simple! FIXME, not quite right (float)Math.sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy)); // FIXME: offsets are 0..1, not 0..length(gradient) int i = 0; for(; i= stop_offsets.length) continue; // gradate from offsets[i - 1] to offsets[i] float percentage = ((distance - stop_offsets[i - 1]) / (stop_offsets[i] - stop_offsets[i - 1])); int a = (int)((((stop_colors[i] >> 24) & 0xff) - ((stop_colors[i - 1] >> 24) & 0xff)) * percentage) + ((stop_colors[i - 1] >> 24) & 0xff); int r = (int)((((stop_colors[i] >> 16) & 0xff) - ((stop_colors[i - 1] >> 16) & 0xff)) * percentage) + ((stop_colors[i - 1] >> 16) & 0xff); int g = (int)((((stop_colors[i] >> 8) & 0xff) - ((stop_colors[i - 1] >> 8) & 0xff)) * percentage) + ((stop_colors[i - 1] >> 8) & 0xff); int b = (int)((((stop_colors[i] >> 0) & 0xff) - ((stop_colors[i - 1] >> 0) & 0xff)) * percentage) + ((stop_colors[i - 1] >> 0) & 0xff); int argb = (a << 24) | (r << 16) | (g << 8) | b; buf.drawPoint((int)x, (int)Math.floor(y), argb); } } */ //} } /* public static class LinearGradientPaint extends GradientPaint { public LinearGradientPaint(float x1, float y1, float x2, float y2, boolean reflect, boolean repeat, Affine gradientTransform, int[] stop_colors, float[] stop_offsets) { super(reflect, repeat, gradientTransform, stop_colors, stop_offsets); this.x1 = x1; this.x2 = x2; this.y1 = y1; this.y2 = y2; } float x1 = 0, y1 = 0, x2 = 300, y2 = 300; } public static class RadialGradientPaint extends GradientPaint { public RadialGradientPaint(float cx, float cy, float fx, float fy, float r, boolean reflect, boolean repeat, Affine gradientTransform, int[] stop_colors, float[] stop_offsets) { super(reflect, repeat, gradientTransform, stop_colors, stop_offsets); this.cx = cx; this.cy = cy; this.fx = fx; this.fy = fy; this.r = r; } } */ }