forked from cuberite/cuberite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Created new color class to handle dye-related coloring
- Loading branch information
1 parent
118aec1
commit 561296f
Showing
10 changed files
with
420 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules | ||
|
||
#include "Color.h" | ||
|
||
|
||
|
||
|
||
|
||
#define COLOR_RED_BITS 0x00FF0000 | ||
#define COLOR_GREEN_BITS 0x0000FF00 | ||
#define COLOR_BLUE_BITS 0x000000FF | ||
#define COLOR_RED_OFFSET 16 | ||
#define COLOR_GREEN_OFFSET 8 | ||
|
||
|
||
|
||
|
||
|
||
void cColor::SetColor(unsigned char a_Red, unsigned char a_Green, unsigned char a_Blue) | ||
{ | ||
m_Color = (static_cast<unsigned int>(a_Red) << COLOR_RED_OFFSET) + (static_cast<unsigned int>(a_Green) << COLOR_GREEN_OFFSET) + (static_cast<unsigned int>(a_Blue)); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
void cColor::SetRed(unsigned char a_Red) | ||
{ | ||
m_Color = (static_cast<unsigned int>(a_Red) << COLOR_RED_OFFSET) + ((COLOR_GREEN_BITS | COLOR_BLUE_BITS) & m_Color); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
void cColor::SetGreen(unsigned char a_Green) | ||
{ | ||
m_Color = (static_cast<unsigned int>(a_Green) << COLOR_GREEN_OFFSET) + ((COLOR_RED_BITS | COLOR_BLUE_BITS) & m_Color); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
void cColor::SetBlue(unsigned char a_Blue) | ||
{ | ||
m_Color = static_cast<unsigned int>(a_Blue) + ((COLOR_RED_BITS | COLOR_GREEN_BITS) & m_Color); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
unsigned char cColor::GetRed() const | ||
{ | ||
return (m_Color & COLOR_RED_BITS) >> COLOR_RED_OFFSET; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
unsigned char cColor::GetGreen() const | ||
{ | ||
return (m_Color & COLOR_GREEN_BITS) >> COLOR_GREEN_OFFSET; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
unsigned char cColor::GetBlue() const | ||
{ | ||
return m_Color & COLOR_BLUE_BITS; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
|
||
// Color.h | ||
|
||
// Declares a class to handle item color related code | ||
|
||
|
||
|
||
|
||
|
||
#pragma once | ||
|
||
// tolua_begin | ||
|
||
class cColor | ||
{ | ||
public: | ||
|
||
enum | ||
{ | ||
COLOR_MIN = 0, | ||
COLOR_MAX = 255, | ||
COLOR_LIMIT = 256, | ||
COLOR_NONE = 0xFFFFFFFF, | ||
}; | ||
cColor() { m_Color = COLOR_NONE;} | ||
cColor(unsigned char a_Red, unsigned char a_Green, unsigned char a_Blue) { SetColor(a_Red, a_Green, a_Blue); } | ||
|
||
/// Returns whether the color is a valid color | ||
bool IsValid() const { return m_Color != COLOR_NONE; } | ||
|
||
/// Changes the color | ||
void SetColor(unsigned char a_Red, unsigned char a_Green, unsigned char a_Blue); | ||
|
||
/// Alters the red value of the color | ||
void SetRed(unsigned char a_Red); | ||
|
||
/// Alters the green value of the color | ||
void SetGreen(unsigned char a_Red); | ||
|
||
/// Alters the blue value of the color | ||
void SetBlue(unsigned char a_Red); | ||
|
||
/// Returns the red value of the color | ||
unsigned char GetRed() const; | ||
|
||
/// Returns the green value of the color | ||
unsigned char GetGreen() const; | ||
|
||
/// Returns the blue value of the color | ||
unsigned char GetBlue() const; | ||
|
||
/// Resets the color | ||
void Clear() { m_Color = COLOR_NONE; } | ||
// tolua_end | ||
|
||
unsigned int m_Color; | ||
|
||
}; |
This file contains 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
Oops, something went wrong.