Last active
August 29, 2015 14:13
-
-
Save marchermans/566d07b3153b09af5428 to your computer and use it in GitHub Desktop.
Color to int
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.Orion.Armory.Util.Client; | |
/* | |
/ Color | |
/ Created by : Orion | |
/ Created on : 27/06/2014 | |
*/ | |
public class Color { | |
private int iColorRed = 255; | |
private int iColorGreen = 255; | |
private int iColorBlue = 255; | |
private int iAlpha = 255; | |
public Color(int pRed, int pGreen, int pBlue) { | |
this(pRed, pGreen, pBlue, 255); | |
} | |
public Color(float pRed, float pGreen, float pBlue) { | |
this(pRed, pGreen, pBlue, 1F); | |
} | |
public Color(int pRed, int pGreen, int pBlue, int pAlpha) { | |
if (pRed > 255) { | |
pRed = 255; | |
} | |
if (pGreen > 255) { | |
pGreen = 255; | |
} | |
if (pBlue > 255) { | |
pBlue = 255; | |
} | |
if (pAlpha > 255) { | |
pAlpha = 255; | |
} | |
this.iColorRed = pRed; | |
this.iColorGreen = pGreen; | |
this.iColorBlue = pBlue; | |
this.iAlpha = pAlpha; | |
} | |
public Color(float pRed, float pGreen, float pBlue, float pAlpha) { | |
this((int) (pRed * 255), (int) (pGreen * 255), (int) (pBlue * 255), (int) (pAlpha * 255)); | |
} | |
public Color(int pColor) { | |
iColorRed = pColor >> 16 & 255; | |
iColorGreen = pColor >> 8 & 255; | |
iColorBlue = pColor & 255; | |
} | |
public int getColorRedInt() { | |
return this.iColorRed; | |
} | |
public float getColorRedFloat() { | |
return (float) (this.iColorRed / 255F); | |
} | |
public int getColorGreenInt() { | |
return this.iColorGreen; | |
} | |
public float getColorGreenFloat() { | |
return (float) (this.iColorGreen / 255F); | |
} | |
public int getColorBlueInt() { | |
return this.iColorBlue; | |
} | |
public float getColorBlueFloat() { | |
return (float) (this.iColorBlue / 255F); | |
} | |
public int getAlphaInt() { | |
return this.iAlpha; | |
} | |
public float getAlphaFloat() { | |
return (float) (this.iAlpha / 255F); | |
} | |
public int getColor() { | |
if (iColorRed > 255) { | |
iColorRed = 255; | |
} | |
if (iColorGreen > 255) { | |
iColorGreen = 255; | |
} | |
if (iColorBlue > 255) { | |
iColorBlue = 255; | |
} | |
if (iAlpha > 255) { | |
iAlpha = 255; | |
} | |
int tReturnValue = iColorRed; | |
tReturnValue = (tReturnValue << 8) + iColorGreen; | |
tReturnValue = (tReturnValue << 8) + iColorBlue; | |
return tReturnValue; | |
} | |
public void setColorRed(int pRed) { | |
if (pRed > 255) | |
{ | |
pRed = 255; | |
} | |
this.iColorRed = pRed; | |
} | |
public void setColorRed(float pRed) { | |
this.setColorRed((int) (pRed * 255F)); | |
} | |
public void setColorBlue(int pBlue) { | |
if (pBlue > 255) | |
{ | |
pBlue = 255; | |
} | |
this.iColorBlue = pBlue; | |
} | |
public void setColorBlue(float pBlue) { | |
this.setColorBlue((int) (pBlue * 255F)); | |
} | |
public void setColorGreen(int pGreen) { | |
if(pGreen > 255) | |
{ | |
pGreen = 255; | |
} | |
this.iColorGreen = pGreen; | |
} | |
public void setColorGreen(float pGreen) { | |
this.setColorGreen((int) (pGreen * 255F)); | |
} | |
public void setAlpha(int pAlpha) { | |
if(pAlpha > 255) | |
{ | |
pAlpha = 255; | |
} | |
this.iAlpha = pAlpha; | |
} | |
public void setAlpha(float pAlpha) { | |
this.setAlpha((int) (pAlpha * 255F)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment