If you think the Android project droidengine2d listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/* Copyright 2013-2014 Miguel Vicente Linares
*//www.java2s.com
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package com.miviclin.droidengine2d.graphics.material;
import com.miviclin.droidengine2d.graphics.texture.TextureRegion;
/**
* This material has texture and HSV color.<br>
* The hue of the texture can be changed. Saturation and brightness can be reduced. And opacity can also be adjusted.
*
* @author Miguel Vicente Linares
*
*/publicclass TextureHsvMaterial extends TransparentTextureMaterial {
privatefloat hOffset;
privatefloat sMulti;
privatefloat vMulti;
/**
* Creates a TextureHsvMaterial.
*
* @param textureRegion TextureRegion.
*/public TextureHsvMaterial(TextureRegion textureRegion) {
this(textureRegion, 1.0f, 0.0f, 1.0f, 1.0f);
}
/**
* Creates a TextureHsvMaterial.
*
* @param textureRegion TextureRegion.
* @param hOffset Hue offset (value between 0.0f and 360.0f).
* @param sMulti Saturation multiplier (value between 0.0f and 1.0f).
* @param vMulti Brightness multiplier (value between 0.0f and 1.0f).
*/public TextureHsvMaterial(TextureRegion textureRegion, float hOffset, float sMulti, float vMulti) {
this(textureRegion, 1.0f, hOffset, sMulti, vMulti);
}
/**
* Creates a TextureHsvMaterial.
*
* @param textureRegion TextureRegion.
* @param opacity (value between 0.0f and 1.0f).
* @param hOffset Hue offset (value between 0.0f and 360.0f).
* @param sMulti Saturation multiplier (value between 0.0f and 1.0f).
* @param vMulti Brightness multiplier (value between 0.0f and 1.0f).
*/public TextureHsvMaterial(TextureRegion textureRegion, float opacity, float hOffset, float sMulti, float vMulti) {
super(textureRegion, opacity);
checkH(hOffset);
checkS(sMulti);
checkV(vMulti);
this.hOffset = hOffset;
this.sMulti = sMulti;
this.vMulti = vMulti;
}
/**
* Returns the hue offset.
*
* @return value between 0.0f and 360.0f
*/publicfloat getHOffset() {
return hOffset;
}
/**
* Sets the hue offset.
*
* @param hOffset Value between 0.0f and 360.0f.
*/publicvoid setHOffset(float hOffset) {
checkH(hOffset);
this.hOffset = hOffset;
}
/**
* Returns the saturation multiplier.
*
* @return value between 0.0f and 1.0f
*/publicfloat getSMulti() {
return sMulti;
}
/**
* Sets the saturation multiplier.
*
* @param sMulti Value between 0.0f and 1.0f.
*/publicvoid setSMulti(float sMulti) {
checkS(sMulti);
this.sMulti = sMulti;
}
/**
* Returns the brightness multiplier.
*
* @return value between 0.0f and 1.0f
*/publicfloat getVMulti() {
return vMulti;
}
/**
* Sets the brightness multiplier.
*
* @param vMulti Value between 0.0f and 1.0f.
*/publicvoid setVMulti(float vMulti) {
checkV(vMulti);
this.vMulti = vMulti;
}
/**
* Checks that hOffset is a value between 0.0f and 360.0f and throws an exception in case it isn't.
*
* @param hOffset
*/privatevoid checkH(float hOffset) {
if (hOffset < 0 || hOffset > 360) {
thrownew IllegalArgumentException("The H component must be a value between 0.0 and 360.0");
}
}
/**
* Checks that sMulti is a value between 0.0f and 1.0f and throws an exception in case it isn't.
*
* @param sMulti
*/privatevoid checkS(float sMulti) {
if (sMulti < 0 || sMulti > 1) {
thrownew IllegalArgumentException("The S component must be a value between 0.0 and 1.0");
}
}
/**
* Checks that vMulti is a value between 0.0f and 1.0f and throws an exception in case it isn't.
*
* @param vMulti
*/privatevoid checkV(float vMulti) {
if (vMulti < 0 || vMulti > 1) {
thrownew IllegalArgumentException("The V component must be a value between 0.0 and 1.0");
}
}
}