-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColour.cpp
More file actions
executable file
·136 lines (115 loc) · 3.69 KB
/
Colour.cpp
File metadata and controls
executable file
·136 lines (115 loc) · 3.69 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* Colour.cpp
* Solar
*
* Created by Michael Robinson on 29/11/2010.
* Copyright 2010 . All rights reserved.
*
*/
#include "Colour.h"
Colour::Colour() {
red = green = blue = 0.0f;
alpha = 1.0f;
}
Colour::~Colour() {
}
Colour::Colour(const Colour& copyMe) {
red = copyMe.getRedComponent();
green = copyMe.getGreenComponent();
blue = copyMe.getBlueComponent();
alpha = copyMe.getAlphaComponent();
}
Colour& Colour::operator=(const Colour& assignFromMe) {
if (this != &assignFromMe) {
//delete members from the stack
//none
//copy in new members
red = assignFromMe.getRedComponent();
green = assignFromMe.getGreenComponent();
blue = assignFromMe.getBlueComponent();
alpha = assignFromMe.getAlphaComponent();
}
return *this;
}
Colour Colour::operator+(const Colour& otherColour) const {
Colour newColour = Colour(otherColour.getRedComponent() + red, otherColour.getGreenComponent() + green, otherColour.getBlueComponent());
if (newColour.getRedComponent() > 1.0f) {
newColour.setRedComponent(1.0f);
}
if (newColour.getGreenComponent() > 1.0f) {
newColour.setGreenComponent(1.0f);
}
if (newColour.getBlueComponent() > 1.0f) {
newColour.setBlueComponent(1.0f);
}
return newColour;
}
Colour::Colour(float newRed, float newGreen, float newBlue, float newAlpha, float limit) {
float factor = limit * 1.0f;
red = newRed / factor;
green = newGreen / factor;
blue = newBlue / factor;
alpha = newAlpha / factor;
}
Colour::Colour(unsigned short newRed, unsigned short newGreen, unsigned short newBlue, unsigned short newAlpha, unsigned short limit) {
float factor = static_cast<float>(limit) * 1.0f;
red = static_cast<float>(newRed) / factor;
green = static_cast<float>(newGreen) / factor;
blue = static_cast<float>(newBlue) / factor;
alpha = static_cast<float>(newAlpha) / factor;
}
float Colour::getRedComponent() const {
return red;
}
float Colour::getGreenComponent() const {
return green;
}
float Colour::getBlueComponent() const {
return blue;
}
float Colour::getAlphaComponent() const {
return alpha;
}
float Colour::setRedComponent(float newRed) {
return red = newRed;
}
float Colour::setGreenComponent(float newGreen) {
return green = newGreen;
}
float Colour::setBlueComponent(float newBlue) {
return blue = newBlue;
}
float Colour::setAlphaComponent(float newAlpha) {
return alpha = newAlpha;
}
Colour* Colour::setRGBA(float newRed, float newGreen, float newBlue, float newAlpha = 1.0f, float limit = 1.0f) {
float factor = limit * 1.0f;
red = newRed / factor;
green = newGreen / factor;
blue = newBlue / factor;
alpha = newAlpha / factor;
return this;
}
unsigned short Colour::setRedComponent(unsigned short newRed, unsigned short limit) {
red = static_cast<float> (newRed) / static_cast<float> (limit);
return newRed;
}
unsigned short Colour::setGreenComponent(unsigned short newGreen, unsigned short limit) {
green = static_cast<float> (newGreen) / static_cast<float> (limit);
return newGreen;
}
unsigned short Colour::setBlueComponent(unsigned short newBlue, unsigned short limit) {
blue = static_cast<float> (newBlue) / static_cast<float> (limit);
return newBlue;
}
unsigned short Colour::setAlphaComponent(unsigned short newAlpha, unsigned short limit) {
alpha = static_cast<float> (newAlpha) / static_cast<float> (limit);
return newAlpha;
}
Colour* Colour::setRGBA(unsigned short newRed, unsigned short newGreen, unsigned short newBlue, unsigned short newAlpha, unsigned short limit) {
red = static_cast<float> (newRed) / static_cast<float> (limit);
green = static_cast<float> (newGreen) / static_cast<float> (limit);
blue = static_cast<float> (newBlue) / static_cast<float> (limit);
alpha = static_cast<float> (newAlpha) / static_cast<float> (limit);
return this;
}