MinGfx Toolkit  1.0
A minimal library for writing cross-platform (Windows, OSX, linux) graphics programs.
color.h
Go to the documentation of this file.
1 /*
2  This file is part of the MinGfx Project.
3 
4  Copyright (c) 2017,2018 Regents of the University of Minnesota.
5  All Rights Reserved.
6 
7  Original Author(s) of this File:
8  Dan Keefe, 2018, University of Minnesota
9 
10  Author(s) of Significant Updates/Modifications to the File:
11  ...
12  */
13 
14 #ifndef SRC_COLOR_H_
15 #define SRC_COLOR_H_
16 
17 #include <iostream>
18 #include <vector>
19 
20 namespace mingfx {
21 
22 
41 class Color {
42 public:
44  Color();
45 
47  Color(float red, float green, float blue, float alpha=1.0);
48 
50  Color(float *p);
51 
53  Color(const std::vector<float> &vals);
54 
56  Color(const Color& p);
57 
59  virtual ~Color();
60 
62  bool operator==(const Color& p) const;
63 
65  bool operator!=(const Color& p) const;
66 
68  Color& operator=(const Color& p);
69 
71  float operator[](const int i) const;
72 
74  float& operator[](const int i);
75 
77  const float * value_ptr() const;
78 
79  std::vector<float> ToVector() const;
80 
84  Color Lerp(const Color &b, float alpha) const;
85 
89  static Color Lerp(const Color &a, const Color &b, float alpha);
90 
91 
92 private:
93  float c[4];
94 };
95 
96 
97 std::ostream & operator<< ( std::ostream &os, const Color &c);
98 std::istream & operator>> ( std::istream &is, Color &c);
99 
100 
101 } // namespace
102 
103 #endif
Represents a 4-component (R,G,B,A) color, stored internally in a float array to be compatable with Op...
Definition: color.h:41
float & operator[](const int i)
Accesses the ith coordinate of the color, stored in RGBA order.
bool operator==(const Color &p) const
Check for equality.
Color(const std::vector< float > &vals)
Constructs a point given a 3 or 4-element vector of floats.
Color(float red, float green, float blue, float alpha=1.0)
Constructs a color. Alpha defaults to 1.0 (completely opaque)
static Color Lerp(const Color &a, const Color &b, float alpha)
Linear interpolation between two colors. Alpha=0.0 returns 'a' and alpha=1.0 returns 'b',...
const float * value_ptr() const
Returns a const pointer to the raw data array.
float operator[](const int i) const
Accesses the ith component of the color, stored in RGBA order.
virtual ~Color()
Color destructor.
Color()
Defaults to black.
Color(float *p)
Constructs a point given a pointer to float array.
Color Lerp(const Color &b, float alpha) const
Linear interpolation between this color and another. Alpha=0.0 returns this color,...
Color(const Color &p)
Copy constructor.
bool operator!=(const Color &p) const
Check for inequality.
Color & operator=(const Color &p)
Assignment operator.
std::vector< float > ToVector() const
Namespace for the MinGfx Toolkit.
Definition: aabb.h:21
std::ostream & operator<<(std::ostream &os, const Color &c)
std::istream & operator>>(std::istream &is, Color &c)