Skip to content

Commit 4a26143

Browse files
authored
Merge pull request #7696 from artificiel/ofcolor-vector
Ofcolor vector constructor
2 parents cc5b398 + 1044a16 commit 4a26143

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

libs/openFrameworks/types/ofColor.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <glm/ext/scalar_common.hpp>
1010
#include <glm/vec3.hpp>
1111
#include <iostream>
12+
#include <limits>
13+
#include <vector>
1214

1315
/// \class ofColor_
1416
///
@@ -41,6 +43,20 @@ class ofColor_{
4143
/// \param alpha The alpha component.
4244
ofColor_(float red, float green, float blue, float alpha = limit());
4345

46+
/// \brief Construct an ofColor_ by using values in a vector
47+
///
48+
/// \param list 1 item = The gray value (full alpha)
49+
/// \param list 2 items = The gray value + alpha
50+
/// \param list 3 items = The RGB values (full alpha)
51+
/// \param list 4 items = The RGB values + alpha
52+
template<class InitType>
53+
ofColor_(std::vector<InitType> list): ofColor_() {
54+
if (list.size() == 1) set(list[0]);
55+
if (list.size() == 2) set(list[0], list[1]);
56+
if (list.size() == 3) set(list[0], list[1], list[2]);
57+
if (list.size() == 4) set(list[0], list[1], list[2], list[3]);
58+
}
59+
4460
/// \brief Construct a grayscale ofColor_ by specifying a single number.
4561
///
4662
/// \param gray A grayscale value.

0 commit comments

Comments
 (0)