From: David ‘Bombe’ Roden Date: Sat, 22 Aug 2009 21:18:44 +0000 (+0200) Subject: Rename Widget_ColorEdit to Widget_CustomColorEdit to prepare for new abstract Widget_... X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=c48a66962db4484b891c6a1933bd9888f49a6413;p=synfig.git Rename Widget_ColorEdit to Widget_CustomColorEdit to prepare for new abstract Widget_ColorEdit. --- diff --git a/synfig-studio/po/POTFILES.in b/synfig-studio/po/POTFILES.in index dd9f9a7..6bc2ba9 100644 --- a/synfig-studio/po/POTFILES.in +++ b/synfig-studio/po/POTFILES.in @@ -210,8 +210,8 @@ src/gtkmm/valuelink.h src/gtkmm/widget_canvaschooser.cpp src/gtkmm/widget_canvaschooser.h src/gtkmm/widget_color.cpp -src/gtkmm/widget_coloredit.cpp -src/gtkmm/widget_coloredit.h +src/gtkmm/widget_customcoloredit.cpp +src/gtkmm/widget_customcoloredit.h src/gtkmm/widget_color.h src/gtkmm/widget_compselect.cpp src/gtkmm/widget_compselect.h diff --git a/synfig-studio/po/ca.po b/synfig-studio/po/ca.po index 1921bdb..7634ad7 100644 --- a/synfig-studio/po/ca.po +++ b/synfig-studio/po/ca.po @@ -1111,15 +1111,15 @@ msgstr "Restringir Ànecs de valors reals al quadrant superior dret" msgid "Gamma" msgstr "Gamma" -#: src/gtkmm/dialog_setup.cpp:116 src/gtkmm/widget_coloredit.cpp:353 +#: src/gtkmm/dialog_setup.cpp:116 src/gtkmm/widget_customcoloredit.cpp:353 msgid "Red" msgstr "Roig" -#: src/gtkmm/dialog_setup.cpp:121 src/gtkmm/widget_coloredit.cpp:355 +#: src/gtkmm/dialog_setup.cpp:121 src/gtkmm/widget_customcoloredit.cpp:355 msgid "Green" msgstr "Verd" -#: src/gtkmm/dialog_setup.cpp:126 src/gtkmm/widget_coloredit.cpp:357 +#: src/gtkmm/dialog_setup.cpp:126 src/gtkmm/widget_customcoloredit.cpp:357 msgid "Blue" msgstr "Blau" @@ -2687,39 +2687,39 @@ msgstr "Error: S'ha llançat una excepció" msgid "Unknown Exception" msgstr "Excepció desconeguda" -#: src/gtkmm/widget_coloredit.cpp:304 +#: src/gtkmm/widget_customcoloredit.cpp:304 msgid "RGB" msgstr "RGB" -#: src/gtkmm/widget_coloredit.cpp:305 +#: src/gtkmm/widget_customcoloredit.cpp:305 msgid "YUV" msgstr "YUV" -#: src/gtkmm/widget_coloredit.cpp:360 +#: src/gtkmm/widget_customcoloredit.cpp:360 msgid "HTML code" msgstr "Codi HTML" -#: src/gtkmm/widget_coloredit.cpp:373 +#: src/gtkmm/widget_customcoloredit.cpp:373 msgid "Luma" msgstr "Luma" -#: src/gtkmm/widget_coloredit.cpp:374 +#: src/gtkmm/widget_customcoloredit.cpp:374 msgid "Hue" msgstr "Matís" -#: src/gtkmm/widget_coloredit.cpp:375 +#: src/gtkmm/widget_customcoloredit.cpp:375 msgid "Saturation" msgstr "Saturació" -#: src/gtkmm/widget_coloredit.cpp:376 +#: src/gtkmm/widget_customcoloredit.cpp:376 msgid "U" msgstr "U" -#: src/gtkmm/widget_coloredit.cpp:377 +#: src/gtkmm/widget_customcoloredit.cpp:377 msgid "V" msgstr "V" -#: src/gtkmm/widget_coloredit.cpp:381 +#: src/gtkmm/widget_customcoloredit.cpp:381 msgid "Alpha" msgstr "Transparència" diff --git a/synfig-studio/po/es.po b/synfig-studio/po/es.po index 5cccda0..f91fb43 100644 --- a/synfig-studio/po/es.po +++ b/synfig-studio/po/es.po @@ -1109,15 +1109,15 @@ msgstr "Restringir Nodos de Valores Reales al Cuadrante Superior Derecho" msgid "Gamma" msgstr "Gamma" -#: src/gtkmm/dialog_setup.cpp:119 src/gtkmm/widget_coloredit.cpp:353 +#: src/gtkmm/dialog_setup.cpp:119 src/gtkmm/widget_customcoloredit.cpp:353 msgid "Red" msgstr "Rojo" -#: src/gtkmm/dialog_setup.cpp:124 src/gtkmm/widget_coloredit.cpp:355 +#: src/gtkmm/dialog_setup.cpp:124 src/gtkmm/widget_customcoloredit.cpp:355 msgid "Green" msgstr "Verde" -#: src/gtkmm/dialog_setup.cpp:129 src/gtkmm/widget_coloredit.cpp:357 +#: src/gtkmm/dialog_setup.cpp:129 src/gtkmm/widget_customcoloredit.cpp:357 msgid "Blue" msgstr "Azul" @@ -2900,39 +2900,39 @@ msgstr "Error: Excepción Lanzada" msgid "Unknown Exception" msgstr "Excepción Desconocida" -#: src/gtkmm/widget_coloredit.cpp:304 +#: src/gtkmm/widget_customcoloredit.cpp:304 msgid "RGB" msgstr "RGB" -#: src/gtkmm/widget_coloredit.cpp:305 +#: src/gtkmm/widget_customcoloredit.cpp:305 msgid "YUV" msgstr "YUV" -#: src/gtkmm/widget_coloredit.cpp:360 +#: src/gtkmm/widget_customcoloredit.cpp:360 msgid "HTML code" msgstr "Código HTML" -#: src/gtkmm/widget_coloredit.cpp:373 +#: src/gtkmm/widget_customcoloredit.cpp:373 msgid "Luma" msgstr "Luma" -#: src/gtkmm/widget_coloredit.cpp:374 +#: src/gtkmm/widget_customcoloredit.cpp:374 msgid "Hue" msgstr "Matiz" -#: src/gtkmm/widget_coloredit.cpp:375 +#: src/gtkmm/widget_customcoloredit.cpp:375 msgid "Saturation" msgstr "Saturación" -#: src/gtkmm/widget_coloredit.cpp:376 +#: src/gtkmm/widget_customcoloredit.cpp:376 msgid "U" msgstr "U" -#: src/gtkmm/widget_coloredit.cpp:377 +#: src/gtkmm/widget_customcoloredit.cpp:377 msgid "V" msgstr "V" -#: src/gtkmm/widget_coloredit.cpp:381 +#: src/gtkmm/widget_customcoloredit.cpp:381 msgid "Alpha" msgstr "Transparencia" diff --git a/synfig-studio/po/fr.po b/synfig-studio/po/fr.po index d0b9465..90921fb 100644 --- a/synfig-studio/po/fr.po +++ b/synfig-studio/po/fr.po @@ -1110,15 +1110,15 @@ msgstr "" msgid "Gamma" msgstr "Gamma" -#: src/gtkmm/dialog_setup.cpp:119 src/gtkmm/widget_coloredit.cpp:353 +#: src/gtkmm/dialog_setup.cpp:119 src/gtkmm/widget_customcoloredit.cpp:353 msgid "Red" msgstr "Rouge" -#: src/gtkmm/dialog_setup.cpp:124 src/gtkmm/widget_coloredit.cpp:355 +#: src/gtkmm/dialog_setup.cpp:124 src/gtkmm/widget_customcoloredit.cpp:355 msgid "Green" msgstr "Vert" -#: src/gtkmm/dialog_setup.cpp:129 src/gtkmm/widget_coloredit.cpp:357 +#: src/gtkmm/dialog_setup.cpp:129 src/gtkmm/widget_customcoloredit.cpp:357 msgid "Blue" msgstr "Bleu" @@ -2901,39 +2901,39 @@ msgstr "Erreur : Exception générée" msgid "Unknown Exception" msgstr "Exception inconnue" -#: src/gtkmm/widget_coloredit.cpp:304 +#: src/gtkmm/widget_customcoloredit.cpp:304 msgid "RGB" msgstr "RVB" -#: src/gtkmm/widget_coloredit.cpp:305 +#: src/gtkmm/widget_customcoloredit.cpp:305 msgid "YUV" msgstr "YUV" -#: src/gtkmm/widget_coloredit.cpp:360 +#: src/gtkmm/widget_customcoloredit.cpp:360 msgid "HTML code" msgstr "Code HTML" -#: src/gtkmm/widget_coloredit.cpp:373 +#: src/gtkmm/widget_customcoloredit.cpp:373 msgid "Luma" msgstr "Luminance" -#: src/gtkmm/widget_coloredit.cpp:374 +#: src/gtkmm/widget_customcoloredit.cpp:374 msgid "Hue" msgstr "Teinte" -#: src/gtkmm/widget_coloredit.cpp:375 +#: src/gtkmm/widget_customcoloredit.cpp:375 msgid "Saturation" msgstr "Saturation" -#: src/gtkmm/widget_coloredit.cpp:376 +#: src/gtkmm/widget_customcoloredit.cpp:376 msgid "U" msgstr "U" -#: src/gtkmm/widget_coloredit.cpp:377 +#: src/gtkmm/widget_customcoloredit.cpp:377 msgid "V" msgstr "V" -#: src/gtkmm/widget_coloredit.cpp:381 +#: src/gtkmm/widget_customcoloredit.cpp:381 msgid "Alpha" msgstr "Alpha" diff --git a/synfig-studio/po/ru.po b/synfig-studio/po/ru.po index c4202fd..884d10f 100644 --- a/synfig-studio/po/ru.po +++ b/synfig-studio/po/ru.po @@ -1099,15 +1099,15 @@ msgstr "" msgid "Gamma" msgstr "Гамма" -#: src/gtkmm/dialog_setup.cpp:121 src/gtkmm/widget_coloredit.cpp:354 +#: src/gtkmm/dialog_setup.cpp:121 src/gtkmm/widget_customcoloredit.cpp:354 msgid "Red" msgstr "Красный" -#: src/gtkmm/dialog_setup.cpp:126 src/gtkmm/widget_coloredit.cpp:356 +#: src/gtkmm/dialog_setup.cpp:126 src/gtkmm/widget_customcoloredit.cpp:356 msgid "Green" msgstr "Зеленый" -#: src/gtkmm/dialog_setup.cpp:131 src/gtkmm/widget_coloredit.cpp:358 +#: src/gtkmm/dialog_setup.cpp:131 src/gtkmm/widget_customcoloredit.cpp:358 msgid "Blue" msgstr "Синий" @@ -2906,39 +2906,39 @@ msgstr "" msgid "Unknown Exception" msgstr "" -#: src/gtkmm/widget_coloredit.cpp:305 +#: src/gtkmm/widget_customcoloredit.cpp:305 msgid "RGB" msgstr "RGB" -#: src/gtkmm/widget_coloredit.cpp:306 +#: src/gtkmm/widget_customcoloredit.cpp:306 msgid "YUV" msgstr "YUV" -#: src/gtkmm/widget_coloredit.cpp:361 +#: src/gtkmm/widget_customcoloredit.cpp:361 msgid "HTML code" msgstr "Код HTML" -#: src/gtkmm/widget_coloredit.cpp:374 +#: src/gtkmm/widget_customcoloredit.cpp:374 msgid "Luma" msgstr "Светимость" -#: src/gtkmm/widget_coloredit.cpp:375 +#: src/gtkmm/widget_customcoloredit.cpp:375 msgid "Hue" msgstr "Тон" -#: src/gtkmm/widget_coloredit.cpp:376 +#: src/gtkmm/widget_customcoloredit.cpp:376 msgid "Saturation" msgstr "Насыщенность" -#: src/gtkmm/widget_coloredit.cpp:377 +#: src/gtkmm/widget_customcoloredit.cpp:377 msgid "U" msgstr "U" -#: src/gtkmm/widget_coloredit.cpp:378 +#: src/gtkmm/widget_customcoloredit.cpp:378 msgid "V" msgstr "V" -#: src/gtkmm/widget_coloredit.cpp:382 +#: src/gtkmm/widget_customcoloredit.cpp:382 msgid "Alpha" msgstr "Альфа" diff --git a/synfig-studio/src/gtkmm/Makefile.am b/synfig-studio/src/gtkmm/Makefile.am index c5cc73d..171edc1 100644 --- a/synfig-studio/src/gtkmm/Makefile.am +++ b/synfig-studio/src/gtkmm/Makefile.am @@ -124,7 +124,7 @@ DOCK_CC = \ WIDGET_HH = \ widget_canvaschooser.h \ widget_color.h \ - widget_coloredit.h \ + widget_customcoloredit.h \ widget_compselect.h \ widget_curves.h \ widget_defaults.h \ @@ -144,7 +144,7 @@ WIDGET_HH = \ WIDGET_CC = \ widget_canvaschooser.cpp \ widget_color.cpp \ - widget_coloredit.cpp \ + widget_customcoloredit.cpp \ widget_compselect.cpp \ widget_curves.cpp \ widget_defaults.cpp \ diff --git a/synfig-studio/src/gtkmm/dialog_color.cpp b/synfig-studio/src/gtkmm/dialog_color.cpp index 6953a75..2677d9f 100644 --- a/synfig-studio/src/gtkmm/dialog_color.cpp +++ b/synfig-studio/src/gtkmm/dialog_color.cpp @@ -80,7 +80,7 @@ Dialog_Color::~Dialog_Color() void Dialog_Color::create_color_edit_widget() { - color_edit_widget = manage(new Widget_ColorEdit()); + color_edit_widget = manage(new Widget_CustomColorEdit()); color_edit_widget->signal_value_changed().connect(sigc::mem_fun(*this, &studio::Dialog_Color::on_color_changed)); get_vbox()->pack_start(*color_edit_widget); diff --git a/synfig-studio/src/gtkmm/dialog_color.h b/synfig-studio/src/gtkmm/dialog_color.h index ee350cf..3337870 100644 --- a/synfig-studio/src/gtkmm/dialog_color.h +++ b/synfig-studio/src/gtkmm/dialog_color.h @@ -32,7 +32,7 @@ #include #include -#include "widget_coloredit.h" +#include "widget_customcoloredit.h" #include "dialogsettings.h" /* === M A C R O S ========================================================= */ @@ -43,14 +43,14 @@ namespace studio { -class Widget_Color; +class Widget_CustomColor; class Dialog_Color : public Gtk::Dialog { DialogSettings dialog_settings; Gtk::Tooltips tooltips; - Widget_ColorEdit* color_edit_widget; + Widget_CustomColorEdit* color_edit_widget; sigc::signal signal_edited_; diff --git a/synfig-studio/src/gtkmm/dialog_gradient.cpp b/synfig-studio/src/gtkmm/dialog_gradient.cpp index 5a3edca..4254525 100644 --- a/synfig-studio/src/gtkmm/dialog_gradient.cpp +++ b/synfig-studio/src/gtkmm/dialog_gradient.cpp @@ -99,7 +99,7 @@ Dialog_Gradient::Dialog_Gradient(): //table->attach(*manage(new Gtk::Label(_("Not yet fully implemented"))), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); table->attach(*widget_gradient, 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - widget_color=manage(new Widget_ColorEdit()); + widget_color=manage(new Widget_CustomColorEdit()); widget_color->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Gradient::on_values_adjusted)); widget_color->signal_value_changed().connect(sigc::mem_fun(*this,&studio::Dialog_Gradient::on_changed)); widget_color->signal_activated().connect(sigc::mem_fun(*this,&studio::Dialog_Gradient::on_values_adjusted)); diff --git a/synfig-studio/src/gtkmm/dialog_gradient.h b/synfig-studio/src/gtkmm/dialog_gradient.h index f9d674c..c27e24f 100644 --- a/synfig-studio/src/gtkmm/dialog_gradient.h +++ b/synfig-studio/src/gtkmm/dialog_gradient.h @@ -40,7 +40,7 @@ #include #include "widget_gradient.h" -#include "widget_coloredit.h" +#include "widget_customcoloredit.h" #include #include @@ -62,7 +62,7 @@ class CanvasInterface; namespace studio { class Widget_Gradient; -class Widget_ColorEdit; +class Widget_CustomColorEdit; class Dialog_Gradient : public Gtk::Dialog { @@ -85,7 +85,7 @@ class Dialog_Gradient : public Gtk::Dialog void on_values_adjusted(); Widget_Gradient* widget_gradient; - Widget_ColorEdit* widget_color; + Widget_CustomColorEdit* widget_color; Gtk::Button *grab_button; void on_changed(); diff --git a/synfig-studio/src/gtkmm/mod_palette/dock_paledit.h b/synfig-studio/src/gtkmm/mod_palette/dock_paledit.h index 4c1ef2e..7e48272 100644 --- a/synfig-studio/src/gtkmm/mod_palette/dock_paledit.h +++ b/synfig-studio/src/gtkmm/mod_palette/dock_paledit.h @@ -39,12 +39,11 @@ #include #include -#include "../widget_coloredit.h" - #include #include #include "../dockable.h" +#include "../widget_color.h" #include #include diff --git a/synfig-studio/src/gtkmm/widget_coloredit.cpp b/synfig-studio/src/gtkmm/widget_coloredit.cpp deleted file mode 100644 index 5e3175a..0000000 --- a/synfig-studio/src/gtkmm/widget_coloredit.cpp +++ /dev/null @@ -1,587 +0,0 @@ -/* === S Y N F I G ========================================================= */ -/*! \file widget_coloredit.cpp -** \brief Template File -** -** $Id$ -** -** \legal -** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley -** Copyright (c) 2007 Chris Moore -** Copyright (c) 2008 Paul Wise -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** \endlegal -*/ -/* ========================================================================= */ - -/* === H E A D E R S ======================================================= */ - -#ifdef USING_PCH -# include "pch.h" -#else -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "widget_coloredit.h" -#include -#include "app.h" -#include -#include -#include -#include -#include -#include - -#include "general.h" - -#endif - -/* === U S I N G =========================================================== */ - -using namespace std; -using namespace etl; -using namespace synfig; -using namespace studio; - -/* === M A C R O S ========================================================= */ - -#define SPINBUTTON_WIDTH 100 - -/* === G L O B A L S ======================================================= */ - -/* === P R O C E D U R E S ================================================= */ - -/* === C L A S S E S ======================================================= */ - -ColorSlider::ColorSlider(const ColorSlider::Type &x): - type(x) -{ - signal_expose_event().connect(sigc::mem_fun(*this, &ColorSlider::redraw)); - set_size_request(-1,12); - add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK); - add_events(Gdk::BUTTON1_MOTION_MASK); -} - -void -ColorSlider::set_type(Type x) { type=x; queue_draw(); } - -void -ColorSlider::set_color(synfig::Color x) { color_=x; queue_draw(); } - -void -ColorSlider::slider_color_TYPE_R(synfig::Color &color, float amount) { color.set_r(amount); } -void -ColorSlider::slider_color_TYPE_G(synfig::Color &color, float amount) { color.set_g(amount); } -void -ColorSlider::slider_color_TYPE_B(synfig::Color &color, float amount) { color.set_b(amount); } -void -ColorSlider::slider_color_TYPE_Y(synfig::Color &color, float amount) { color.set_y(amount); } -void -ColorSlider::slider_color_TYPE_U(synfig::Color &color, float amount) { color.set_u(amount-0.5f); } -void -ColorSlider::slider_color_TYPE_V(synfig::Color &color, float amount) { color.set_v(amount-0.5f); } -void -ColorSlider::slider_color_TYPE_HUE(synfig::Color &color, float amount) { color.set_uv_angle(Angle::rot(amount)); } -void -ColorSlider::slider_color_TYPE_SAT(synfig::Color &color, float amount) { color.set_s(amount*0.5f); } -void -ColorSlider::slider_color_TYPE_A(synfig::Color &color, float amount) { color.set_a(amount); } - -void -ColorSlider::adjust_color(Type type, synfig::Color &color, float amount) -{ - static const slider_color_func jump_table[int(TYPE_END)] = - { - slider_color_TYPE_R, - slider_color_TYPE_G, - slider_color_TYPE_B, - slider_color_TYPE_Y, - slider_color_TYPE_U, - slider_color_TYPE_V, - slider_color_TYPE_HUE, - slider_color_TYPE_SAT, - slider_color_TYPE_A, - }; - jump_table[int(type)](color,amount); -} - -bool -ColorSlider::redraw(GdkEventExpose */*bleh*/) -{ - Color color(color_); - - static const slider_color_func jump_table[int(TYPE_END)] = - { - slider_color_TYPE_R, - slider_color_TYPE_G, - slider_color_TYPE_B, - slider_color_TYPE_Y, - slider_color_TYPE_U, - slider_color_TYPE_V, - slider_color_TYPE_HUE, - slider_color_TYPE_SAT, - slider_color_TYPE_A, - }; - - slider_color_func color_func(jump_table[int(type)]); - - float amount; - switch(type) - { - case TYPE_R: amount=color.get_r(); break; - case TYPE_G: amount=color.get_g(); break; - case TYPE_B: amount=color.get_b(); break; - case TYPE_Y: amount=color.get_y(); break; - case TYPE_U: amount=color.get_u()+0.5; break; - case TYPE_V: amount=color.get_v()+0.5; break; - case TYPE_HUE: amount=Angle::rot(color.get_uv_angle()).get(); amount-=floor(amount); break; - case TYPE_SAT: amount=color.get_s()*2.0; break; - case TYPE_A: amount=color.get_a(); break; - default: amount=0; break; - } - if(use_colorspace_gamma() && (type gc(Gdk::GC::create(get_window())); - const Color bg1(0.75, 0.75, 0.75); - const Color bg2(0.5, 0.5, 0.5); - int i; - for(i=width-1;i>=0;i--) - { - color_func(color, - (use_colorspace_gamma() && typeset_rgb_fg_color(colorconv_synfig2gdk(c1)); - get_window()->draw_rectangle(gc, true, ca.get_x()+i, ca.get_y(), 1, height/2); - - gc->set_rgb_fg_color(colorconv_synfig2gdk(c2)); - get_window()->draw_rectangle(gc, true, ca.get_x()+i, ca.get_y()+height/2, 1, height/2); - } - else - { - gc->set_rgb_fg_color(colorconv_synfig2gdk(c2)); - get_window()->draw_rectangle(gc, true, ca.get_x()+i, ca.get_y(), 1, height/2); - - gc->set_rgb_fg_color(colorconv_synfig2gdk(c1)); - get_window()->draw_rectangle(gc, true, ca.get_x()+i, ca.get_y()+height/2, 1, height/2); - } - } - - get_style()->paint_arrow( - get_window(), - Gtk::STATE_SELECTED, - Gtk::SHADOW_OUT, - ca, - *this, - " ", - Gtk::ARROW_UP, - 1, - int(amount*width)-height/2, - 0, - height, - height - ); - - gc->set_rgb_fg_color(Gdk::Color("#ffffff")); - get_window()->draw_rectangle(gc, false, ca.get_x()+1, ca.get_y()+1, width-3, height-3); - gc->set_rgb_fg_color(Gdk::Color("#000000")); - get_window()->draw_rectangle(gc, false, ca.get_x(), ca.get_y(), width-1, height-1); - return true; -} - -bool -ColorSlider::on_event(GdkEvent *event) -{ - const int width(get_width()); - float x = 0; - if( GDK_SCROLL == event->type ){ - Color color(color_); - float amount; - switch(type) - { - case TYPE_R: amount=color.get_r(); break; - case TYPE_G: amount=color.get_g(); break; - case TYPE_B: amount=color.get_b(); break; - case TYPE_Y: amount=color.get_y(); break; - case TYPE_U: amount=color.get_u()+0.5; break; - case TYPE_V: amount=color.get_v()+0.5; break; - case TYPE_HUE: amount=Angle::rot(color.get_uv_angle()).get(); amount-=floor(amount); break; - case TYPE_SAT: amount=color.get_s()*2.0; break; - case TYPE_A: amount=color.get_a(); break; - default: amount=0; break; - } - if(use_colorspace_gamma() && (typescroll.direction){ - case GDK_SCROLL_UP: - case GDK_SCROLL_RIGHT: - x+=1.0; - break; - case GDK_SCROLL_DOWN: - case GDK_SCROLL_LEFT: - x-=1.0; - break; - } - } else { - x = float(event->button.x); - } - - float pos(x/width); - if(pos<0 || x<=0)pos=0; - if(pos>1)pos=1; - - if(use_colorspace_gamma() && (typebutton.x<=0)pos=0; - if(pos>1)pos=1; - - switch(event->type) - { - case GDK_SCROLL: - signal_slider_moved_(type,pos); - queue_draw(); - signal_activated_(); - return true; - - case GDK_BUTTON_RELEASE: - signal_activated_(); - return true; - - case GDK_BUTTON_PRESS: - case GDK_MOTION_NOTIFY: -// adjust_color(type,color_,pos); - signal_slider_moved_(type,pos); - queue_draw(); - return true; - break; - default: - break; - } - return false; -} - -/* === M E T H O D S ======================================================= */ - -Widget_ColorEdit::Widget_ColorEdit(): - R_adjustment(0,-10000000,10000000,1,10,0), - G_adjustment(0,-10000000,10000000,1,10,0), - B_adjustment(0,-10000000,10000000,1,10,0), - A_adjustment(0,-10000000,10000000,1,10,0) -{ - notebook=manage(new Gtk::Notebook); - - Gtk::Table* rgb_table(manage(new Gtk::Table())); - Gtk::Table* yuv_table(manage(new Gtk::Table())); - Gtk::Table* main_table(this); - - { - Gtk::VBox* rgb_box(manage(new Gtk::VBox())); - Gtk::VBox* yuv_box(manage(new Gtk::VBox())); - rgb_box->pack_start(*rgb_table,false,false); - yuv_box->pack_start(*yuv_table,false,false); - notebook->append_page(*rgb_box,_("RGB")); - notebook->append_page(*yuv_box,_("YUV")); - } - - color=Color(0,0,0,0); - - set_size_request(200,-1); - hold_signals=true; - - Gtk::Label *label; - - R_adjustment.set_lower(-10000000); - G_adjustment.set_lower(-10000000); - B_adjustment.set_lower(-10000000); - A_adjustment.set_lower(-10000000); - - clamp_=true; - - Pango::AttrList attr_list; - Pango::AttrInt pango_size(Pango::Attribute::create_attr_size(Pango::SCALE*7)); - pango_size.set_start_index(0); - pango_size.set_end_index(64); - attr_list.change(pango_size); - - widget_color.set_size_request(-1,16); - attach(widget_color, 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - attach(*notebook, 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); - -#define SLIDER_ROW(i,n,l) \ - slider_##n=manage(new ColorSlider(ColorSlider::TYPE_##n)); \ - slider_##n->signal_slider_moved().connect(sigc::mem_fun(*this,&studio::Widget_ColorEdit::on_slider_moved)); \ - /*slider_##n->signal_activated().connect(sigc::mem_fun(*this,&studio::Widget_ColorEdit::activated));*/ \ - slider_##n->signal_activated().connect(sigc::mem_fun(*this,&studio::Widget_ColorEdit::on_value_changed)); \ - label=manage(new class Gtk::Label(l,0.0,0.5)); \ - label->set_use_markup(false); \ - label->set_use_underline(false); \ - label->set_attributes(attr_list); \ - table->attach(*label, 0, 1, 1+2*i, 2+2*i, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); \ - table->attach(*slider_##n, 0, 1, 2+2*i, 3+2*i, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0) - -#define ATTACH_SPIN_BUTTON(i,n) \ - spinbutton_##n=manage(new class Gtk::SpinButton(n##_adjustment,1,0)); \ - spinbutton_##n->set_update_policy(Gtk::UPDATE_ALWAYS); \ - spinbutton_##n->set_size_request(SPINBUTTON_WIDTH,-1); \ - spinbutton_##n->show(); \ - table->attach(*spinbutton_##n, 1, 2, 1+2*i, 3+2*i, Gtk::SHRINK, Gtk::EXPAND, 2, 0) - - { - Gtk::Table* table(rgb_table); - SLIDER_ROW(0,R,_("Red")); - ATTACH_SPIN_BUTTON(0,R); - SLIDER_ROW(1,G,_("Green")); - 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); - SLIDER_ROW(0,Y,_("Luma")); - SLIDER_ROW(1,HUE,_("Hue")); - SLIDER_ROW(2,SAT,_("Saturation")); - SLIDER_ROW(3,U,_("U")); - SLIDER_ROW(4,V,_("V")); - } - { - Gtk::Table* table(main_table); - SLIDER_ROW(1,A,_("Alpha")); - ATTACH_SPIN_BUTTON(1,A); - } - -#undef SLIDER_ROW -#undef ATTACH_SPIN_BUTTON - - spinbutton_R->signal_activate().connect(sigc::mem_fun(*spinbutton_G,&Gtk::SpinButton::grab_focus)); - spinbutton_G->signal_activate().connect(sigc::mem_fun(*spinbutton_B,&Gtk::SpinButton::grab_focus)); - spinbutton_B->signal_activate().connect(sigc::mem_fun(*spinbutton_A,&Gtk::SpinButton::grab_focus)); - spinbutton_A->signal_activate().connect(sigc::mem_fun(*spinbutton_R,&Gtk::SpinButton::grab_focus)); - - R_adjustment.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_ColorEdit::on_value_changed)); - G_adjustment.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_ColorEdit::on_value_changed)); - B_adjustment.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_ColorEdit::on_value_changed)); - A_adjustment.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_ColorEdit::on_value_changed)); - - show_all_children(); - - set_digits(1); - set_value(color); - - hold_signals=false; -} - -Widget_ColorEdit::~Widget_ColorEdit() -{ -} - -void -Widget_ColorEdit::on_slider_moved(ColorSlider::Type type, float amount) -{ - Color color(get_value_raw()); - - assert(color.is_valid()); - ColorSlider::adjust_color(type,color,amount); - assert(color.is_valid()); - - // If a non-primary colorslider is adjusted, - // we want to make sure that we clamp - if(type>ColorSlider::TYPE_B && (color.get_r()<0 ||color.get_g()<0 ||color.get_b()<0)) - clamp_=true; - - /* - if(type==ColorSlider::TYPE_R && color.get_r()<0)clamp_=false; - if(type==ColorSlider::TYPE_G && color.get_g()<0)clamp_=false; - if(type==ColorSlider::TYPE_B && color.get_b()<0)clamp_=false; - */ - clamp_=false; - - set_value(color); - assert(color.is_valid()); -} - -void -Widget_ColorEdit::on_hex_edited() -{ - Color color(get_value_raw()); - String s = hex_color->get_text(); - color.set_hex(s); - set_value(color); - signal_value_changed_(); -} - -void -Widget_ColorEdit::on_value_changed() -{ - if(hold_signals) - return; - - const Color color(get_value_raw()); - assert(color.is_valid()); - slider_R->set_color(color); - slider_G->set_color(color); - slider_B->set_color(color); - slider_Y->set_color(color); - slider_U->set_color(color); - slider_V->set_color(color); - 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(); - signal_value_changed_(); -} - -void -Widget_ColorEdit::set_has_frame(bool x) -{ - spinbutton_R->set_has_frame(x); - spinbutton_G->set_has_frame(x); - spinbutton_B->set_has_frame(x); - spinbutton_A->set_has_frame(x); - spinbutton_R->set_size_request(SPINBUTTON_WIDTH,-1); - spinbutton_G->set_size_request(SPINBUTTON_WIDTH,-1); - spinbutton_B->set_size_request(SPINBUTTON_WIDTH,-1); - spinbutton_A->set_size_request(SPINBUTTON_WIDTH,-1); -} - -void -Widget_ColorEdit::set_digits(int x) -{ - spinbutton_R->set_digits(x); - spinbutton_G->set_digits(x); - spinbutton_B->set_digits(x); - spinbutton_A->set_digits(x); - spinbutton_R->set_size_request(SPINBUTTON_WIDTH,-1); - spinbutton_G->set_size_request(SPINBUTTON_WIDTH,-1); - spinbutton_B->set_size_request(SPINBUTTON_WIDTH,-1); - spinbutton_A->set_size_request(SPINBUTTON_WIDTH,-1); -} - -void -Widget_ColorEdit::set_value(const synfig::Color &data) -{ - assert(data.is_valid()); - hold_signals=true; - clamp_=false; - - color=data; - - if(use_colorspace_gamma()) - { - R_adjustment.set_value(gamma_in(color.get_r())*100); - G_adjustment.set_value(gamma_in(color.get_g())*100); - B_adjustment.set_value(gamma_in(color.get_b())*100); - } - else - { - R_adjustment.set_value(color.get_r()*100); - G_adjustment.set_value(color.get_g()*100); - B_adjustment.set_value(color.get_b()*100); - } - A_adjustment.set_value(color.get_a()*100); - - slider_R->set_color(color); - slider_G->set_color(color); - slider_B->set_color(color); - slider_Y->set_color(color); - slider_U->set_color(color); - slider_V->set_color(color); - 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; -} - -synfig::Color -Widget_ColorEdit::get_value_raw() -{ - Color color; - if(use_colorspace_gamma()) - { - color.set_r(gamma_out(R_adjustment.get_value()/100.0f)); - color.set_g(gamma_out(G_adjustment.get_value()/100.0f)); - color.set_b(gamma_out(B_adjustment.get_value()/100.0f)); - } - else - { - color.set_r(R_adjustment.get_value()/100); - color.set_g(G_adjustment.get_value()/100); - color.set_b(B_adjustment.get_value()/100); - } - color.set_a(A_adjustment.get_value()/100); - assert(color.is_valid()); - - return color; -} - -const synfig::Color & -Widget_ColorEdit::get_value() -{ - if(use_colorspace_gamma()) - { - color.set_r(gamma_out(R_adjustment.get_value()/100.0f)); - color.set_g(gamma_out(G_adjustment.get_value()/100.0f)); - color.set_b(gamma_out(B_adjustment.get_value()/100.0f)); - assert(color.is_valid()); - } - else - { - color.set_r(R_adjustment.get_value()/100); - color.set_g(G_adjustment.get_value()/100); - color.set_b(B_adjustment.get_value()/100); - assert(color.is_valid()); - } - color.set_a(A_adjustment.get_value()/100); - assert(color.is_valid()); - - if(notebook->get_current_page()!=0) - color=color.clamped(); - - /*{ - // Clamp out negative values - color.set_r(std::max(0.0f,(float)color.get_r())); - color.set_g(std::max(0.0f,(float)color.get_g())); - color.set_b(std::max(0.0f,(float)color.get_b())); - }*/ - - return color; -} diff --git a/synfig-studio/src/gtkmm/widget_coloredit.h b/synfig-studio/src/gtkmm/widget_coloredit.h deleted file mode 100644 index 63dcfa6..0000000 --- a/synfig-studio/src/gtkmm/widget_coloredit.h +++ /dev/null @@ -1,188 +0,0 @@ -/* === S Y N F I G ========================================================= */ -/*! \file widget_coloredit.h -** \brief Template Header -** -** $Id$ -** -** \legal -** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** \endlegal -*/ -/* ========================================================================= */ - -/* === S T A R T =========================================================== */ - -#ifndef __SYNFIG_STUDIO_WIDGET_COLOREDIT_H -#define __SYNFIG_STUDIO_WIDGET_COLOREDIT_H - -/* === H E A D E R S ======================================================= */ - -#include -#include -#include -#include -#include -#include -#include "widget_color.h" - -/* === M A C R O S ========================================================= */ - -/* === T Y P E D E F S ===================================================== */ - -/* === C L A S S E S & S T R U C T S ======================================= */ - -namespace Gtk { - class Notebook; -}; - -namespace studio { - -class ColorSlider : public Gtk::DrawingArea -{ -public: - enum Type - { - TYPE_R, - TYPE_G, - TYPE_B, - TYPE_Y, - TYPE_U, - TYPE_V, - TYPE_HUE, - TYPE_SAT, - TYPE_A, - - TYPE_END - }; - -private: - - sigc::signal signal_slider_moved_; - sigc::signal signal_activated_; - - Type type; - synfig::Color color_; - -public: - - sigc::signal& signal_slider_moved() { return signal_slider_moved_; } - sigc::signal& signal_activated() { return signal_activated_; } - - Type - get_type()const { return type; } - - const synfig::Color& - get_color()const { return color_; } - - - ColorSlider(const Type &x=TYPE_Y); - - void - set_type(Type x); - - void - set_color(synfig::Color x); - - static void adjust_color(Type type, synfig::Color &color, float amount); - -private: - typedef void (*slider_color_func)(synfig::Color &,float); - - static void slider_color_TYPE_R(synfig::Color &color, float amount); - static void slider_color_TYPE_G(synfig::Color &color, float amount); - static void slider_color_TYPE_B(synfig::Color &color, float amount); - static void slider_color_TYPE_Y(synfig::Color &color, float amount); - static void slider_color_TYPE_U(synfig::Color &color, float amount); - static void slider_color_TYPE_V(synfig::Color &color, float amount); - static void slider_color_TYPE_HUE(synfig::Color &color, float amount); - static void slider_color_TYPE_SAT(synfig::Color &color, float amount); - static void slider_color_TYPE_A(synfig::Color &color, float amount); - - - bool - redraw(GdkEventExpose*bleh); - bool on_event(GdkEvent *event); -}; // END of class ColorSlider - - -class Widget_ColorEdit : public Gtk::Table -{ - sigc::signal signal_activated_; - sigc::signal signal_value_changed_; - - 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; - ColorSlider *slider_V; - ColorSlider *slider_SAT; - ColorSlider *slider_HUE; - - Widget_Color widget_color; - - bool hold_signals; - - bool clamp_; - - Gtk::SpinButton *spinbutton_R; - Gtk::SpinButton *spinbutton_G; - Gtk::SpinButton *spinbutton_B; - Gtk::SpinButton *spinbutton_A; - - Gtk::Adjustment R_adjustment; - Gtk::Adjustment G_adjustment; - Gtk::Adjustment B_adjustment; - Gtk::Adjustment A_adjustment; - - synfig::Color color; - - Gtk::Notebook* notebook; - -protected: - - void on_value_changed(); - -public: - - sigc::signal& signal_activated() { return signal_activated_; } - - sigc::signal& signal_activate() { return signal_activated_; } - - void on_slider_moved(ColorSlider::Type type, float amount); - void on_hex_edited(); - - //Glib::SignalProxy0 signal_activate() { return spinbutton_A->signal_activate(); } - - sigc::signal& signal_value_changed() { return signal_value_changed_; } - - void activated() { signal_activated_(); } - void activate() { signal_activated_(); } - void set_value(const synfig::Color &data); - const synfig::Color &get_value(); - synfig::Color get_value_raw(); - void set_has_frame(bool x); - void set_digits(int x); - Widget_ColorEdit(); - ~Widget_ColorEdit(); -}; // END of class Widget_ColorEdit - -}; // END of namespace studio - -/* === E N D =============================================================== */ - -#endif diff --git a/synfig-studio/src/gtkmm/widget_customcoloredit.cpp b/synfig-studio/src/gtkmm/widget_customcoloredit.cpp new file mode 100644 index 0000000..eef9924 --- /dev/null +++ b/synfig-studio/src/gtkmm/widget_customcoloredit.cpp @@ -0,0 +1,587 @@ +/* === S Y N F I G ========================================================= */ +/*! \file widget_customcoloredit.cpp +** \brief Template File +** +** $Id$ +** +** \legal +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2007 Chris Moore +** Copyright (c) 2008 Paul Wise +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#ifdef USING_PCH +# include "pch.h" +#else +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "widget_customcoloredit.h" +#include +#include "app.h" +#include +#include +#include +#include +#include +#include + +#include "general.h" + +#endif + +/* === U S I N G =========================================================== */ + +using namespace std; +using namespace etl; +using namespace synfig; +using namespace studio; + +/* === M A C R O S ========================================================= */ + +#define SPINBUTTON_WIDTH 100 + +/* === G L O B A L S ======================================================= */ + +/* === P R O C E D U R E S ================================================= */ + +/* === C L A S S E S ======================================================= */ + +ColorSlider::ColorSlider(const ColorSlider::Type &x): + type(x) +{ + signal_expose_event().connect(sigc::mem_fun(*this, &ColorSlider::redraw)); + set_size_request(-1,12); + add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK); + add_events(Gdk::BUTTON1_MOTION_MASK); +} + +void +ColorSlider::set_type(Type x) { type=x; queue_draw(); } + +void +ColorSlider::set_color(synfig::Color x) { color_=x; queue_draw(); } + +void +ColorSlider::slider_color_TYPE_R(synfig::Color &color, float amount) { color.set_r(amount); } +void +ColorSlider::slider_color_TYPE_G(synfig::Color &color, float amount) { color.set_g(amount); } +void +ColorSlider::slider_color_TYPE_B(synfig::Color &color, float amount) { color.set_b(amount); } +void +ColorSlider::slider_color_TYPE_Y(synfig::Color &color, float amount) { color.set_y(amount); } +void +ColorSlider::slider_color_TYPE_U(synfig::Color &color, float amount) { color.set_u(amount-0.5f); } +void +ColorSlider::slider_color_TYPE_V(synfig::Color &color, float amount) { color.set_v(amount-0.5f); } +void +ColorSlider::slider_color_TYPE_HUE(synfig::Color &color, float amount) { color.set_uv_angle(Angle::rot(amount)); } +void +ColorSlider::slider_color_TYPE_SAT(synfig::Color &color, float amount) { color.set_s(amount*0.5f); } +void +ColorSlider::slider_color_TYPE_A(synfig::Color &color, float amount) { color.set_a(amount); } + +void +ColorSlider::adjust_color(Type type, synfig::Color &color, float amount) +{ + static const slider_color_func jump_table[int(TYPE_END)] = + { + slider_color_TYPE_R, + slider_color_TYPE_G, + slider_color_TYPE_B, + slider_color_TYPE_Y, + slider_color_TYPE_U, + slider_color_TYPE_V, + slider_color_TYPE_HUE, + slider_color_TYPE_SAT, + slider_color_TYPE_A, + }; + jump_table[int(type)](color,amount); +} + +bool +ColorSlider::redraw(GdkEventExpose */*bleh*/) +{ + Color color(color_); + + static const slider_color_func jump_table[int(TYPE_END)] = + { + slider_color_TYPE_R, + slider_color_TYPE_G, + slider_color_TYPE_B, + slider_color_TYPE_Y, + slider_color_TYPE_U, + slider_color_TYPE_V, + slider_color_TYPE_HUE, + slider_color_TYPE_SAT, + slider_color_TYPE_A, + }; + + slider_color_func color_func(jump_table[int(type)]); + + float amount; + switch(type) + { + case TYPE_R: amount=color.get_r(); break; + case TYPE_G: amount=color.get_g(); break; + case TYPE_B: amount=color.get_b(); break; + case TYPE_Y: amount=color.get_y(); break; + case TYPE_U: amount=color.get_u()+0.5; break; + case TYPE_V: amount=color.get_v()+0.5; break; + case TYPE_HUE: amount=Angle::rot(color.get_uv_angle()).get(); amount-=floor(amount); break; + case TYPE_SAT: amount=color.get_s()*2.0; break; + case TYPE_A: amount=color.get_a(); break; + default: amount=0; break; + } + if(use_colorspace_gamma() && (type gc(Gdk::GC::create(get_window())); + const Color bg1(0.75, 0.75, 0.75); + const Color bg2(0.5, 0.5, 0.5); + int i; + for(i=width-1;i>=0;i--) + { + color_func(color, + (use_colorspace_gamma() && typeset_rgb_fg_color(colorconv_synfig2gdk(c1)); + get_window()->draw_rectangle(gc, true, ca.get_x()+i, ca.get_y(), 1, height/2); + + gc->set_rgb_fg_color(colorconv_synfig2gdk(c2)); + get_window()->draw_rectangle(gc, true, ca.get_x()+i, ca.get_y()+height/2, 1, height/2); + } + else + { + gc->set_rgb_fg_color(colorconv_synfig2gdk(c2)); + get_window()->draw_rectangle(gc, true, ca.get_x()+i, ca.get_y(), 1, height/2); + + gc->set_rgb_fg_color(colorconv_synfig2gdk(c1)); + get_window()->draw_rectangle(gc, true, ca.get_x()+i, ca.get_y()+height/2, 1, height/2); + } + } + + get_style()->paint_arrow( + get_window(), + Gtk::STATE_SELECTED, + Gtk::SHADOW_OUT, + ca, + *this, + " ", + Gtk::ARROW_UP, + 1, + int(amount*width)-height/2, + 0, + height, + height + ); + + gc->set_rgb_fg_color(Gdk::Color("#ffffff")); + get_window()->draw_rectangle(gc, false, ca.get_x()+1, ca.get_y()+1, width-3, height-3); + gc->set_rgb_fg_color(Gdk::Color("#000000")); + get_window()->draw_rectangle(gc, false, ca.get_x(), ca.get_y(), width-1, height-1); + return true; +} + +bool +ColorSlider::on_event(GdkEvent *event) +{ + const int width(get_width()); + float x = 0; + if( GDK_SCROLL == event->type ){ + Color color(color_); + float amount; + switch(type) + { + case TYPE_R: amount=color.get_r(); break; + case TYPE_G: amount=color.get_g(); break; + case TYPE_B: amount=color.get_b(); break; + case TYPE_Y: amount=color.get_y(); break; + case TYPE_U: amount=color.get_u()+0.5; break; + case TYPE_V: amount=color.get_v()+0.5; break; + case TYPE_HUE: amount=Angle::rot(color.get_uv_angle()).get(); amount-=floor(amount); break; + case TYPE_SAT: amount=color.get_s()*2.0; break; + case TYPE_A: amount=color.get_a(); break; + default: amount=0; break; + } + if(use_colorspace_gamma() && (typescroll.direction){ + case GDK_SCROLL_UP: + case GDK_SCROLL_RIGHT: + x+=1.0; + break; + case GDK_SCROLL_DOWN: + case GDK_SCROLL_LEFT: + x-=1.0; + break; + } + } else { + x = float(event->button.x); + } + + float pos(x/width); + if(pos<0 || x<=0)pos=0; + if(pos>1)pos=1; + + if(use_colorspace_gamma() && (typebutton.x<=0)pos=0; + if(pos>1)pos=1; + + switch(event->type) + { + case GDK_SCROLL: + signal_slider_moved_(type,pos); + queue_draw(); + signal_activated_(); + return true; + + case GDK_BUTTON_RELEASE: + signal_activated_(); + return true; + + case GDK_BUTTON_PRESS: + case GDK_MOTION_NOTIFY: +// adjust_color(type,color_,pos); + signal_slider_moved_(type,pos); + queue_draw(); + return true; + break; + default: + break; + } + return false; +} + +/* === M E T H O D S ======================================================= */ + +Widget_CustomColorEdit::Widget_CustomColorEdit(): + R_adjustment(0,-10000000,10000000,1,10,0), + G_adjustment(0,-10000000,10000000,1,10,0), + B_adjustment(0,-10000000,10000000,1,10,0), + A_adjustment(0,-10000000,10000000,1,10,0) +{ + notebook=manage(new Gtk::Notebook); + + Gtk::Table* rgb_table(manage(new Gtk::Table())); + Gtk::Table* yuv_table(manage(new Gtk::Table())); + Gtk::Table* main_table(this); + + { + Gtk::VBox* rgb_box(manage(new Gtk::VBox())); + Gtk::VBox* yuv_box(manage(new Gtk::VBox())); + rgb_box->pack_start(*rgb_table,false,false); + yuv_box->pack_start(*yuv_table,false,false); + notebook->append_page(*rgb_box,_("RGB")); + notebook->append_page(*yuv_box,_("YUV")); + } + + color=Color(0,0,0,0); + + set_size_request(200,-1); + hold_signals=true; + + Gtk::Label *label; + + R_adjustment.set_lower(-10000000); + G_adjustment.set_lower(-10000000); + B_adjustment.set_lower(-10000000); + A_adjustment.set_lower(-10000000); + + clamp_=true; + + Pango::AttrList attr_list; + Pango::AttrInt pango_size(Pango::Attribute::create_attr_size(Pango::SCALE*7)); + pango_size.set_start_index(0); + pango_size.set_end_index(64); + attr_list.change(pango_size); + + widget_color.set_size_request(-1,16); + attach(widget_color, 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + attach(*notebook, 0, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); + +#define SLIDER_ROW(i,n,l) \ + slider_##n=manage(new ColorSlider(ColorSlider::TYPE_##n)); \ + slider_##n->signal_slider_moved().connect(sigc::mem_fun(*this,&studio::Widget_CustomColorEdit::on_slider_moved)); \ + /*slider_##n->signal_activated().connect(sigc::mem_fun(*this,&studio::Widget_CustomColorEdit::activated));*/ \ + slider_##n->signal_activated().connect(sigc::mem_fun(*this,&studio::Widget_CustomColorEdit::on_value_changed)); \ + label=manage(new class Gtk::Label(l,0.0,0.5)); \ + label->set_use_markup(false); \ + label->set_use_underline(false); \ + label->set_attributes(attr_list); \ + table->attach(*label, 0, 1, 1+2*i, 2+2*i, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0); \ + table->attach(*slider_##n, 0, 1, 2+2*i, 3+2*i, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0) + +#define ATTACH_SPIN_BUTTON(i,n) \ + spinbutton_##n=manage(new class Gtk::SpinButton(n##_adjustment,1,0)); \ + spinbutton_##n->set_update_policy(Gtk::UPDATE_ALWAYS); \ + spinbutton_##n->set_size_request(SPINBUTTON_WIDTH,-1); \ + spinbutton_##n->show(); \ + table->attach(*spinbutton_##n, 1, 2, 1+2*i, 3+2*i, Gtk::SHRINK, Gtk::EXPAND, 2, 0) + + { + Gtk::Table* table(rgb_table); + SLIDER_ROW(0,R,_("Red")); + ATTACH_SPIN_BUTTON(0,R); + SLIDER_ROW(1,G,_("Green")); + 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_CustomColorEdit::on_hex_edited)); + table->attach(*hex_color, 0, 1, 8, 9, Gtk::SHRINK, Gtk::SHRINK, 0, 0); + } + { + Gtk::Table* table(yuv_table); + SLIDER_ROW(0,Y,_("Luma")); + SLIDER_ROW(1,HUE,_("Hue")); + SLIDER_ROW(2,SAT,_("Saturation")); + SLIDER_ROW(3,U,_("U")); + SLIDER_ROW(4,V,_("V")); + } + { + Gtk::Table* table(main_table); + SLIDER_ROW(1,A,_("Alpha")); + ATTACH_SPIN_BUTTON(1,A); + } + +#undef SLIDER_ROW +#undef ATTACH_SPIN_BUTTON + + spinbutton_R->signal_activate().connect(sigc::mem_fun(*spinbutton_G,&Gtk::SpinButton::grab_focus)); + spinbutton_G->signal_activate().connect(sigc::mem_fun(*spinbutton_B,&Gtk::SpinButton::grab_focus)); + spinbutton_B->signal_activate().connect(sigc::mem_fun(*spinbutton_A,&Gtk::SpinButton::grab_focus)); + spinbutton_A->signal_activate().connect(sigc::mem_fun(*spinbutton_R,&Gtk::SpinButton::grab_focus)); + + R_adjustment.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_CustomColorEdit::on_value_changed)); + G_adjustment.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_CustomColorEdit::on_value_changed)); + B_adjustment.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_CustomColorEdit::on_value_changed)); + A_adjustment.signal_value_changed().connect(sigc::mem_fun(*this,&studio::Widget_CustomColorEdit::on_value_changed)); + + show_all_children(); + + set_digits(1); + set_value(color); + + hold_signals=false; +} + +Widget_CustomColorEdit::~Widget_CustomColorEdit() +{ +} + +void +Widget_CustomColorEdit::on_slider_moved(ColorSlider::Type type, float amount) +{ + Color color(get_value_raw()); + + assert(color.is_valid()); + ColorSlider::adjust_color(type,color,amount); + assert(color.is_valid()); + + // If a non-primary colorslider is adjusted, + // we want to make sure that we clamp + if(type>ColorSlider::TYPE_B && (color.get_r()<0 ||color.get_g()<0 ||color.get_b()<0)) + clamp_=true; + + /* + if(type==ColorSlider::TYPE_R && color.get_r()<0)clamp_=false; + if(type==ColorSlider::TYPE_G && color.get_g()<0)clamp_=false; + if(type==ColorSlider::TYPE_B && color.get_b()<0)clamp_=false; + */ + clamp_=false; + + set_value(color); + assert(color.is_valid()); +} + +void +Widget_CustomColorEdit::on_hex_edited() +{ + Color color(get_value_raw()); + String s = hex_color->get_text(); + color.set_hex(s); + set_value(color); + signal_value_changed_(); +} + +void +Widget_CustomColorEdit::on_value_changed() +{ + if(hold_signals) + return; + + const Color color(get_value_raw()); + assert(color.is_valid()); + slider_R->set_color(color); + slider_G->set_color(color); + slider_B->set_color(color); + slider_Y->set_color(color); + slider_U->set_color(color); + slider_V->set_color(color); + 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(); + signal_value_changed_(); +} + +void +Widget_CustomColorEdit::set_has_frame(bool x) +{ + spinbutton_R->set_has_frame(x); + spinbutton_G->set_has_frame(x); + spinbutton_B->set_has_frame(x); + spinbutton_A->set_has_frame(x); + spinbutton_R->set_size_request(SPINBUTTON_WIDTH,-1); + spinbutton_G->set_size_request(SPINBUTTON_WIDTH,-1); + spinbutton_B->set_size_request(SPINBUTTON_WIDTH,-1); + spinbutton_A->set_size_request(SPINBUTTON_WIDTH,-1); +} + +void +Widget_CustomColorEdit::set_digits(int x) +{ + spinbutton_R->set_digits(x); + spinbutton_G->set_digits(x); + spinbutton_B->set_digits(x); + spinbutton_A->set_digits(x); + spinbutton_R->set_size_request(SPINBUTTON_WIDTH,-1); + spinbutton_G->set_size_request(SPINBUTTON_WIDTH,-1); + spinbutton_B->set_size_request(SPINBUTTON_WIDTH,-1); + spinbutton_A->set_size_request(SPINBUTTON_WIDTH,-1); +} + +void +Widget_CustomColorEdit::set_value(const synfig::Color &data) +{ + assert(data.is_valid()); + hold_signals=true; + clamp_=false; + + color=data; + + if(use_colorspace_gamma()) + { + R_adjustment.set_value(gamma_in(color.get_r())*100); + G_adjustment.set_value(gamma_in(color.get_g())*100); + B_adjustment.set_value(gamma_in(color.get_b())*100); + } + else + { + R_adjustment.set_value(color.get_r()*100); + G_adjustment.set_value(color.get_g()*100); + B_adjustment.set_value(color.get_b()*100); + } + A_adjustment.set_value(color.get_a()*100); + + slider_R->set_color(color); + slider_G->set_color(color); + slider_B->set_color(color); + slider_Y->set_color(color); + slider_U->set_color(color); + slider_V->set_color(color); + 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; +} + +synfig::Color +Widget_CustomColorEdit::get_value_raw() +{ + Color color; + if(use_colorspace_gamma()) + { + color.set_r(gamma_out(R_adjustment.get_value()/100.0f)); + color.set_g(gamma_out(G_adjustment.get_value()/100.0f)); + color.set_b(gamma_out(B_adjustment.get_value()/100.0f)); + } + else + { + color.set_r(R_adjustment.get_value()/100); + color.set_g(G_adjustment.get_value()/100); + color.set_b(B_adjustment.get_value()/100); + } + color.set_a(A_adjustment.get_value()/100); + assert(color.is_valid()); + + return color; +} + +const synfig::Color & +Widget_CustomColorEdit::get_value() +{ + if(use_colorspace_gamma()) + { + color.set_r(gamma_out(R_adjustment.get_value()/100.0f)); + color.set_g(gamma_out(G_adjustment.get_value()/100.0f)); + color.set_b(gamma_out(B_adjustment.get_value()/100.0f)); + assert(color.is_valid()); + } + else + { + color.set_r(R_adjustment.get_value()/100); + color.set_g(G_adjustment.get_value()/100); + color.set_b(B_adjustment.get_value()/100); + assert(color.is_valid()); + } + color.set_a(A_adjustment.get_value()/100); + assert(color.is_valid()); + + if(notebook->get_current_page()!=0) + color=color.clamped(); + + /*{ + // Clamp out negative values + color.set_r(std::max(0.0f,(float)color.get_r())); + color.set_g(std::max(0.0f,(float)color.get_g())); + color.set_b(std::max(0.0f,(float)color.get_b())); + }*/ + + return color; +} diff --git a/synfig-studio/src/gtkmm/widget_customcoloredit.h b/synfig-studio/src/gtkmm/widget_customcoloredit.h new file mode 100644 index 0000000..30f1c47 --- /dev/null +++ b/synfig-studio/src/gtkmm/widget_customcoloredit.h @@ -0,0 +1,188 @@ +/* === S Y N F I G ========================================================= */ +/*! \file widget_customcoloredit.h +** \brief Template Header +** +** $Id$ +** +** \legal +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. +** +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** \endlegal +*/ +/* ========================================================================= */ + +/* === S T A R T =========================================================== */ + +#ifndef __SYNFIG_STUDIO_WIDGET_CUSTOMCOLOREDIT_H +#define __SYNFIG_STUDIO_WIDGET_CUSTOMCOLOREDIT_H + +/* === H E A D E R S ======================================================= */ + +#include +#include +#include +#include +#include +#include +#include "widget_color.h" + +/* === M A C R O S ========================================================= */ + +/* === T Y P E D E F S ===================================================== */ + +/* === C L A S S E S & S T R U C T S ======================================= */ + +namespace Gtk { + class Notebook; +}; + +namespace studio { + +class ColorSlider : public Gtk::DrawingArea +{ +public: + enum Type + { + TYPE_R, + TYPE_G, + TYPE_B, + TYPE_Y, + TYPE_U, + TYPE_V, + TYPE_HUE, + TYPE_SAT, + TYPE_A, + + TYPE_END + }; + +private: + + sigc::signal signal_slider_moved_; + sigc::signal signal_activated_; + + Type type; + synfig::Color color_; + +public: + + sigc::signal& signal_slider_moved() { return signal_slider_moved_; } + sigc::signal& signal_activated() { return signal_activated_; } + + Type + get_type()const { return type; } + + const synfig::Color& + get_color()const { return color_; } + + + ColorSlider(const Type &x=TYPE_Y); + + void + set_type(Type x); + + void + set_color(synfig::Color x); + + static void adjust_color(Type type, synfig::Color &color, float amount); + +private: + typedef void (*slider_color_func)(synfig::Color &,float); + + static void slider_color_TYPE_R(synfig::Color &color, float amount); + static void slider_color_TYPE_G(synfig::Color &color, float amount); + static void slider_color_TYPE_B(synfig::Color &color, float amount); + static void slider_color_TYPE_Y(synfig::Color &color, float amount); + static void slider_color_TYPE_U(synfig::Color &color, float amount); + static void slider_color_TYPE_V(synfig::Color &color, float amount); + static void slider_color_TYPE_HUE(synfig::Color &color, float amount); + static void slider_color_TYPE_SAT(synfig::Color &color, float amount); + static void slider_color_TYPE_A(synfig::Color &color, float amount); + + + bool + redraw(GdkEventExpose*bleh); + bool on_event(GdkEvent *event); +}; // END of class ColorSlider + + +class Widget_CustomColorEdit : public Gtk::Table +{ + sigc::signal signal_activated_; + sigc::signal signal_value_changed_; + + 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; + ColorSlider *slider_V; + ColorSlider *slider_SAT; + ColorSlider *slider_HUE; + + Widget_Color widget_color; + + bool hold_signals; + + bool clamp_; + + Gtk::SpinButton *spinbutton_R; + Gtk::SpinButton *spinbutton_G; + Gtk::SpinButton *spinbutton_B; + Gtk::SpinButton *spinbutton_A; + + Gtk::Adjustment R_adjustment; + Gtk::Adjustment G_adjustment; + Gtk::Adjustment B_adjustment; + Gtk::Adjustment A_adjustment; + + synfig::Color color; + + Gtk::Notebook* notebook; + +protected: + + void on_value_changed(); + +public: + + sigc::signal& signal_activated() { return signal_activated_; } + + sigc::signal& signal_activate() { return signal_activated_; } + + void on_slider_moved(ColorSlider::Type type, float amount); + void on_hex_edited(); + + //Glib::SignalProxy0 signal_activate() { return spinbutton_A->signal_activate(); } + + sigc::signal& signal_value_changed() { return signal_value_changed_; } + + void activated() { signal_activated_(); } + void activate() { signal_activated_(); } + void set_value(const synfig::Color &data); + const synfig::Color &get_value(); + synfig::Color get_value_raw(); + void set_has_frame(bool x); + void set_digits(int x); + Widget_CustomColorEdit(); + ~Widget_CustomColorEdit(); +}; // END of class Widget_CustomColorEdit + +}; // END of namespace studio + +/* === E N D =============================================================== */ + +#endif diff --git a/synfig-studio/src/gtkmm/widget_value.cpp b/synfig-studio/src/gtkmm/widget_value.cpp index c6a8b97..579eaba 100644 --- a/synfig-studio/src/gtkmm/widget_value.cpp +++ b/synfig-studio/src/gtkmm/widget_value.cpp @@ -43,7 +43,7 @@ #include "widget_vector.h" #include "widget_filename.h" #include "widget_enum.h" -#include "widget_coloredit.h" +#include "widget_customcoloredit.h" #include "widget_canvaschooser.h" #include "widget_time.h" #include "app.h" @@ -84,7 +84,7 @@ Widget_ValueBase::Widget_ValueBase(): vector_widget=manage(new class Widget_Vector()); pack_start(*vector_widget); - color_widget=manage(new class Widget_ColorEdit()); + color_widget=manage(new class Widget_CustomColorEdit()); pack_start(*color_widget); enum_widget=manage(new class Widget_Enum()); diff --git a/synfig-studio/src/gtkmm/widget_value.h b/synfig-studio/src/gtkmm/widget_value.h index 99bdf5b..b1391af 100644 --- a/synfig-studio/src/gtkmm/widget_value.h +++ b/synfig-studio/src/gtkmm/widget_value.h @@ -65,7 +65,7 @@ namespace studio { class Widget_Color; -class Widget_ColorEdit; +class Widget_CustomColorEdit; class Widget_CanvasChooser; class Widget_Enum; class Widget_Filename; @@ -88,7 +88,7 @@ class Widget_ValueBase : public Gtk::HBox Gtk::CheckButton *bool_widget; //Gtk::ColorSelection *color_widget; - Widget_ColorEdit *color_widget; + Widget_CustomColorEdit *color_widget; Widget_CanvasChooser *canvas_widget; Widget_Enum *enum_widget; Widget_Filename *filename_widget;