Cosmetic of the parametric curve editor + reset button added for the curves

This commit is contained in:
Hombre
2010-07-07 10:51:30 +02:00
parent 757fa3b54e
commit d95cf20c98
6 changed files with 78 additions and 10 deletions

View File

@@ -22,14 +22,22 @@
#include <guiutils.h> #include <guiutils.h>
#include <multilangmgr.h> #include <multilangmgr.h>
extern Glib::ustring argv0;
CurveEditor::CurveEditor () : cl(NULL), activeParamControl(-1), realized(false), curveTypeIx(-1) { CurveEditor::CurveEditor () : cl(NULL), activeParamControl(-1), realized(false), curveTypeIx(-1) {
Gtk::HBox* tsbox = Gtk::manage (new Gtk::HBox ()); Gtk::HBox* tsbox = Gtk::manage (new Gtk::HBox ());
Gtk::Label* tslab = Gtk::manage (new Gtk::Label (M("CURVEEDITOR_TYPE"))); Gtk::Label* tslab = Gtk::manage (new Gtk::Label (M("CURVEEDITOR_TYPE")));
curveType = Gtk::manage (new Gtk::ComboBoxText ()); curveType = Gtk::manage (new Gtk::ComboBoxText ());
curve_reset = Gtk::manage (new Gtk::Button ());
curve_reset->add (*Gtk::manage (new Gtk::Image (argv0+"/images/undo.png")));
curve_reset->set_relief (Gtk::RELIEF_NONE);
curve_reset->set_border_width (0);
curve_reset->set_tooltip_text (M("CURVEEDITOR_TOOLTIPLINEAR"));
tsbox->pack_start (*tslab, Gtk::PACK_SHRINK, 8); tsbox->pack_start (*tslab, Gtk::PACK_SHRINK, 8);
tsbox->pack_start (*curveType); tsbox->pack_start (*curveType);
tsbox->pack_start (*curve_reset, Gtk::PACK_SHRINK, 0);
pack_start (*tsbox); pack_start (*tsbox);
@@ -37,7 +45,9 @@ CurveEditor::CurveEditor () : cl(NULL), activeParamControl(-1), realized(false),
curveType->append_text (M("CURVEEDITOR_PARAMETRIC")); curveType->append_text (M("CURVEEDITOR_PARAMETRIC"));
curveType->append_text (M("CURVEEDITOR_CUSTOM")); curveType->append_text (M("CURVEEDITOR_CUSTOM"));
curveType->set_active (0); curveType->set_active (0);
curve_reset->signal_clicked().connect( sigc::mem_fun(*this, &CurveEditor::curveResetPressed) );
// custom curve // custom curve
customCurveBox = new Gtk::VBox (); customCurveBox = new Gtk::VBox ();
Gtk::HBox* tmpa = Gtk::manage (new Gtk::HBox ()); Gtk::HBox* tmpa = Gtk::manage (new Gtk::HBox ());
@@ -47,16 +57,16 @@ CurveEditor::CurveEditor () : cl(NULL), activeParamControl(-1), realized(false),
//af->add (*customCurve); //af->add (*customCurve);
customCurve->set_size_request (GRAPH_SIZE+2*RADIUS, GRAPH_SIZE+2*RADIUS); customCurve->set_size_request (GRAPH_SIZE+2*RADIUS, GRAPH_SIZE+2*RADIUS);
customCurve->setType (Spline); customCurve->setType (Spline);
//customCurve->set_tooltip_text (M("CURVEEDITOR_TOOLTIPMOVESPEED"));
tmpa->pack_start (*customCurve, true, false, 4); tmpa->pack_start (*customCurve, true, false, 4);
customCurveBox->pack_start (*tmpa, true, true,4); customCurveBox->pack_start (*tmpa, true, true,4);
//customCurveBox->set_size_request (0, -1);
Gtk::HBox* bbox = Gtk::manage (new Gtk::HBox ()); Gtk::HBox* bbox = Gtk::manage (new Gtk::HBox ());
save = Gtk::manage (new Gtk::Button ()); save = Gtk::manage (new Gtk::Button ());
save->add (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-save"), Gtk::ICON_SIZE_BUTTON))); save->add (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-save"), Gtk::ICON_SIZE_BUTTON)));
load = Gtk::manage (new Gtk::Button ()); load = Gtk::manage (new Gtk::Button ());
load->add (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-open"), Gtk::ICON_SIZE_BUTTON))); load->add (*Gtk::manage (new Gtk::Image (Gtk::StockID("gtk-open"), Gtk::ICON_SIZE_BUTTON)));
bbox->pack_end (*save, Gtk::PACK_EXPAND_WIDGET, 4); bbox->pack_end (*save, Gtk::PACK_EXPAND_WIDGET, 4);
bbox->pack_end (*load, Gtk::PACK_EXPAND_WIDGET, 4); bbox->pack_end (*load, Gtk::PACK_EXPAND_WIDGET, 4);
@@ -67,7 +77,7 @@ CurveEditor::CurveEditor () : cl(NULL), activeParamControl(-1), realized(false),
load->signal_clicked().connect( sigc::mem_fun(*this, &CurveEditor::loadPressed) ); load->signal_clicked().connect( sigc::mem_fun(*this, &CurveEditor::loadPressed) );
save->set_tooltip_text (M("CURVEEDITOR_TOOLTIPSAVE")); save->set_tooltip_text (M("CURVEEDITOR_TOOLTIPSAVE"));
load->set_tooltip_text (M("CURVEEDITOR_TOOLTIPLOAD")); load->set_tooltip_text (M("CURVEEDITOR_TOOLTIPLOAD"));
// parametric curve // parametric curve
paramCurveBox = new Gtk::VBox (); paramCurveBox = new Gtk::VBox ();
paramCurve = Gtk::manage (new MyCurve ()); paramCurve = Gtk::manage (new MyCurve ());
@@ -79,8 +89,8 @@ CurveEditor::CurveEditor () : cl(NULL), activeParamControl(-1), realized(false),
shcSelector = Gtk::manage (new SHCSelector ()); shcSelector = Gtk::manage (new SHCSelector ());
shcSelector->set_size_request (GRAPH_SIZE, 20); shcSelector->set_size_request (GRAPH_SIZE, 20);
paramctab->attach (*paramCurve, 0, 1, 0, 1, Gtk::FILL, Gtk::SHRINK, RADIUS+2, RADIUS+2); paramctab->attach (*paramCurve, 0, 1, 0, 1, Gtk::FILL, Gtk::SHRINK, 4, 4);
paramctab->attach (*shcSelector, 0, 1, 1, 2, Gtk::FILL, Gtk::SHRINK, RADIUS+2, 2); paramctab->attach (*shcSelector, 0, 1, 1, 2, Gtk::FILL, Gtk::SHRINK, RADIUS+4, 0);
Gtk::HBox* tmpb = Gtk::manage (new Gtk::HBox ()); Gtk::HBox* tmpb = Gtk::manage (new Gtk::HBox ());
tmpb->pack_start (*paramctab, true, false); tmpb->pack_start (*paramctab, true, false);
@@ -331,6 +341,25 @@ void CurveEditor::curveChanged () {
cl->curveChanged (); cl->curveChanged ();
} }
void CurveEditor::curveResetPressed () {
switch (curveTypeIx) {
case 2 : // Custom
customCurve->reset ();
break;
case 1 : // Parametric
highlights->resetPressed();
lights->resetPressed();
darks->resetPressed();
shadows->resetPressed();
shcSelector->reset();
paramCurve->reset ();
break;
default:
break;
}
curveChanged ();
}
void CurveEditor::shcChanged () { void CurveEditor::shcChanged () {
paramCurve->setPoints (getCurve()); paramCurve->setPoints (getCurve());

View File

@@ -27,6 +27,7 @@
class CurveEditor : public Gtk::VBox, public CurveListener, public SHCListener, public AdjusterListener { class CurveEditor : public Gtk::VBox, public CurveListener, public SHCListener, public AdjusterListener {
Gtk::ComboBoxText* curveType; Gtk::ComboBoxText* curveType;
Gtk::Button* curve_reset;
Gtk::VBox* paramCurveBox; Gtk::VBox* paramCurveBox;
Gtk::VBox* customCurveBox; Gtk::VBox* customCurveBox;
@@ -68,6 +69,7 @@ class CurveEditor : public Gtk::VBox, public CurveListener, public SHCListener,
void setCurve (const std::vector<double>& c); void setCurve (const std::vector<double>& c);
std::vector<double> getCurve (); std::vector<double> getCurve ();
void curveChanged (); void curveChanged ();
void curveResetPressed ();
void shcChanged (); void shcChanged ();
void adjusterChanged (Adjuster* a, double newval); void adjusterChanged (Adjuster* a, double newval);
bool adjusterEntered (GdkEventCrossing* ev, int ac); bool adjusterEntered (GdkEventCrossing* ev, int ac);

View File

@@ -603,3 +603,26 @@ void MyCurve::updateBackgroundHistogram (unsigned int* hist) {
} }
void MyCurve::reset() {
int width = get_allocation().get_width() - RADIUS * 2;
int height = get_allocation().get_height() - RADIUS * 2;
switch (curve.type) {
case Spline :
curve.x.clear();
curve.y.clear();
curve.x.push_back(0.);
curve.y.push_back(0.);
curve.x.push_back(1.);
curve.y.push_back(1.);
grab_point = -1;
lit_point = -1;
interpolate (width, height);
break;
case Parametric :
// Nothing to do (?)
default:
break;
}
//draw(width, height, -1);
}

View File

@@ -83,6 +83,7 @@ class MyCurve : public Gtk::DrawingArea {
void notifyListener (); void notifyListener ();
void setActiveParam (int ac); void setActiveParam (int ac);
void updateBackgroundHistogram (unsigned int* hist); void updateBackgroundHistogram (unsigned int* hist);
void reset ();
}; };
#endif #endif

View File

@@ -19,6 +19,7 @@
#include <shcselector.h> #include <shcselector.h>
#include <iomanip> #include <iomanip>
#include <mycurve.h>
SHCSelector::SHCSelector() : movingPosition(-1), cl(NULL) { SHCSelector::SHCSelector() : movingPosition(-1), cl(NULL) {
@@ -99,18 +100,22 @@ bool SHCSelector::on_expose_event(GdkEventExpose* event) {
cr->set_line_width (0.5); cr->set_line_width (0.5);
if (movingPosition >= 0) { if (movingPosition >= 0) {
int i = movingPosition; int i = movingPosition;
int offset;
int layout_width, layout_height;
Glib::RefPtr<Pango::Layout> layout = create_pango_layout(Glib::ustring::format(std::setprecision(2), positions[i])); Glib::RefPtr<Pango::Layout> layout = create_pango_layout(Glib::ustring::format(std::setprecision(2), positions[i]));
cr->move_to (w*positions[i]+wslider/2-0.5, 0); layout->get_pixel_size(layout_width, layout_height);
offset = positions[i] > 0.5 ? -layout_width-1-wslider/2 : 1+wslider/2;
cr->move_to (w*positions[i]+offset-0.5, 0);
cr->set_source_rgb (bgc.get_red_p(), bgc.get_green_p(), bgc.get_blue_p()); cr->set_source_rgb (bgc.get_red_p(), bgc.get_green_p(), bgc.get_blue_p());
layout->add_to_cairo_context (cr); layout->add_to_cairo_context (cr);
cr->fill_preserve (); cr->fill_preserve ();
cr->stroke (); cr->stroke ();
cr->move_to (w*positions[i]+wslider/2+0.5, 1); cr->move_to (w*positions[i]+offset+0.5, 1);
layout->add_to_cairo_context (cr); layout->add_to_cairo_context (cr);
cr->fill_preserve (); cr->fill_preserve ();
cr->stroke (); cr->stroke ();
cr->set_source_rgb (fgc.get_red_p(), fgc.get_green_p(), fgc.get_blue_p()); cr->set_source_rgb (fgc.get_red_p(), fgc.get_green_p(), fgc.get_blue_p());
cr->move_to (w*positions[i]+wslider/2, 0.5); cr->move_to (w*positions[i]+offset, 0.5);
layout->add_to_cairo_context (cr); layout->add_to_cairo_context (cr);
cr->fill_preserve (); cr->fill_preserve ();
cr->stroke (); cr->stroke ();
@@ -164,3 +169,10 @@ void SHCSelector::styleChanged (const Glib::RefPtr<Gtk::Style>& style) {
queue_draw (); queue_draw ();
} }
void SHCSelector::reset () { // : movingPosition(-1), cl(NULL) {
positions[0] = 0.25;
positions[1] = 0.5;
positions[2] = 0.75;
queue_draw ();
}

View File

@@ -55,6 +55,7 @@ class SHCSelector : public Gtk::DrawingArea {
bool on_button_release_event (GdkEventButton* event); bool on_button_release_event (GdkEventButton* event);
bool on_motion_notify_event (GdkEventMotion* event); bool on_motion_notify_event (GdkEventMotion* event);
void styleChanged (const Glib::RefPtr<Gtk::Style>& style); void styleChanged (const Glib::RefPtr<Gtk::Style>& style);
void reset ();
}; };
#endif #endif