-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColor.cpp
More file actions
52 lines (41 loc) · 1011 Bytes
/
Color.cpp
File metadata and controls
52 lines (41 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Original Author: Kyle Netherland
// Used with permission by Steven Ulfelder
#include "Color.h"
#include <string>
#include <sstream>
using namespace std;
void Color::setColor(unsigned int R, unsigned int G, unsigned int B, unsigned int A)
{
this->R = R;
this->G = G;
this->B = B;
if (A > 255)
this->A = A;
else
this->A = 255;
}
bool Color::equals(unsigned R, unsigned G, unsigned B)
{
if (R == this->R && G == this->G && B == this->B)
return true;
return false;
}
unsigned Color::getHex()
{
int rgbVal = ((this->R & 0xff) << 16) | ((this->G & 0xff) << 8) | (this->B & 0xff);
static string hexDigits = "0123456789ABCDEF";
string rgbStr = "";
for (int i = (3 * 2) - 1; i >= 0; i--)
rgbStr += hexDigits[((rgbVal >> i * 4) & 0xF)];
if (rgbStr == "000000")
return (unsigned)000000;
unsigned toReturn;
istringstream iss(rgbStr);
iss >> hex >> toReturn;
return toReturn;
}
SDL_Color Color::getSDLColor()
{
SDL_Color tmpColor = { this->R, this->G, this->B };
return tmpColor;
}