New curve editor, first batch (parametric curves, overlaid histogram in curve area)
This commit is contained in:
@@ -19,55 +19,125 @@
|
||||
#include <curveeditor.h>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <guiutils.h>
|
||||
#include <multilangmgr.h>
|
||||
|
||||
CurveEditor::CurveEditor () {
|
||||
CurveEditor::CurveEditor () : cl(NULL), activeParamControl(-1), realized(false), curveTypeIx(-1) {
|
||||
|
||||
curve = Gtk::manage (new MyCurve ());
|
||||
Gtk::HBox* tsbox = Gtk::manage (new Gtk::HBox ());
|
||||
Gtk::Label* tslab = Gtk::manage (new Gtk::Label ("Type:"));
|
||||
curveType = Gtk::manage (new Gtk::ComboBoxText ());
|
||||
|
||||
tsbox->pack_start (*tslab, Gtk::PACK_SHRINK, 8);
|
||||
tsbox->pack_start (*curveType);
|
||||
|
||||
pack_start (*tsbox);
|
||||
|
||||
curveType->append_text ("Linear");
|
||||
curveType->append_text ("Parametric");
|
||||
curveType->append_text ("Custom");
|
||||
curveType->set_active (0);
|
||||
|
||||
// custom curve
|
||||
customCurveBox = new Gtk::VBox ();
|
||||
customCurve = Gtk::manage (new MyCurve ());
|
||||
Gtk::AspectFrame* af = Gtk::manage (new Gtk::AspectFrame ("",Gtk::ALIGN_CENTER,Gtk::ALIGN_CENTER,1,false));
|
||||
af->add (*curve);
|
||||
curve->set_size_request (-1, 200);
|
||||
pack_start (*af, Gtk::PACK_EXPAND_WIDGET);
|
||||
af->add (*customCurve);
|
||||
customCurve->set_size_request (-1, 200);
|
||||
customCurve->setType (Spline);
|
||||
customCurveBox->pack_start (*af, Gtk::PACK_EXPAND_WIDGET);
|
||||
|
||||
Gtk::HBox* bbox = Gtk::manage (new Gtk::HBox ());
|
||||
|
||||
linear = Gtk::manage (new Gtk::Button (M("CURVEEDITOR_LINEAR")));
|
||||
save = Gtk::manage (new Gtk::Button ());
|
||||
Gtk::Image* saveImg = Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-save"), Gtk::ICON_SIZE_BUTTON));
|
||||
saveImg->show ();
|
||||
save->add (*saveImg);
|
||||
save->add (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-save"), Gtk::ICON_SIZE_BUTTON)));
|
||||
load = Gtk::manage (new Gtk::Button ());
|
||||
Gtk::Image* loadImg = Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-open"), Gtk::ICON_SIZE_BUTTON));
|
||||
loadImg->show ();
|
||||
load->add (*loadImg);
|
||||
load->add (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-open"), Gtk::ICON_SIZE_BUTTON)));
|
||||
|
||||
bbox->pack_start (*linear);
|
||||
bbox->pack_end (*save, Gtk::PACK_SHRINK, 4);
|
||||
bbox->pack_end (*load, Gtk::PACK_SHRINK, 4);
|
||||
bbox->pack_end (*save, Gtk::PACK_EXPAND_WIDGET, 4);
|
||||
bbox->pack_end (*load, Gtk::PACK_EXPAND_WIDGET, 4);
|
||||
|
||||
pack_end (*bbox, Gtk::PACK_SHRINK, 2);
|
||||
show_all ();
|
||||
customCurveBox->pack_end (*bbox, Gtk::PACK_SHRINK, 2);
|
||||
customCurveBox->show_all ();
|
||||
|
||||
linear->signal_clicked().connect( sigc::mem_fun(*this, &CurveEditor::linearPressed) );
|
||||
save->signal_clicked().connect( sigc::mem_fun(*this, &CurveEditor::savePressed) );
|
||||
load->signal_clicked().connect( sigc::mem_fun(*this, &CurveEditor::loadPressed) );
|
||||
|
||||
linear->set_tooltip_text (M("CURVEEDITOR_TOOLTIPLINEAR"));
|
||||
save->set_tooltip_text (M("CURVEEDITOR_TOOLTIPSAVE"));
|
||||
load->set_tooltip_text (M("CURVEEDITOR_TOOLTIPLOAD"));
|
||||
|
||||
// parametric curve
|
||||
paramCurveBox = new Gtk::VBox ();
|
||||
paramCurve = Gtk::manage (new MyCurve ());
|
||||
Gtk::Table* ctab = Gtk::manage (new Gtk::Table (2,1));
|
||||
Gtk::AspectFrame* afp = Gtk::manage (new Gtk::AspectFrame ("",Gtk::ALIGN_CENTER,Gtk::ALIGN_CENTER,1,false));
|
||||
afp->add (*paramCurve);
|
||||
paramCurve->set_size_request (200, 200);
|
||||
paramCurve->setType (Parametric);
|
||||
shcSelector = Gtk::manage (new SHCSelector ());
|
||||
shcSelector->set_size_request (200, 20);
|
||||
|
||||
ctab->attach (*afp, 0, 1, 0, 1, Gtk::FILL, Gtk::SHRINK, 2, 2);
|
||||
ctab->attach (*shcSelector, 0, 1, 1, 2, Gtk::FILL, Gtk::SHRINK, 2, 2);
|
||||
|
||||
Gtk::HBox* tmpb = Gtk::manage (new Gtk::HBox ());
|
||||
tmpb->pack_start (*ctab, true, false);
|
||||
|
||||
paramCurveBox->pack_start (*tmpb, true, true);
|
||||
|
||||
highlights = Gtk::manage (new Adjuster ("Highlights", -100, 100, 1, 0));
|
||||
lights = Gtk::manage (new Adjuster ("Lights", -100, 100, 1, 0));
|
||||
darks = Gtk::manage (new Adjuster ("Darks", -100, 100, 1, 0));
|
||||
shadows = Gtk::manage (new Adjuster ("Shadows", -100, 100, 1, 0));
|
||||
|
||||
Gtk::EventBox* evhighlights = Gtk::manage (new Gtk::EventBox ());
|
||||
Gtk::EventBox* evlights = Gtk::manage (new Gtk::EventBox ());
|
||||
Gtk::EventBox* evdarks = Gtk::manage (new Gtk::EventBox ());
|
||||
Gtk::EventBox* evshadows = Gtk::manage (new Gtk::EventBox ());
|
||||
|
||||
evhighlights->add (*highlights);
|
||||
evlights->add (*lights);
|
||||
evdarks->add (*darks);
|
||||
evshadows->add (*shadows);
|
||||
|
||||
paramCurveBox->pack_start (*Gtk::manage (new Gtk::HSeparator ()));
|
||||
paramCurveBox->pack_start (*evhighlights);
|
||||
paramCurveBox->pack_start (*evlights);
|
||||
paramCurveBox->pack_start (*evdarks);
|
||||
paramCurveBox->pack_start (*evshadows);
|
||||
paramCurveBox->show_all ();
|
||||
|
||||
customCurveBox->reference ();
|
||||
paramCurveBox->reference ();
|
||||
|
||||
customCurve->setCurveListener (this);
|
||||
paramCurve->setCurveListener (this);
|
||||
shcSelector->setSHCListener (this);
|
||||
|
||||
highlights->setAdjusterListener (this);
|
||||
lights->setAdjusterListener (this);
|
||||
darks->setAdjusterListener (this);
|
||||
shadows->setAdjusterListener (this);
|
||||
|
||||
evhighlights->set_events(Gdk::ENTER_NOTIFY_MASK | Gdk::LEAVE_NOTIFY_MASK);
|
||||
evlights->set_events(Gdk::ENTER_NOTIFY_MASK | Gdk::LEAVE_NOTIFY_MASK);
|
||||
evdarks->set_events(Gdk::ENTER_NOTIFY_MASK | Gdk::LEAVE_NOTIFY_MASK);
|
||||
evshadows->set_events(Gdk::ENTER_NOTIFY_MASK | Gdk::LEAVE_NOTIFY_MASK);
|
||||
typeconn = curveType->signal_changed().connect (sigc::mem_fun(*this, &CurveEditor::typeSelectionChanged) );
|
||||
evhighlights->signal_enter_notify_event().connect (sigc::bind(sigc::mem_fun(*this, &CurveEditor::adjusterEntered), 4));
|
||||
evlights->signal_enter_notify_event().connect (sigc::bind(sigc::mem_fun(*this, &CurveEditor::adjusterEntered), 5));
|
||||
evdarks->signal_enter_notify_event().connect (sigc::bind(sigc::mem_fun(*this, &CurveEditor::adjusterEntered), 6));
|
||||
evshadows->signal_enter_notify_event().connect (sigc::bind(sigc::mem_fun(*this, &CurveEditor::adjusterEntered), 7));
|
||||
evhighlights->signal_leave_notify_event().connect (sigc::bind(sigc::mem_fun(*this, &CurveEditor::adjusterLeft), 4));
|
||||
evlights->signal_leave_notify_event().connect (sigc::bind(sigc::mem_fun(*this, &CurveEditor::adjusterLeft), 5));
|
||||
evdarks->signal_leave_notify_event().connect (sigc::bind(sigc::mem_fun(*this, &CurveEditor::adjusterLeft), 6));
|
||||
evshadows->signal_leave_notify_event().connect (sigc::bind(sigc::mem_fun(*this, &CurveEditor::adjusterLeft), 7));
|
||||
|
||||
show_all ();
|
||||
}
|
||||
|
||||
void CurveEditor::linearPressed () {
|
||||
CurveEditor::~CurveEditor () {
|
||||
|
||||
std::vector<double> lcurve (5);
|
||||
lcurve[0] = 1.0;
|
||||
lcurve[1] = 0.0;
|
||||
lcurve[2] = 0.0;
|
||||
lcurve[3] = 1.0;
|
||||
lcurve[4] = 1.0;
|
||||
curve->setPoints (lcurve);
|
||||
curve->queue_draw ();
|
||||
curve->notifyListener ();
|
||||
delete customCurveBox;
|
||||
delete paramCurveBox;
|
||||
}
|
||||
|
||||
void CurveEditor::savePressed () {
|
||||
@@ -99,18 +169,7 @@ void CurveEditor::savePressed () {
|
||||
|
||||
std::string fname = dialog.get_filename();
|
||||
|
||||
bool hasext = true;
|
||||
int dotpos = fname.find_last_of ('.');
|
||||
if (dotpos==Glib::ustring::npos)
|
||||
hasext = false;
|
||||
int dirpos1 = fname.find_last_of ('/');
|
||||
if (dirpos1!=Glib::ustring::npos || dirpos1>dotpos)
|
||||
hasext = false;
|
||||
int dirpos2 = fname.find_last_of ('\\');
|
||||
if (dirpos2!=Glib::ustring::npos || dirpos2>dotpos)
|
||||
hasext = false;
|
||||
|
||||
if (!hasext)
|
||||
if (getExtension (fname)!="rtc")
|
||||
fname = fname + ".rtc";
|
||||
|
||||
if (Glib::file_test (fname, Glib::FILE_TEST_EXISTS)) {
|
||||
@@ -122,7 +181,7 @@ void CurveEditor::savePressed () {
|
||||
}
|
||||
|
||||
std::ofstream f (fname.c_str());
|
||||
std::vector<double> p = curve->getPoints ();
|
||||
std::vector<double> p = customCurve->getPoints ();
|
||||
int ix = 0;
|
||||
if (p[ix++]<0)
|
||||
f << "Linear\n";
|
||||
@@ -170,25 +229,165 @@ void CurveEditor::loadPressed () {
|
||||
if (f)
|
||||
p.push_back (x);
|
||||
}
|
||||
curve->setPoints (p);
|
||||
curve->queue_draw ();
|
||||
curve->notifyListener ();
|
||||
customCurve->setPoints (p);
|
||||
customCurve->queue_draw ();
|
||||
customCurve->notifyListener ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CurveEditor::on_realize () {
|
||||
|
||||
Gtk::VBox::on_realize();
|
||||
realized = true;
|
||||
setCurve (tmpCurve);
|
||||
}
|
||||
|
||||
void CurveEditor::setCurve (const std::vector<double>& c) {
|
||||
|
||||
if (c.size()>4) {
|
||||
curve->setPoints (c);
|
||||
curve->queue_draw ();
|
||||
tmpCurve = c;
|
||||
|
||||
if (realized && curveType->get_active_row_number()<3) { // if it is not realized or "unchanged" is selected, just store the curve (prev line) and do not change gui
|
||||
|
||||
typeconn.block(true);
|
||||
if (c.size()==0 || c[0]==0) {
|
||||
curveType->set_active (0);
|
||||
curveTypeIx = 0;
|
||||
}
|
||||
else if (c[0]==1) {
|
||||
curveType->set_active (2);
|
||||
curveTypeIx = 2;
|
||||
customCurve->setPoints (c);
|
||||
}
|
||||
else if (c[0]==2) {
|
||||
curveType->set_active (1);
|
||||
curveTypeIx = 1;
|
||||
paramCurve->setPoints (c);
|
||||
shcSelector->setPositions (c[1], c[2], c[3]);
|
||||
highlights->setValue (c[4]);
|
||||
lights->setValue (c[5]);
|
||||
darks->setValue (c[6]);
|
||||
shadows->setValue (c[7]);
|
||||
}
|
||||
removeIfThere (this, customCurveBox, false);
|
||||
removeIfThere (this, paramCurveBox, false);
|
||||
|
||||
if (curveType->get_active_row_number()==1)
|
||||
pack_start (*paramCurveBox);
|
||||
else if (curveType->get_active_row_number()==2)
|
||||
pack_start (*customCurveBox);
|
||||
|
||||
typeconn.block(false);
|
||||
}
|
||||
else
|
||||
linearPressed ();
|
||||
}
|
||||
|
||||
std::vector<double> CurveEditor::getCurve () {
|
||||
|
||||
return curve->getPoints ();
|
||||
if (!realized || curveType->get_active_row_number()==3)
|
||||
return tmpCurve;
|
||||
|
||||
if (curveTypeIx<=0) {
|
||||
std::vector<double> lcurve (1);
|
||||
lcurve[0] = 0.0;
|
||||
return lcurve;
|
||||
}
|
||||
else if (curveTypeIx==1) {
|
||||
std::vector<double> lcurve (8);
|
||||
lcurve[0] = 2.0;
|
||||
shcSelector->getPositions (lcurve[1], lcurve[2], lcurve[3]);
|
||||
lcurve[4] = highlights->getValue ();
|
||||
lcurve[5] = lights->getValue ();
|
||||
lcurve[6] = darks->getValue ();
|
||||
lcurve[7] = shadows->getValue ();
|
||||
return lcurve;
|
||||
}
|
||||
else if (curveTypeIx==2)
|
||||
return customCurve->getPoints ();
|
||||
}
|
||||
|
||||
void CurveEditor::typeSelectionChanged () {
|
||||
|
||||
removeIfThere (this, customCurveBox, false);
|
||||
removeIfThere (this, paramCurveBox, false);
|
||||
|
||||
if (curveType->get_active_row_number()==1)
|
||||
pack_start (*paramCurveBox);
|
||||
else if (curveType->get_active_row_number()==2)
|
||||
pack_start (*customCurveBox);
|
||||
|
||||
if (curveType->get_active_row_number()<3)
|
||||
curveTypeIx = curveType->get_active_row_number();
|
||||
|
||||
curveChanged ();
|
||||
}
|
||||
|
||||
void CurveEditor::curveChanged () {
|
||||
|
||||
if (cl)
|
||||
cl->curveChanged ();
|
||||
}
|
||||
|
||||
void CurveEditor::shcChanged () {
|
||||
|
||||
paramCurve->setPoints (getCurve());
|
||||
if (cl)
|
||||
cl->curveChanged ();
|
||||
}
|
||||
|
||||
void CurveEditor::adjusterChanged (Adjuster* a, double newval) {
|
||||
|
||||
paramCurve->setPoints (getCurve());
|
||||
if (cl)
|
||||
cl->curveChanged ();
|
||||
}
|
||||
|
||||
bool CurveEditor::adjusterEntered (GdkEventCrossing* ev, int ac) {
|
||||
|
||||
if (ev->detail != GDK_NOTIFY_INFERIOR) {
|
||||
activeParamControl = ac;
|
||||
paramCurve->setActiveParam (activeParamControl);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CurveEditor::adjusterLeft (GdkEventCrossing* ev, int ac) {
|
||||
|
||||
if (ev->detail != GDK_NOTIFY_INFERIOR) {
|
||||
activeParamControl = -1;
|
||||
paramCurve->setActiveParam (activeParamControl);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CurveEditor::setBatchMode (bool batchMode) {
|
||||
|
||||
curveType->append_text ("(Unchanged)");
|
||||
}
|
||||
|
||||
bool CurveEditor::isUnChanged () {
|
||||
|
||||
return curveType->get_active_row_number()==3;
|
||||
}
|
||||
|
||||
void CurveEditor::setUnChanged (bool uc) {
|
||||
|
||||
if (uc) {
|
||||
typeconn.block(true);
|
||||
removeIfThere (this, customCurveBox, false);
|
||||
removeIfThere (this, paramCurveBox, false);
|
||||
curveType->set_active (3);
|
||||
typeconn.block(false);
|
||||
}
|
||||
else {
|
||||
typeconn.block(true);
|
||||
curveType->set_active (-1); // hack: if it remains 3 (unchanged), then setcurve does not switch selection in the combo
|
||||
setCurve (getCurve ());
|
||||
typeconn.block(false);
|
||||
}
|
||||
}
|
||||
|
||||
void CurveEditor::updateBackgroundHistogram (unsigned int* hist) {
|
||||
|
||||
paramCurve->updateBackgroundHistogram (hist);
|
||||
customCurve->updateBackgroundHistogram (hist);
|
||||
}
|
||||
|
Reference in New Issue
Block a user