Stefan Schuermans commited on 2019-06-09 20:32:40
Showing 3 changed files, with 120 additions and 0 deletions.
| ... | ... |
@@ -0,0 +1,57 @@ |
| 1 |
+/* Blinker |
|
| 2 |
+ Copyright 2011-2019 Stefan Schuermans <stefan@blinkenarea.org> |
|
| 3 |
+ Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html |
|
| 4 |
+ a blinkenarea.org project */ |
|
| 5 |
+ |
|
| 6 |
+#include <iomanip> |
|
| 7 |
+#include <sstream> |
|
| 8 |
+#include <string> |
|
| 9 |
+ |
|
| 10 |
+#include "Color.h" |
|
| 11 |
+#include "StringParser.h" |
|
| 12 |
+ |
|
| 13 |
+namespace Blinker {
|
|
| 14 |
+ |
|
| 15 |
+/// constructor |
|
| 16 |
+Color::Color(): |
|
| 17 |
+ m_red(0), |
|
| 18 |
+ m_green(0), |
|
| 19 |
+ m_blue(0) |
|
| 20 |
+{
|
|
| 21 |
+} |
|
| 22 |
+ |
|
| 23 |
+/** |
|
| 24 |
+ * @brief parse from string |
|
| 25 |
+ * @param[in] str color as string in web format |
|
| 26 |
+ * @return if parsing was successful |
|
| 27 |
+ */ |
|
| 28 |
+bool Color::fromStr(const std::string &str) |
|
| 29 |
+{
|
|
| 30 |
+ StringParser parser(str); |
|
| 31 |
+ unsigned int red, green, blue; |
|
| 32 |
+ if (!parser.uintHex(2, red) || |
|
| 33 |
+ !parser.uintHex(2, green) || |
|
| 34 |
+ !parser.uintHex(2, blue) || |
|
| 35 |
+ !parser.isDone()) {
|
|
| 36 |
+ return false; |
|
| 37 |
+ } |
|
| 38 |
+ m_red = red; |
|
| 39 |
+ m_green = green; |
|
| 40 |
+ m_blue = blue; |
|
| 41 |
+ return true; |
|
| 42 |
+} |
|
| 43 |
+ |
|
| 44 |
+/** |
|
| 45 |
+ * @brief convert to string |
|
| 46 |
+ * @return color as string in web format |
|
| 47 |
+ */ |
|
| 48 |
+std::string Color::toStr() const |
|
| 49 |
+{
|
|
| 50 |
+ std::stringstream strm; |
|
| 51 |
+ strm << std::hex << std::setw(2) << std::setfill('0')
|
|
| 52 |
+ << m_red << m_green << m_blue; |
|
| 53 |
+ return strm.str(); |
|
| 54 |
+} |
|
| 55 |
+ |
|
| 56 |
+} // namespace Blinker |
|
| 57 |
+ |
| ... | ... |
@@ -0,0 +1,43 @@ |
| 1 |
+/* Blinker |
|
| 2 |
+ Copyright 2011-2019 Stefan Schuermans <stefan@blinkenarea.org> |
|
| 3 |
+ Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html |
|
| 4 |
+ a blinkenarea.org project */ |
|
| 5 |
+ |
|
| 6 |
+#ifndef BLINKER_COLOR_H |
|
| 7 |
+#define BLINKER_COLOR_H |
|
| 8 |
+ |
|
| 9 |
+#include <string> |
|
| 10 |
+ |
|
| 11 |
+namespace Blinker {
|
|
| 12 |
+ |
|
| 13 |
+/// a color (24 bit RGB in web notation) |
|
| 14 |
+class Color |
|
| 15 |
+{
|
|
| 16 |
+public: |
|
| 17 |
+ /// constructor |
|
| 18 |
+ Color(); |
|
| 19 |
+ |
|
| 20 |
+public: |
|
| 21 |
+ /** |
|
| 22 |
+ * @brief parse from string |
|
| 23 |
+ * @param[in] str color as string in web format |
|
| 24 |
+ * @return if parsing was successful |
|
| 25 |
+ */ |
|
| 26 |
+ bool fromStr(const std::string &str); |
|
| 27 |
+ |
|
| 28 |
+ /** |
|
| 29 |
+ * @brief convert to string |
|
| 30 |
+ * @return color as string in web format |
|
| 31 |
+ */ |
|
| 32 |
+ std::string toStr() const; |
|
| 33 |
+ |
|
| 34 |
+public: |
|
| 35 |
+ unsigned char m_red; ///< red channel of color |
|
| 36 |
+ unsigned char m_green; ///< red channel of color |
|
| 37 |
+ unsigned char m_blue; ///< red channel of color |
|
| 38 |
+}; // class Color |
|
| 39 |
+ |
|
| 40 |
+} // namespace Blinker |
|
| 41 |
+ |
|
| 42 |
+#endif // #ifndef BLINKER_COLOR_H |
|
| 43 |
+ |
| ... | ... |
@@ -0,0 +1,20 @@ |
| 1 |
+/* Blinker |
|
| 2 |
+ Copyright 2011-2019 Stefan Schuermans <stefan@blinkenarea.org> |
|
| 3 |
+ Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html |
|
| 4 |
+ a blinkenarea.org project */ |
|
| 5 |
+ |
|
| 6 |
+#ifndef BLINKER_COLORFILE_H |
|
| 7 |
+#define BLINKER_COLORFILE_H |
|
| 8 |
+ |
|
| 9 |
+#include "Color.h" |
|
| 10 |
+#include "SettingFile_impl.h" |
|
| 11 |
+ |
|
| 12 |
+namespace Blinker {
|
|
| 13 |
+ |
|
| 14 |
+/// setting file containting color |
|
| 15 |
+typedef SettingFile<Color> ColorFile; |
|
| 16 |
+ |
|
| 17 |
+} // namespace Blinker |
|
| 18 |
+ |
|
| 19 |
+#endif // #ifndef BLINKER_COLORFILE_H |
|
| 20 |
+ |
|
| 0 | 21 |