⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 malleablecolor.java

📁 NetWar是一个实时策略游戏
💻 JAVA
字号:
/*
	Netwar
	Copyright (C) 2002  Daniel Grund, Kyle Kakligian, Jason Komutrattananon, & Brian Hibler.

	This file is part of Netwar.

	Netwar is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	Netwar is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Netwar; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package netwar.utils.vectorgraphics;
import java.awt.*;
import java.awt.color.*;
import java.awt.image.ColorModel;
import java.awt.geom.*;
import netwar.utils.Assert;


/** This is a Color which can be changed through a predifined one-dimensional spectrum.
 * Check out the 'cloacking' Beam Sniper to see what it can do ;)
 * Basically, when you construct it you specify the RGBA values for two colors,
 * and the number of colors you want. The other colors are calculated such
 * that the change in red is nearly constant between two consecutive colors
 * and the same is true for green, blue and alpha.
 * Use setCurrent(int) to pick a color from 1 to N (default is 1).
 * In this way you can change the color even after you've passed it off to
 * something else (like a GraphicThing for example).
 * @author Daniel Grund
 */
public class MalleableColor extends Color {
	ColorSpectrum colors;
	int current;
	/** Creates a new instance of MalleableColor 
	 * @param redOne the red level of color 1
	 * @param redN the red level of color N
	 * @param greenOne the green level of color 1
	 * @param greenN the green level of color N
	 * @param blueOne the blue level of color 1
	 * @param blueN the blue level of color N
	 * @param alphaOne the alpha level of color 1
	 * @param alphaN the alpha level of color N
	 * @param N the number of colors in this spectrum
	 */
	public MalleableColor(ColorSpectrum cs) {
		super(cs.getColor(0).getRGB());
		current = 0;
		colors = cs;
	}
	/** Set the current color to use from the spectrum.
	 * @param cur An integer from 1 to N indicating which color is now in use.
	 */
	public void setCurrent(int cur) {
		Assert.notFalse(cur > 0, "Tried to set the current color on a MalleableColor to a value less than 1.");
		Assert.notFalse(cur <= colors.getLength(), "Tried to set the current color on a MalleableColor to a value greater than N.");
		
		current = cur - 1; 
	}
	/** Get the current color in use.
	 * @return An integer from 1 to N indicating which color is now in use.
	 */
	public int getCurrent() {
		return current + 1;
	}
	
	public int getAlpha() {
		return colors.getColor(current).getAlpha();
	}
	public int getBlue() {
		return colors.getColor(current).getBlue();
	}
	public int getGreen() {
		return colors.getColor(current).getGreen();
	}
	public int getRed() {
		return colors.getColor(current).getRed();
	}
	public int getRGB() {
		return colors.getColor(current).getRGB();
	}
	public int hashCode() {
		return colors.getColor(current).hashCode();
	}
	public boolean equals(Object o) {
		return colors.getColor(current).equals(o);
	}
	public float[] getRGBComponents(float[] compArray) {
		return colors.getColor(current).getRGBComponents(compArray);
	}
	public float[] getRGBColorComponents(float[] compArray) {
		return colors.getColor(current).getRGBColorComponents(compArray);
	}
	public float[] getComponents(float[] compArray) {
		return colors.getColor(current).getComponents(compArray);
	}
	public float[] getColorComponents(float[] compArray) {
		return colors.getColor(current).getColorComponents(compArray);
	}
	public float[] getComponents(ColorSpace cspace, float[] compArray) {
		return colors.getColor(current).getComponents(cspace, compArray);
	}
	public float[] getColorComponents(ColorSpace cspace, float[] compArray) {
		return colors.getColor(current).getColorComponents(cspace, compArray);
	}
	public ColorSpace getColorSpace() {
		return colors.getColor(current).getColorSpace();
	}
	public PaintContext createContext(	ColorModel cm,
						Rectangle r,
						Rectangle2D r2d,
						AffineTransform xform,
						RenderingHints hints) {
		return colors.getColor(current).createContext(cm, r, r2d, xform, hints);
	}
	public int getTransparency() {
		return colors.getColor(current).getTransparency();
	}
		


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -