#include <ETL/angle>
#include "color.h"
#include <cstdio>
+#include <sstream>
+#include <iostream>
#endif
+static ColorReal
+Color::hex2real(String s)
+{
+ std::istringstream i(s);
+ int n;
+ i.fill('0');
+ if (!(i >> hex >> n))
+ throw String("bad conversion from hex string \"") + s + String("\"");
+ return n / 255.0f;
+}
+
+static const String
+Color::real2hex(ColorReal c)
+{
+ std::ostringstream o;
+ o.width(2);
+ o.fill('0');
+ if (c<0) c = 0;
+ if (c>1) c = 1;
+ o << hex << int(c*255.0f);
+ return o.str();
+}
+
+void
+Color::set_hex(String& hex)
+{
+ value_type r, g, b;
+ try
+ {
+ if (hex.size() == 3)
+ {
+ r = hex2real(hex.substr(0,1)+hex.substr(0,1));
+ g = hex2real(hex.substr(1,1)+hex.substr(1,1));
+ b = hex2real(hex.substr(2,1)+hex.substr(2,1));
+ r_ = r; g_ = g; b_ = b;
+ }
+ else if (hex.size() == 6)
+ {
+ r = hex2real(hex.substr(0,2));
+ g = hex2real(hex.substr(2,2));
+ b = hex2real(hex.substr(4,2));
+ r_ = r; g_ = g; b_ = b;
+ }
+ }
+ catch (string s)
+ {
+ printf("caught <%s>\n", s.c_str());
+ return;
+ }
+}
+
#if 0
Color&
Color::rotate_uv(const Angle& theta)const
#include <math.h>
#include <cassert>
#include "gamma.h"
-#include <string.h>
+#include <synfig/string.h>
#ifdef USE_HALF_TYPE
#include <OpenEXR/half.h>
private:
value_type a_, r_, g_, b_;
+ mutable String hex_;
public:
//! Synonym for get_a(). \see get_a()
const value_type& get_alpha()const { return get_a(); }
+ //! Converts a 2 character hex string \a s (00-ff) into a ColorReal (0.0-1.0)
+ static ColorReal hex2real(String s);
+
+ //! Converts a ColorReal \a c (0.0-1.0) into a 2 character hex string (00-ff)
+ static const String real2hex(ColorReal c);
+
+ //! Returns the color as a 6 character hex sting
+ const String& get_hex()const { return hex_ = real2hex(r_)+real2hex(g_)+real2hex(b_); }
+
+ //! Sets the color's R, G, and B from a 3 or 6 character hex string
+ void set_hex(String& hex);
+
//! Sets the RED component to \a x
Color& set_r(const value_type& x) { r_ = x; return *this; }
ATTACH_SPIN_BUTTON(1,G);
SLIDER_ROW(2,B,_("Blue"));
ATTACH_SPIN_BUTTON(2,B);
+
+ hex_color_label = manage(new Gtk::Label(_("HTML code"), 0.0, 0.5));
+ hex_color_label->set_use_markup(false);
+ hex_color_label->set_use_underline(false);
+ hex_color_label->set_attributes(attr_list);
+ table->attach(*hex_color_label, 0, 1, 7, 8, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
+
+ hex_color = manage(new Gtk::Entry());
+ hex_color->set_width_chars(8);
+ hex_color->signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_ColorEdit::on_hex_edited));
+ table->attach(*hex_color, 0, 1, 8, 9, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
}
{
Gtk::Table* table(yuv_table);
}
void
+Widget_ColorEdit::on_hex_edited()
+{
+ Color color(get_value_raw());
+ String s = hex_color->get_text();
+ color.set_hex(s);
+ set_value(color);
+}
+
+void
Widget_ColorEdit::on_value_changed()
{
if(hold_signals)
slider_HUE->set_color(color);
slider_SAT->set_color(color);
slider_A->set_color(color);
+ hex_color->set_text(color.get_hex());
widget_color.set_value(color);
activate();
slider_HUE->set_color(color);
slider_SAT->set_color(color);
slider_A->set_color(color);
+ hex_color->set_text(color.get_hex());
widget_color.set_value(color);
hold_signals=false;
ColorSlider *slider_R;
ColorSlider *slider_G;
ColorSlider *slider_B;
+ Gtk::Label *hex_color_label;
+ Gtk::Entry *hex_color;
+
ColorSlider *slider_A;
ColorSlider *slider_Y;
ColorSlider *slider_U;
sigc::signal<void>& signal_activate() { return signal_activated_; }
void on_slider_moved(ColorSlider::Type type, float amount);
+ void on_hex_edited();
//Glib::SignalProxy0<void> signal_activate() { return spinbutton_A->signal_activate(); }