Flat curve editor widget, HSV tool modified to use it.

Usage :
 - click & drag a control point to move it in X&Y direction
 - click & drag a vertical line to move it in horizontal or vertical direction (the very first move will be used to determine the motion direction)
 - click & drag the yellow or blue square handle to modify the tangent of the same color
This commit is contained in:
Hombre
2011-03-24 00:39:48 +01:00
parent e57a56b40f
commit eb4b2d8781
44 changed files with 4778 additions and 2136 deletions

View File

@@ -18,6 +18,7 @@
*/
#include <hsvequalizer.h>
#include <utils.h>
using namespace rtengine;
using namespace rtengine::procparams;
@@ -26,196 +27,61 @@ using namespace rtengine::procparams;
HSVEqualizer::HSVEqualizer () : Gtk::VBox(), FoldableToolPanel(this) {
enabled = Gtk::manage (new Gtk::CheckButton (M("GENERAL_ENABLED")));
enabled->set_active (true);
pack_start(*enabled);
enaConn = enabled->signal_toggled().connect( sigc::mem_fun(*this, &HSVEqualizer::enabledToggled) );
Gtk::HSeparator *hsvsepa = Gtk::manage (new Gtk::HSeparator());
pack_start(*hsvsepa, Gtk::PACK_SHRINK, 2);
hsvsepa->show ();
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Gtk::HBox* hb = Gtk::manage (new Gtk::HBox ());
hb->set_border_width (4);
hb->show ();
Gtk::Label* hsvselect = Gtk::manage (new Gtk::Label (M("TP_HSVEQUALIZER_CHANNEL")+":"));
hsvselect->show ();
hsvchannel = Gtk::manage (new Gtk::ComboBoxText ());
hsvchannel->append_text (M("TP_HSVEQUALIZER_SAT"));
hsvchannel->append_text (M("TP_HSVEQUALIZER_VAL"));
hsvchannel->append_text (M("TP_HSVEQUALIZER_HUE"));
hsvchannel->show ();
hb->pack_start(*hsvselect, Gtk::PACK_SHRINK, 4);
hb->pack_start(*hsvchannel);
Gtk::Button * neutralButton = Gtk::manage (new Gtk::Button(M("TP_HSVEQUALIZER_NEUTRAL")));
hb->pack_start(*neutralButton, Gtk::PACK_SHRINK, 2);
neutralPressedConn = neutralButton->signal_pressed().connect( sigc::mem_fun(*this, &HSVEqualizer::neutralPressed));
pack_start (*hb);
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
/*
Gtk::HBox * buttonBox17 = Gtk::manage (new Gtk::HBox());
pack_start(*buttonBox17, Gtk::PACK_SHRINK, 2);
Gtk::Button * neutralButton = Gtk::manage (new Gtk::Button(M("TP_HSVEQUALIZER_NEUTRAL")));
buttonBox17->pack_start(*neutralButton, Gtk::PACK_SHRINK, 2);
neutralPressedConn = neutralButton->signal_pressed().connect( sigc::mem_fun(*this, &HSVEqualizer::neutralPressed));
buttonBox17->show();
*/
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Gtk::HSeparator *hsvsepb = Gtk::manage (new Gtk::HSeparator());
pack_start(*hsvsepb, Gtk::PACK_SHRINK, 2);
hsvsepb->show ();
satbox = new Gtk::VBox ();
sat[0] = new Adjuster (M("TP_HSVEQUALIZER1"), -100, 100, 1, 0);
sat[1] = new Adjuster (M("TP_HSVEQUALIZER2"), -100, 100, 1, 0);
sat[2] = new Adjuster (M("TP_HSVEQUALIZER3"), -100, 100, 1, 0);
sat[3] = new Adjuster (M("TP_HSVEQUALIZER4"), -100, 100, 1, 0);
sat[4] = new Adjuster (M("TP_HSVEQUALIZER5"), -100, 100, 1, 0);
sat[5] = new Adjuster (M("TP_HSVEQUALIZER6"), -100, 100, 1, 0);
sat[6] = new Adjuster (M("TP_HSVEQUALIZER7"), -100, 100, 1, 0);
sat[7] = new Adjuster (M("TP_HSVEQUALIZER8"), -100, 100, 1, 0);
for(int i = 0; i < 8; i++)
{
sat[i]->setAdjusterListener(this);
satbox->pack_start(*sat[i]);
}
//show_all_children ();
satbox->show ();
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%
valbox = new Gtk::VBox ();
val[0] = new Adjuster (M("TP_HSVEQUALIZER1"), -100, 100, 1, 0);
val[1] = new Adjuster (M("TP_HSVEQUALIZER2"), -100, 100, 1, 0);
val[2] = new Adjuster (M("TP_HSVEQUALIZER3"), -100, 100, 1, 0);
val[3] = new Adjuster (M("TP_HSVEQUALIZER4"), -100, 100, 1, 0);
val[4] = new Adjuster (M("TP_HSVEQUALIZER5"), -100, 100, 1, 0);
val[5] = new Adjuster (M("TP_HSVEQUALIZER6"), -100, 100, 1, 0);
val[6] = new Adjuster (M("TP_HSVEQUALIZER7"), -100, 100, 1, 0);
val[7] = new Adjuster (M("TP_HSVEQUALIZER8"), -100, 100, 1, 0);
for(int i = 0; i < 8; i++)
{
val[i]->setAdjusterListener(this);
valbox->pack_start(*val[i]);
}
//show_all_children ();
valbox->show ();
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%
huebox = new Gtk::VBox ();
hue[0] = new Adjuster (M("TP_HSVEQUALIZER1"), -100, 100, 1, 0);
hue[1] = new Adjuster (M("TP_HSVEQUALIZER2"), -100, 100, 1, 0);
hue[2] = new Adjuster (M("TP_HSVEQUALIZER3"), -100, 100, 1, 0);
hue[3] = new Adjuster (M("TP_HSVEQUALIZER4"), -100, 100, 1, 0);
hue[4] = new Adjuster (M("TP_HSVEQUALIZER5"), -100, 100, 1, 0);
hue[5] = new Adjuster (M("TP_HSVEQUALIZER6"), -100, 100, 1, 0);
hue[6] = new Adjuster (M("TP_HSVEQUALIZER7"), -100, 100, 1, 0);
hue[7] = new Adjuster (M("TP_HSVEQUALIZER8"), -100, 100, 1, 0);
for(int i = 0; i < 8; i++)
{
hue[i]->setAdjusterListener(this);
huebox->pack_start(*hue[i]);
}
//huebox->show_all_children ();
huebox->show ();
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%
huebox->reference ();
valbox->reference ();
satbox->reference ();
//enaConn = enabled->signal_toggled().connect( sigc::mem_fun(*this, &HSVEqualizer::enabled_toggled) );
hsvchannel->signal_changed().connect( sigc::mem_fun(*this, &HSVEqualizer::hsvchannelChanged) );
curveEditorG = new CurveEditorGroup (M("TP_HSVEQUALIZER_CHANNEL"));
curveEditorG->setCurveListener (this);
curveEditorG->setColorProvider (this);
hshape = (FlatCurveEditor*)curveEditorG->addCurve(CT_Flat, M("TP_HSVEQUALIZER_HUE"));
sshape = (FlatCurveEditor*)curveEditorG->addCurve(CT_Flat, M("TP_HSVEQUALIZER_SAT"));
vshape = (FlatCurveEditor*)curveEditorG->addCurve(CT_Flat, M("TP_HSVEQUALIZER_VAL"));
// This will add the reset button at the end of the curveType buttons
curveEditorG->curveListComplete();
pack_start (*curveEditorG, Gtk::PACK_SHRINK, 4);
//curveEditorG->show();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
HSVEqualizer::~HSVEqualizer () {
for (int i=0;i<8;i++)
{
delete hue[i];
delete val[i];
delete sat[i];
}
delete curveEditorG;
}
void HSVEqualizer::read (const ProcParams* pp, const ParamsEdited* pedited) {
disableListener ();
if (pedited) {
for (int i=0; i<8; i++) {
sat[i]->setEditedState (pedited->hsvequalizer.sat[i] ? Edited : UnEdited);
val[i]->setEditedState (pedited->hsvequalizer.val[i] ? Edited : UnEdited);
hue[i]->setEditedState (pedited->hsvequalizer.hue[i] ? Edited : UnEdited);
}
enabled->set_inconsistent (!pedited->hsvequalizer.enabled);
hshape->setUnChanged (!pedited->hsvequalizer.hcurve);
sshape->setUnChanged (!pedited->hsvequalizer.scurve);
vshape->setUnChanged (!pedited->hsvequalizer.vcurve);
}
enaConn.block (true);
enabled->set_active (pp->hsvequalizer.enabled);
enaConn.block (false);
lastEnabled = pp->hsvequalizer.enabled;
for (int i=0; i<8; i++) {
sat[i]->setValue (pp->hsvequalizer.sat[i]);
val[i]->setValue (pp->hsvequalizer.val[i]);
hue[i]->setValue (pp->hsvequalizer.hue[i]);
}
if (pedited && !pedited->hsvequalizer.hsvchannel)
hsvchannel->set_active (3);
else if (pp->hsvequalizer.hsvchannel=="sat")
hsvchannel->set_active (0);
else if (pp->hsvequalizer.hsvchannel=="val")
hsvchannel->set_active (1);
else if (pp->hsvequalizer.hsvchannel=="hue")
hsvchannel->set_active (2);
hshape->setCurve (pp->hsvequalizer.hcurve);
sshape->setCurve (pp->hsvequalizer.scurve);
vshape->setCurve (pp->hsvequalizer.vcurve);
enableListener ();
}
void HSVEqualizer::write (ProcParams* pp, ParamsEdited* pedited) {
pp->hsvequalizer.enabled = enabled->get_active ();
for (int i=0; i<8; i++) {
pp->hsvequalizer.sat[i] = sat[i]->getValue();
pp->hsvequalizer.val[i] = val[i]->getValue();
pp->hsvequalizer.hue[i] = hue[i]->getValue();
}
if (hsvchannel->get_active_row_number()==0)
pp->hsvequalizer.hsvchannel = "sat";
else if (hsvchannel->get_active_row_number()==1)
pp->hsvequalizer.hsvchannel = "val";
else if (hsvchannel->get_active_row_number()==2)
pp->hsvequalizer.hsvchannel = "hue";
pp->hsvequalizer.hcurve = hshape->getCurve ();
pp->hsvequalizer.scurve = sshape->getCurve ();
pp->hsvequalizer.vcurve = vshape->getCurve ();
if (pedited) {
pedited->hsvequalizer.enabled = !enabled->get_inconsistent();//from dirpyreq
for (int i=0; i<8; i++) {
pedited->hsvequalizer.sat[i] = sat[i]->getEditedState ();
pedited->hsvequalizer.val[i] = val[i]->getEditedState ();
pedited->hsvequalizer.hue[i] = hue[i]->getEditedState ();
}
pedited->hsvequalizer.hcurve = !hshape->isUnChanged ();
pedited->hsvequalizer.scurve = !sshape->isUnChanged ();
pedited->hsvequalizer.vcurve = !vshape->isUnChanged ();
}
}
/*
void HSVEqualizer::setDefaults (const ProcParams* defParams, const ParamsEdited* pedited) {
for (int i = 0; i < 8; i++) {
@@ -239,7 +105,27 @@ void HSVEqualizer::setDefaults (const ProcParams* defParams, const ParamsEdited*
}
}
}
*/
/*
* Curve listener
*
* If more than one curve has been added, the curve listener is automatically
* set to 'multi=true', and send a pointer of the modified curve in a parameter
*/
void HSVEqualizer::curveChanged (CurveEditor* ce) {
if (listener) {
if (ce == hshape)
listener->panelChanged (EvHSVEqualizerH, M("HISTORY_CUSTOMCURVE"));
if (ce == sshape)
listener->panelChanged (EvHSVEqualizerS, M("HISTORY_CUSTOMCURVE"));
if (ce == vshape)
listener->panelChanged (EvHSVEqualizerV, M("HISTORY_CUSTOMCURVE"));
}
}
/*
void HSVEqualizer::adjusterChanged (Adjuster* a, double newval) {
if (listener && enabled->get_active()) {
@@ -289,75 +175,47 @@ void HSVEqualizer::adjusterChanged (Adjuster* a, double newval) {
//listener->panelChanged (EvHSVEqualizer, ss.str());
}
}
*/
void HSVEqualizer::enabledToggled () {
if (batchMode) {
if (enabled->get_inconsistent()) {
enabled->set_inconsistent (false);
enaConn.block (true);
enabled->set_active (false);
enaConn.block (false);
}
else if (lastEnabled)
enabled->set_inconsistent (true);
lastEnabled = enabled->get_active ();
void HSVEqualizer::colorForValue (double valX, double valY) {
float r, g, b;
CurveEditor* ce = curveEditorG->getDisplayedCurve();
if (ce == hshape) { // Hue = f(Hue)
float h = (float)((valY - 0.5) * 2. + valX);
if (h > 1.0)
h -= 1.0;
else if (h < 0.0)
h += 1.0;
hsv2rgb(h, (float)0.5, (float)0.5, r, g, b);
red = (double)r;
green = (double)g;
blue = (double)b;
}
if (listener) {
if (enabled->get_active ())
listener->panelChanged (EvHSVEqEnabled, M("GENERAL_ENABLED"));
else
listener->panelChanged (EvHSVEqEnabled, M("GENERAL_DISABLED"));
else if (ce == sshape) { // Saturation = f(Hue)
hsv2rgb((float)valX, (float)valY, (float)0.5, r, g, b);
red = (double)r;
green = (double)g;
blue = (double)b;
}
else if (ce == vshape) { // Value = f(Hue)
hsv2rgb((float)valX, (float)0.5, (float)valY, r, g, b);
red = (double)r;
green = (double)g;
blue = (double)b;
}
else {
printf("Error: no curve displayed!\n");
}
}
void HSVEqualizer::hsvchannelChanged () {
removeIfThere (this, satbox, false);
removeIfThere (this, valbox, false);
removeIfThere (this, huebox, false);
if (hsvchannel->get_active_row_number()==0)
pack_start (*satbox);
else if (hsvchannel->get_active_row_number()==1)
pack_start (*valbox);
else if (hsvchannel->get_active_row_number()==2)
pack_start (*huebox);
}
void HSVEqualizer::setBatchMode (bool batchMode) {
ToolPanel::setBatchMode (batchMode);
for (int i = 0; i < 8; i++) {
sat[i]->showEditedCB();
val[i]->showEditedCB();
hue[i]->showEditedCB();
}
hsvchannel->append_text (M("GENERAL_UNCHANGED"));
}
ToolPanel::setBatchMode (batchMode);
void HSVEqualizer::neutralPressed () {
if (hsvchannel->get_active_row_number()==0)
for (int i = 0; i < 8; i++) {
sat[i]->setValue(0);
adjusterChanged(sat[i], 0);
}
else if (hsvchannel->get_active_row_number()==1)
for (int i = 0; i < 8; i++) {
val[i]->setValue(0);
adjusterChanged(val[i], 0);
}
else if (hsvchannel->get_active_row_number()==2)
for (int i = 0; i < 8; i++) {
hue[i]->setValue(0);
adjusterChanged(hue[i], 0);
}
curveEditorG->setBatchMode (batchMode);
}