Add operator overloads for Color taking Color references
This commit is contained in:
		
							parent
							
								
									cae8b21068
								
							
						
					
					
						commit
						dea1967344
					
				
					 2 changed files with 87 additions and 0 deletions
				
			
		|  | @ -391,3 +391,78 @@ Color::operator=(const Color &rhs) | |||
|     alpha = rhs.alpha; | ||||
|     return *this; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| Color & | ||||
| Color::operator*=(const Color &rhs) | ||||
| { | ||||
|     red *= rhs.red; | ||||
|     green *= rhs.green; | ||||
|     blue *= rhs.blue; | ||||
|     return *this; | ||||
| } | ||||
| 
 | ||||
| Color & | ||||
| Color::operator/=(const Color &rhs) | ||||
| { | ||||
|     red *= (1.0 / rhs.red); | ||||
|     green *= (1.0 / rhs.green); | ||||
|     blue *= (1.0 / rhs.blue); | ||||
|     return *this; | ||||
| } | ||||
| 
 | ||||
| Color & | ||||
| Color::operator+=(const Color &rhs) | ||||
| { | ||||
|     red += rhs.red; | ||||
|     green += rhs.green; | ||||
|     blue += rhs.blue; | ||||
|     alpha += rhs.alpha; | ||||
|     return *this; | ||||
| } | ||||
| 
 | ||||
| Color & | ||||
| Color::operator-=(const Color &rhs) | ||||
| { | ||||
|     red -= rhs.red; | ||||
|     green -= rhs.green; | ||||
|     blue -= rhs.blue; | ||||
|     alpha -= rhs.alpha; | ||||
|     return *this; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| Color | ||||
| Color::operator*(const Color &rhs) | ||||
|     const | ||||
| { | ||||
|     return Color(*this) *= rhs; | ||||
| } | ||||
| 
 | ||||
| Color | ||||
| Color::operator/(const Color &rhs) | ||||
|     const | ||||
| { | ||||
|     return Color(*this) /= rhs; | ||||
| } | ||||
| 
 | ||||
| Color | ||||
| Color::operator+(const Color &rhs) | ||||
|     const | ||||
| { | ||||
|     return Color(*this) += rhs; | ||||
| } | ||||
| 
 | ||||
| Color | ||||
| Color::operator-(const Color &rhs) | ||||
|     const | ||||
| { | ||||
|     return Color(*this) -= rhs; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| const Color | ||||
| operator*(const float &lhs, const Color &rhs) | ||||
| { | ||||
|     return rhs * lhs; | ||||
| } | ||||
|  |  | |||
							
								
								
									
										12
									
								
								src/basics.h
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								src/basics.h
									
										
									
									
									
								
							|  | @ -72,6 +72,16 @@ struct Color | |||
| 
 | ||||
|     Color &operator=(const Color &rhs); | ||||
| 
 | ||||
|     // These operators blend the two colors.
 | ||||
|     Color &operator*=(const Color &rhs); | ||||
|     Color &operator/=(const Color &rhs); | ||||
|     Color &operator+=(const Color &rhs); | ||||
|     Color &operator-=(const Color &rhs); | ||||
|     Color operator*(const Color &rhs) const; | ||||
|     Color operator/(const Color &rhs) const; | ||||
|     Color operator+(const Color &rhs) const; | ||||
|     Color operator-(const Color &rhs) const; | ||||
| 
 | ||||
|     static const Color Black; | ||||
|     static const Color White; | ||||
|     static const Color Red; | ||||
|  | @ -81,4 +91,6 @@ struct Color | |||
|     float red, green, blue, alpha; | ||||
| }; | ||||
| 
 | ||||
| const Color operator*(const float &lhs, const Color &rhs); | ||||
| 
 | ||||
| #endif | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue