Author: Carlos Lopez <[email protected]>
Date:   Tue Jun  5 18:57:53 2012 +0200

CairoColor: Add members to display color in hex a decimal format. Add member to 
set color channels based on the hexadecimal string.

---

 synfig-core/src/synfig/color.cpp |   31 +++++++++++++++++++++++++++++++
 synfig-core/src/synfig/color.h   |    8 ++++++++
 2 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/synfig-core/src/synfig/color.cpp b/synfig-core/src/synfig/color.cpp
index d81a507..fc4f31f 100644
--- a/synfig-core/src/synfig/color.cpp
+++ b/synfig-core/src/synfig/color.cpp
@@ -66,6 +66,13 @@ Color::hex2real(String s)
        return n / 255.0f;
 }
 
+unsigned char
+CairoColor::hex2char(String s)
+{
+       ColorReal cr(Color::hex2real(s));
+       return (unsigned char)(cr*255.0f);
+}
+
 const String
 Color::real2hex(ColorReal c)
 {
@@ -78,6 +85,13 @@ Color::real2hex(ColorReal c)
        return o.str();
 }
 
+const String
+CairoColor::char2hex(unsigned char c)
+{
+       String s(Color::real2hex((ColorReal)(c/((float)ceil()))));
+       return s.c_str();
+}
+
 void
 Color::set_hex(String& str)
 {
@@ -118,6 +132,16 @@ Color::set_hex(String& str)
        }
 }
 
+void 
+CairoColor::set_hex(String& str)
+{
+       CairoColor ret(*this);
+       Color c;
+       c.set_hex(str);
+       c=c.clamped();
+       ret=CairoColor(c);
+}
+
 const String
 Color::get_string(void)const
 {
@@ -126,6 +150,13 @@ Color::get_string(void)const
        return String(o.str().c_str());
 }
 
+const String
+CairoColor::get_string(void)const
+{
+       std::ostringstream o;
+       o << std::fixed << std::setprecision(3) << "#" << get_hex() << " : " << 
std::setw(6) << a_;
+       return String(o.str().c_str());
+}
 
 Color
 Color::clamped_negative()const
diff --git a/synfig-core/src/synfig/color.h b/synfig-core/src/synfig/color.h
index 8e0e93d..de0586b 100644
--- a/synfig-core/src/synfig/color.h
+++ b/synfig-core/src/synfig/color.h
@@ -723,6 +723,14 @@ public:
        const unsigned char get_b()const { return b_; }
        const unsigned char get_a()const { return a_; }
        const unsigned char get_alpha()const { return a_; }
+       
+       const String get_string(void)const;
+
+       static const String char2hex(unsigned char c);
+       static unsigned char hex2char(String s);
+       
+       void set_hex( String& str);
+       const String get_hex()const { return 
String(char2hex(r_)+char2hex(g_)+char2hex(b_)); }
 
        CairoColor& set_r(const unsigned char x) {r_ = x; return *this; }
        CairoColor& set_g(const unsigned char x) {g_ = x; return *this; }


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Synfig-devl mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synfig-devl

Reply via email to