-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor.h
61 lines (52 loc) · 1.28 KB
/
color.h
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
53
54
55
56
57
58
59
60
61
#ifndef COLOR_H_
#define COLOR_H_
#include <SDL2/SDL.h>
#include <iostream>
using namespace std;
class Color
{
private:
unsigned char red = 0;
unsigned char green = 0;
unsigned char blue = 0;
unsigned char alpha = 1; //note: alpha is belongs to [0 , 1]
unsigned int color = 0; //new Uint32;
public:
void setColor(unsigned char r, unsigned char g, unsigned char b , unsigned char alpha)
{
red = r;
green = g;
blue = b;
color = red;
color = color << 8;
color = green;
color = color << 8;
color = blue;
color = color << 8;
color = alpha;
color = color << 8;
}
static unsigned int RGBA(unsigned char red, unsigned char green, unsigned char blue,unsigned char alpha)
{
unsigned int color;
color = red;
color = color << 8;
color = green;
color = color << 8;
color = blue;
color = color << 8;
color = alpha;
color = color << 8;
return color;
}
void showColor()
{
cout << "Red:" << (int)red << " Green: " << (int)green << " Blue: "
<< (int)blue << " Whole color is " << color << endl;
}
Uint32 returnColor()
{
return color;
}
};
#endif